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

###
# Off-World Resource Base
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260321.3

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='off-world-resource-base'
GAME_NAME='O.R.B.: Off-World Resource Base'

ARCHIVE_BASE_0_NAME='setup_orb_2.0.0.5.exe'
ARCHIVE_BASE_0_MD5='b1cab44f6fe398ed008dda23e1538c03'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='651435'
ARCHIVE_BASE_0_VERSION='1.04-gog2.0.0.5'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/orb_offworld_resource_base'

CONTENT_PATH_DEFAULT='app'
CONTENT_GAME_BIN_FILES='
orb.exe
Orb.ini
Orbsetup.exe
orbsetup.ini'
# orb.exe requirements
CONTENT_LIBS_BIN_FILES='
binkw32.dll
mss32.dll
C4dll-D.dll'
CONTENT_GAME0_BIN_FILES='
bobo.dat
lensflares.ini
NetColors.ini
*.asi
*.flt
*.m3d'
# TODO: Move the editor to a dedicated package.
CONTENT_GAME1_BIN_FILES='
OrbScenarioEditor.exe'
CONTENT_GAME_DATA_FILES='
orbdata
cdkey
Seq.flg
Game.positions
Default.SUP
orb.SUP
Credits.txt
*.bmp'
CONTENT_DOC_DATA_FILES='
manual.pdf
Units.pdf
Readme.txt
scen_eula.txt'

# Work around display glitches if not running at the desktop resolution.
# (WINE 11.4)
WINE_VIRTUAL_DESKTOP='auto'

APP_MAIN_EXE='orb.exe'

APP_SETUP_ID="${GAME_ID}-setup"
APP_SETUP_NAME="$GAME_NAME - Settings"
APP_SETUP_CAT='Settings'
APP_SETUP_EXE='Orbsetup.exe'

# TODO: Move the editor to a dedicated package.
APP_EDITOR_ID="${GAME_ID}-editor"
APP_EDITOR_NAME="$GAME_NAME - Scenario editor"
APP_EDITOR_EXE='OrbScenarioEditor.exe'

USER_PERSISTENT_DIRECTORIES='
orbdata/players
orbdata/scenarios'
USER_PERSISTENT_FILES='
orb.ini
orbdata/frontend/players.dat
orbdata/language/Current.lang'

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.

# 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
