#!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later # Copyright (C) 2021 KikooDX START_POS="$PWD" LEVEL_COUNT=0 cd assets/levels || exit for PACK in *; do PACK_NAME="$(basename "$PACK")" cd "$PACK" || exit for LEVEL in *; do [ "$(basename $LEVEL)" == fxconv-metadata.txt ] && continue LEVEL_ARRAY="$(printf '%s\n\tlevel_binaries[%s] = %s;' \ "$LEVEL_ARRAY" "$LEVEL_COUNT" \ "kble_$(basename "$LEVEL" .kble)")" EXTERN_LEVEL="$(printf '%s\nextern uint8_t %s[];' "$EXTERN_LEVEL" \ "kble_$(basename "$LEVEL" .kble)")" LEVEL_COUNT="$((LEVEL_COUNT + 1))" LEVEL_NAME="$(basename "$LEVEL" | cut -c2- | awk -F '.' '{print $1}' | tr '[:lower:]' '[:upper:]')" [ -z "$LEVEL_NAMES" ] && LEVEL_NAMES=" \"$LEVEL_NAME\"" || LEVEL_NAMES="$LEVEL_NAMES, \"$LEVEL_NAME\"" done cd .. done printf '/* SPDX-License-Identifier: GPL-3.0-or-later */\n' printf '/* This code was generated with `make_filepaths.sh` */\n' printf '#include "filepaths.h"\n' printf '#include \n' printf '%s\n\n' "$EXTERN_LEVEL" printf 'uint8_t *level_binaries[%s];\n\n' "$LEVEL_COUNT" printf 'char *const level_names[%s] = {%s\n};\n\n' "$LEVEL_COUNT" "$LEVEL_NAMES" # init_level_binaries printf 'void\ninit_level_binaries(void)\n{' printf '%s\n}\n' "$LEVEL_ARRAY" # Create headers cd "$START_POS" mkdir -p generated/include printf '#define LEVEL_COUNT %s\n' "$LEVEL_COUNT" > generated/include/pack_count.h [ "$((LEVEL_COUNT % 4))" != 0 ] && LEVEL_COUNT="$((LEVEL_COUNT + 4 - LEVEL_COUNT % 4))" printf '#define PACK_COUNT %s\n' "$((LEVEL_COUNT / 4))" >> generated/include/pack_count.h