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

###
# Jazz Jackrabbit 2 expansions:
# - The Christmas Chronicles
# - JJ2+
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260206.2

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='jazz-jackrabbit-2'
GAME_NAME='Jazz Jackrabbit 2'

EXPANSION_ID_CHRISTMAS='the-christmas-chronicles'
EXPANSION_NAME_CHRISTMAS='The Christmas Chronicles'

EXPANSION_ID_JJ2PLUS='jj2plus'
EXPANSION_NAME_JJ2PLUS='JJ2+'

ARCHIVE_BASE_CHRISTMAS_1_NAME='setup_jazz_jackrabbit_2_the_christmas_chronicles_1.2x_(16742).exe'
ARCHIVE_BASE_CHRISTMAS_1_MD5='7ef514ecfdbbe321665b507b47f55fc5'
ARCHIVE_BASE_CHRISTMAS_1_TYPE='innosetup'
ARCHIVE_BASE_CHRISTMAS_1_SIZE='71308'
ARCHIVE_BASE_CHRISTMAS_1_VERSION='1.2x-gog16742'
ARCHIVE_BASE_CHRISTMAS_1_URL='https://www.gog.com/game/jazz_jackrabbit_2_collection'

ARCHIVE_BASE_CHRISTMAS_0_NAME='setup_jazz_jackrabbit_2_cc_1.2x_(16742).exe'
ARCHIVE_BASE_CHRISTMAS_0_MD5='3289263ea6bad8bc35f02176e22109f2'
ARCHIVE_BASE_CHRISTMAS_0_TYPE='innosetup'
ARCHIVE_BASE_CHRISTMAS_0_SIZE='70000'
ARCHIVE_BASE_CHRISTMAS_0_VERSION='1.2x-gog16742'

ARCHIVE_BASE_JJ2PLUS_1_NAME='setup_jazz_jackrabbit_2_1.24_jj2_(5.12)_(66703).exe'
ARCHIVE_BASE_JJ2PLUS_1_MD5='e76181591367d1ad986a6dec22fa6f9f'
ARCHIVE_BASE_JJ2PLUS_1_TYPE='innosetup'
ARCHIVE_BASE_JJ2PLUS_1_SIZE='76618'
ARCHIVE_BASE_JJ2PLUS_1_VERSION='1.24-gog66703'
ARCHIVE_BASE_JJ2PLUS_1_URL='https://www.gog.com/game/jazz_jackrabbit_2_collection'

ARCHIVE_BASE_JJ2PLUS_0_NAME='setup_jazz_jackrabbit_2_1.24_jj2_(5.9)_(46861).exe'
ARCHIVE_BASE_JJ2PLUS_0_MD5='94f8477d51e35b4cdc6b3d999b502580'
ARCHIVE_BASE_JJ2PLUS_0_TYPE='innosetup'
ARCHIVE_BASE_JJ2PLUS_0_SIZE='78000'
ARCHIVE_BASE_JJ2PLUS_0_VERSION='1.24-gog46861'

