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

###
# Dicey Dungeons
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260607.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='dicey-dungeons'
GAME_NAME='Dicey Dungeons'

ARCHIVE_BASE_1_NAME='dicey-dungeons-linux64.zip'
ARCHIVE_BASE_1_MD5='7561697f602e3a0af054569e3a8114b3'
ARCHIVE_BASE_1_SIZE='110000'
ARCHIVE_BASE_1_VERSION='1.11-itch.2021.03.18'
ARCHIVE_BASE_1_URL='https://terrycavanagh.itch.io/dicey-dungeons'

ARCHIVE_BASE_0_NAME='dicey-dungeons-linux64.zip'
ARCHIVE_BASE_0_MD5='14879aa94aef2291d6aec0c4c9e760c5'
ARCHIVE_BASE_0_SIZE='450000'
ARCHIVE_BASE_0_VERSION='1.10-itch.2020.11.05'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_MAIN_FILES='
diceydungeons
lime.ndll
data
manifest
mods
soundstuff'

APP_MAIN_EXE='diceydungeons'
APP_MAIN_ICON='data/icon.png'

PKG_MAIN_ARCH='64'
PKG_MAIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6'
# Easier upgrades from pre-20260607.2 packages
PKG_MAIN_PROVIDES='
dicey-dungeons-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
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Build a 512×512 icon from the 1024×1024 provided one.

if [ $(option_value 'icons') -eq 1 ]; then
	APP_MAIN_ICON_512="${APP_MAIN_ICON%.png}_512.png"
	gm convert "$(icon_full_path 'APP_MAIN_ICON')" \
		-resize 512 "$(icon_full_path 'APP_MAIN_ICON_512')"
	APP_MAIN_ICONS_LIST="$(application_icons_list 'APP_MAIN')
	APP_MAIN_ICON_512"
fi

# Include game data.

content_inclusion_icons
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
