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

###
# StarTopia
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260323.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='startopia'
GAME_NAME='StarTopia'

GAME_ID_DEMO="${GAME_ID}-demo"
GAME_NAME_DEMO="$GAME_NAME (demo)"

ARCHIVE_BASE_0_NAME='setup_startopia_2.0.0.17.exe'
ARCHIVE_BASE_0_MD5='4fe8d194afc1012e136ed3e82f1de171'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='600000'
ARCHIVE_BASE_0_VERSION='1.01b-gog2.0.0.17'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/startopia'

ARCHIVE_BASE_DEMO_0_NAME='startopia_demo.exe'
ARCHIVE_BASE_DEMO_0_MD5='2e170f8c4700b2d271ac2a6fac23920a'
ARCHIVE_BASE_DEMO_0_EXTRACTOR='unzip'
ARCHIVE_BASE_DEMO_0_SIZE='149364'
ARCHIVE_BASE_DEMO_0_VERSION='2001.5.15.1-archive.org'
ARCHIVE_BASE_DEMO_0_URL='https://archive.org/details/startopia_demo'

CONTENT_PATH_DEFAULT='app'
CONTENT_PATH_DEFAULT_DEMO='.'
CONTENT_GAME_BIN_FILES='
startopia.exe'
# startopia.exe requirements
CONTENT_LIBS_BIN_FILES='
binkw32.dll'
CONTENT_GAME_L10N_FILES='
data/speech/english
text/english
startopia.ini'
CONTENT_GAME_DATA_FILES='
startopia.jpg
cardid.tom
data
intro
languageinis
missions'
CONTENT_DOC_DATA_FILES='
eula
weblinks
*.doc
*.html
*.pdf
*.rtf
*.txt'

USER_PERSISTENT_DIRECTORIES='
profiles'
USER_PERSISTENT_FILES='
startopia.ini'

APP_MAIN_EXE='startopia.exe'
APP_MAIN_EXE_DEMO='StarTopia.exe'

PACKAGES_LIST='
PKG_BIN
PKG_L10N
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_L10N
PKG_DATA'

PKG_L10N_ID="${GAME_ID}-l10n"
PKG_L10N_ID_DEMO="${GAME_ID_DEMO}-l10n"
PKG_L10N_DESCRIPTION='English localisation'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_ID_DEMO="${GAME_ID_DEMO}-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

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Generate a minimal configuration file.

game_path="C:\\$(game_id)"
intro_path="${game_path}\\intro\\"
drive_path_music="${game_path}\\data\\"
drive_path_sound="${game_path}\\data\\"
sound_path_voice="${game_path}\\data\\"
cat > "$(package_path 'PKG_L10N')$(path_game_data)/startopia.ini" <<- EOF
[Intro]
IntroPath=${intro_path}
[Sound]
DrivePathMusic=${drive_path_music}
DrivePathSound=${drive_path_sound}
SoundPathVoice=${sound_path_voice}
[Language]
TextLanguage=English
SpeechLanguage=English
EOF

# Write launchers.

# Install shipped libraries.
wineprefix_init_custom() {
	cat <<- EOF
	# Install shipped libraries.
	ln --force --symbolic $(path_libraries)/* "\${PATH_PREFIX}"
	EOF
}

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
