#!/bin/sh
# SPDX-License-Identifier: ACSL
# SPDX-FileCopyrightText: © 2019 Antoine Le Gonidec <vv221@dotslashplay.it>
set -o errexit

###
# Perimeter
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260331.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='perimeter'
GAME_NAME='Perimeter'

ARCHIVE_BASE_0_NAME='setup_perimeter_1.03_(19064).exe'
ARCHIVE_BASE_0_MD5='a65c86a8de9b938bc070bcbe5900aef2'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_PART1_NAME='setup_perimeter_1.03_(19064)-1.bin'
ARCHIVE_BASE_0_PART1_MD5='ba08f50e95ce6424d214f57383d338c8'
ARCHIVE_BASE_0_SIZE='3800000'
ARCHIVE_BASE_0_VERSION='1.03-gog19064'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/perimeter'

CONTENT_PATH_DEFAULT='app'
# TODO: Install the library in a standard path.
CONTENT_GAME_BIN_FILES='
binkw32.dll
config.exe
Perimeter.exe'
CONTENT_GAME0_BIN_RELATIVE_PATH='__support/app'
CONTENT_GAME0_BIN_FILES='
Resource/controls.ini
Config.ini
network.ini
Perimeter.ini'
CONTENT_GAME_DATA_FILES='
cache_font
RESOURCE
Scripts'
CONTENT_DOC_DATA_FILES='
MANUAL.pdf
readme.txt'

USER_PERSISTENT_DIRECTORIES='
RESOURCE/Saves'
USER_PERSISTENT_FILES='
RESOURCE/controls.ini
Config.ini
network.ini
Perimeter.ini'

APP_MAIN_EXE='Perimeter.exe'
APP_MAIN_ICON='Perimeter.ico'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
# TODO: Check if the following library is actually required.
PKG_BIN_DEPENDENCIES_LIBRARIES='
libXcursor.so.1'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'

# Load common functions.

if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${HOME}/.local/lib/play.it" \
		'/usr/local/lib/play.it' \
		'/usr/lib/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit.sh.2"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit.sh.2 not found.\n'
	exit 1
fi
# shellcheck source=libplayit.sh.2
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Enforce consistent paths.

path_reference='RESOURCE'
path_alternative='Resource'
mv \
	"$(path_archive_contents 'GAME0_BIN')/${path_alternative}" \
	"$(path_archive_contents 'GAME0_BIN')/${path_reference}"

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
