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

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

script_version=20260421.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='sudocats'
GAME_NAME='Sudocats'

ARCHIVE_BASE_2_NAME='setup_sudocats_1.11_(json_achievements_fix)_(64bit)_(69928).exe'
ARCHIVE_BASE_2_MD5='ad7da533bc7b59c7b0f62c468e2bae85'
ARCHIVE_BASE_2_TYPE='innosetup'
ARCHIVE_BASE_2_SIZE='250280'
ARCHIVE_BASE_2_VERSION='1.11-gog69928'
ARCHIVE_BASE_2_URL='https://www.gog.com/en/game/sudocats'

ARCHIVE_BASE_1_NAME='setup_sudocats_1.1_(random_puzzles_with_gog_wrapper)_(64bit)_(68010).exe'
ARCHIVE_BASE_1_MD5='c4a1e2a5cabddeedf73832c5841d576c'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='250591'
ARCHIVE_BASE_1_VERSION='1.1-gog68010'

ARCHIVE_BASE_0_NAME='setup_sudocats_1.0_gog_(64bit)_(62585).exe'
ARCHIVE_BASE_0_MD5='c75b4230f05cc5b4d875abd855767dcf'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='230000'
ARCHIVE_BASE_0_VERSION='1.0-gog62585'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES='
sudocats.exe'
# The game fails to start if steam_api64.dll is missing.
CONTENT_GAME0_BIN_FILES='
steam_api64.dll'
# Starting with game build 1.1, galaxy64.dll is required.
CONTENT_GAME1_BIN_FILES='
Galaxy64.dll
GalaxyConfig.json'
CONTENT_GAME_DATA_FILES='
sudocats.pck'

USER_PERSISTENT_FILES='
*.cfg'

# Native Godot can not be used, it crashes on launch:
# SCRIPT ERROR: Parse Error: The identifier "Steam" isn't declared in the current scope.
#           at: GDScript::load_byte_code (res://GLOBAL/functions.gdc:83)
# (…)
# SCRIPT ERROR: Parse Error: The identifier "Steam" isn't declared in the current scope.
#           at: GDScript::load_byte_code (res://GLOBAL/steam.gdc:41)
# (Godot 3.6.2)
APP_MAIN_EXE='sudocats.exe'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

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

# 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
