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

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

script_version=20260402.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='etherlords-1'
GAME_NAME='Etherlords'

ARCHIVE_BASE_0_NAME='setup_etherlords_2.0.0.10.exe'
ARCHIVE_BASE_0_MD5='13f406358ed79d49754ef3a48de6c2db'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='1458432'
ARCHIVE_BASE_0_VERSION='1.07-gog2.0.0.10'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/etherlords'

CONTENT_PATH_DEFAULT='app'
CONTENT_GAME_BIN_FILES='
MP3DEC.ASI
Etherlords.exe
CombatCamera.ini
settings.ini'
# TODO: Install libraries in a standard path.
# TODO: Drop unused libraries.
CONTENT_GAME0_BIN_FILES='
2DintMMX.dll
3DfpFPU.dll
binkw32.dll
dsetup.dll
mss32.dll'
CONTENT_GAME_DATA_FILES='
Campaigns
Duel
Maps
Resources
HallOfFame.hl
ar_text.res'
CONTENT_DOC_DATA_FILES='
Manual.pdf
ReadMe.txt
ReadMe 1.07.txt'

USER_PERSISTENT_DIRECTORIES='
Campaign
Duel
Save'
USER_PERSISTENT_FILES='
HallOfFame.hl
*.ini'

# Without a virtual desktop the zone pointed by the mouse
# is distinct from where the cursor is displayed.
# The native windowed mode shows similar symptoms.
# (WINE 11.5)
# The game does not seem to support resolutions higher than 1024×768.
WINE_VIRTUAL_DESKTOP='1024x768'

APP_MAIN_EXE='Etherlords.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'

# 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