CONTENT_PATH_DEFAULT='.'
CONTENT_PATH_DEFAULT_CHRISTMAS_0='app'
CONTENT_SOURCE_FILES_CHRISTMAS='
html/vssver.scc
j2lc_easter.j2t
j2lc_snoweaster.j2t
tiles/haunt1.anm
tiles/haunt1m.anm
tiles/townhs1.anm
tiles/townhs2.anm
tiles/xmas1.anm
tiles/xmas1m.anm
tiles/xmas2.anm
tiles/xmas3.anm
xb-beaster.j2l
xb-easter-d.j2l
xb-kings-ea.j2l
xb-wacky-ea.j2l
xc-frightni.j2l
xe-carrotiz.j2l
xe-easter09.j2l
xe-easter2.j2l
xe-easter-b.j2l
xe-easter.j2l
xe-elves.j2l
xmas1.j2l
xmas1.j2m
xmas2.j2l
xmas2.j2m
xmas3.j2l
xmas3.j2m
xmas99.j2e
xmbattle1.j2l
xmbattle2.j2l'
CONTENT_SOURCE_FILES_JJ2PLUS='
3rabi.j2s
afrikaans.j2s
allshields.mut
doubledom.mut
forcenormalpalette.mut
jcshelp/atproperties.gif
jcshelp/atproperties.htm
jcshelp/backspace.gif
jcshelp/b.gif
jcshelp/c.gif
jcshelp/control.gif
jcshelp/delete.gif
jcshelp/edestscenbare.gif
jcshelp/edestscenery.htm
jcshelp/edestscen.gif
jcshelp/e.gif
jcshelp/eight.gif
jcshelp/eleven.gif
jcshelp/enter.gif
jcshelp/etriggerscenery.htm
jcshelp/f.gif
jcshelp/five.gif
jcshelp/four.gif
jcshelp/glossary.htm
jcshelp/i.gif
jcshelp/index.htm
jcshelp/jazz2pal.gif
jcshelp/key.gif
jcshelp/layerproperties.htm
jcshelp/layerprop.gif
jcshelp/levelproperties.htm
jcshelp/levelprop.gif
jcshelp/nine.gif
jcshelp/one.gif
jcshelp/plus.gif
jcshelp/setevent.gif
jcshelp/setevent.htm
jcshelp/seven.gif
jcshelp/shift.gif
jcshelp/six.gif
jcshelp/space.gif
jcshelp/srevents.gif
jcshelp/srevents.htm
jcshelp/tbanimtiles.gif
jcshelp/tblayer.gif
jcshelp/tbparallax.gif
jcshelp/tbtiles.gif
jcshelp/ten.gif
jcshelp/t.gif
jcshelp/three.gif
jcshelp/tsbuildex.gif
jcshelp/tsbuild.gif
jcshelp/tsbuild.htm
jcshelp/tsmanual.htm
jcshelp/tsmask.gif
jcshelp/tsorganizer.gif
jcshelp/tsorganizer.htm
jcshelp/tspal.htm
jcshelp/tsproperties.gif
jcshelp/tsproperties.htm
jcshelp/tsstencil.gif
jcshelp/tstiles.gif
jcshelp/two.gif
jcshelp/view_animtiles.htm
jcshelp/view_layer.htm
jcshelp/view_parallax.htm
jcshelp/views.htm
jcshelp/view_tiles.htm
plus52scripting.j2as
plus52scripting.j2l
plusbutterfly.j2as
plusbutterfly.j2l
pluscharjump.j2as
pluscharjump.j2l
plusdomlevel.j2l
plusfrlevel.j2l
plus.j2a
plus.j2d
plusjblevel.j2l
pluslayers.j2as
pluslayers.j2l
plusmusic.j2as
plusmusic.j2l
plusmusic.mo3
pluspalettes.j2as
pluspalettes.j2l
pluspixelmapex.j2as
pluspixelmapex.j2l
plusseasonsautumn.pal
plusseasons.j2as
plusseasons.j2l
plusseasonssummer.pal
plusseasonswinter.pal
plustimerex.j2as
plustimerex.j2l
polski.j2s
seenergyblast.asc
seenergyblast.j2a
seenergyblast.wav
sefirework1.wav
sefirework2.wav
sefirework.asc
sefirework.j2a
sejtf.mut
seroller.asc
seroller.j2a
seroller.wav
seweapon.asc
share1.j2m
share2.j2m
share3.j2m
swedish.j2s
tiles/readme.txt
wsf01.j2t'
CONTENT_DOC_MAIN_FILES_CHRISTMAS='
deutsch.pdf
english.pdf
espanol.pdf
francois.pdf
italiano.pdf
nederlnd.pdf'
CONTENT_DOC_MAIN_FILES_JJ2PLUS='
license.doc
order.doc
order_uk.doc
plus-angelscript.html
plus-readme.html'

PKG_PARENT_ID="$GAME_ID"

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_PARENT'

# Easier upgrades from pre-20250812.4 packages
PKG_MAIN_PROVIDES_CHRISTMAS="${PKG_MAIN_PROVIDES_CHRISTMAS:-}
jazz-jackrabbit-2-the-christmas-chronicles-bin
jazz-jackrabbit-2-the-christmas-chronicles-data"
PKG_MAIN_PROVIDES_JJ2PLUS="${PKG_MAIN_PROVIDES_JJ2PLUS:-}
jazz-jackrabbit-2-jj2plus-bin
jazz-jackrabbit-2-jj2plus-data"

# Load common functions.

# Scan library paths used by ./play.it ≥ 2.35.
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
# Scan library paths used by ./play.it < 2.35.
# This can go away when PLAYIT_COMPATIBILITY_LEVEL is bumped to 2.35 or higher.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${XDG_DATA_HOME:="${HOME}/.local/share"}/play.it" \
		'/usr/local/share/games/play.it' \
		'/usr/local/share/play.it' \
		'/usr/share/games/play.it' \
		'/usr/share/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit2.sh"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
# Error out if the library can not be found.
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

# Include game data.

option_package=$(option_value 'package')
case "$option_package" in
	('deb')
		PATH_JAZZ2='/usr/share/games/jazz2-native'
	;;
	('gentoo')
		PATH_JAZZ2='/usr/share/jazz2'
	;;
	(*)
		PATH_JAZZ2='/usr/share/Jazz² Resurrection'
	;;
esac
content_inclusion 'SOURCE' 'PKG_MAIN' "${PATH_JAZZ2}/Source"
content_inclusion_default

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
