#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: © 2020 bbob
# SPDX-FileCopyrightText: © 2023 Antoine Le Gonidec <vv221@dotslashplay.it>
set -o errexit

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

script_version=20260317.4

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='symmetry'
GAME_NAME='Symmetry'

ARCHIVE_BASE_0_NAME='setup_symmetry_1.0.2.win_(21945).exe'
ARCHIVE_BASE_0_MD5='2a0d1919d41b48b8dc5af3071ad7babc'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='210000'
ARCHIVE_BASE_0_VERSION='1.0.2-gog21945'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/symmetry'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES='
Symmetry.exe
options.ini'
# TODO: Install libraries in a standard path.
# TODO: Drop unused libraries.
CONTENT_GAME0_BIN_FILES='
CChromaEditorLibrary.dll
D3DX9_43.dll'
CONTENT_GAME_DATA_FILES='
Texts
splash.png
snd_*.ogg'
# TODO: Install fonts in a standard path.
CONTENT_GAME0_DATA_FILES='
Fonts/JejuGothic.ttf
Fonts/simhei.ttf
Fonts/togoshi-gothic.ttf'
# TODO: Check if these *.chroma files are required.
CONTENT_GAME1_DATA_FILES='
*.chroma'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/AppData/Local/Symmetry'

APP_MAIN_EXE='symmetry.exe'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

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

# An inner archive uses the cabinet archive format.

REQUIREMENTS_LIST='
cabextract'

# 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 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=libplayit2.sh
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default
ARCHIVE_INNER_CAB_PATH="${PLAYIT_WORKDIR}/gamedata/symmetry.cab"
ARCHIVE_INNER_CAB_TYPE='cabinet'
# Rename the cabinet archive to avoid a collision with a similarly named file.
mv "${PLAYIT_WORKDIR}/gamedata/Symmetry.exe" "$ARCHIVE_INNER_CAB_PATH"
archive_extraction 'ARCHIVE_INNER_CAB'
rm "$ARCHIVE_INNER_CAB_PATH"
# Fix file paths, they use "@" instead of "/" as a path component separator.
find "$(path_archive_contents)" -type f | while read -r file_source; do
	file_destination=$(printf '%s' "$file_source" | sed 's#@#/#g')
	if [ "$file_destination" != "$file_source" ]; then
		mkdir --parents "$(dirname "$file_destination")"
		mv "$file_source" "$file_destination"
	fi
done

# 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
