#!/usr/bin/env bash # Exporta o Stellar Highway (Safwan Murad / Stellar Stones, GPL-3.0; github.com/Safwan-Murad/Stellar-Highway) para a web # com o Godot 4.7.2 oficial (a versao do projeto): renderer Compatibility, SEM threads (modelo web_nothreads_release), # sem PWA. Mudancas no projeto (stellar-highway/web.patch): renderer Compatibility e fisica sem thread separada; o # botao que abre a pasta de replays no gerenciador de arquivos (OS.shell_open) some; os creditos trocam a explosao do # missil de terceiros (sem licenca) pela nossa, e as mencoes a loja de apps saem do README e do CONTRIBUTING. Os 11 # quadros da explosao (46x45) sao gerados por stellar-highway/explosion.py (dominio publico, determinístico) com os # mesmos nomes dos originais (GameFiles/SpinHead IMGS/Missile/Explosion/N.png), e os .import do autor continuam valendo. # # src/FredGames.Bundler/Builds/build-stellar-highway.sh # # O editor (macOS universal) e os modelos de exportacao vem do release 4.7.2-stable do GitHub, conferidos pelo # SHA-256 e ficam em artifacts/tools/godot-4.7.2, instalados sob lockf. O editor roda com HOME dentro da pasta de saida. # # Saida: artifacts/build/stellar-highway-b7f9900/{web/,stellar-highway-b7f9900.tar.gz}, que o bundle.yaml do jogo # confere pelo SHA-256. O tar.gz e o fonte do jogo ja com as mudancas acima e sai igual a cada execucao. set -euo pipefail COMMIT=b7f990027674472c0cadafcbcc103f71320333a9 SHA256=5f10b2f5e0a702571489df3f045712f2b0ddb3113a9ade7f0963c06d27ebe655 GODOT=4.7.2 GODOT_URL=https://github.com/godotengine/godot/releases/download/$GODOT-stable GODOT_MAC_SHA256=c58a24e31d720be9d62f60cb5627c4e695fb72f21b0cfe1bc9ccaa9a3b3ba63e GODOT_TPZ_SHA256=f298490b8d44d934be425a5a65a51bf15f422428b229a06a6e11d9ffea248011 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/stellar-highway-${COMMIT:0:7}" cache="$root/artifacts/build/cache" tools="$root/artifacts/tools" mkdir -p "$cache" fetch() { if [ ! -f "$cache/$2" ]; then curl -fsSL --retry 4 "$1" -o "$cache/$2.partial" && mv "$cache/$2.partial" "$cache/$2" fi echo "$3 $cache/$2" | shasum -a 256 -c - } install_godot() { [ -d "$tools/godot-$GODOT" ] && return 0 fetch "$GODOT_URL/Godot_v$GODOT-stable_macos.universal.zip" "Godot_v$GODOT-stable_macos.universal.zip" "$GODOT_MAC_SHA256" fetch "$GODOT_URL/Godot_v$GODOT-stable_export_templates.tpz" "Godot_v$GODOT-stable_export_templates.tpz" "$GODOT_TPZ_SHA256" rm -rf "$tools/godot-$GODOT.tmp" mkdir -p "$tools/godot-$GODOT.tmp" unzip -q "$cache/Godot_v$GODOT-stable_macos.universal.zip" -d "$tools/godot-$GODOT.tmp" unzip -q "$cache/Godot_v$GODOT-stable_export_templates.tpz" templates/web_nothreads_release.zip templates/version.txt \ -d "$tools/godot-$GODOT.tmp" mv "$tools/godot-$GODOT.tmp" "$tools/godot-$GODOT" } if [ "${1:-}" = "--install" ]; then install_godot; exit 0; fi fetch "https://github.com/Safwan-Murad/Stellar-Highway/archive/$COMMIT.tar.gz" "stellar-highway-${COMMIT:0:7}.tar.gz" "$SHA256" if [ ! -d "$tools/godot-$GODOT" ]; then lockf -k "$root/artifacts/godot-$GODOT.lock" bash "${BASH_SOURCE[0]}" --install fi rm -rf "$out" mkdir -p "$out/tree" "$out/web" tar -xzf "$cache/stellar-highway-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 # Mudancas do porte (web.patch) e a explosao nossa no lugar da de terceiros. ( cd "$out/tree" && patch -p1 < "$here/stellar-highway/web.patch" ) python3 -I "$here/stellar-highway/explosion.py" "$out/tree/GameFiles/SpinHead IMGS/Missile/Explosion" rm -f "$out/tree/"*.orig # O Godot 4.4+ cria um .uid aleatorio para cada script sem ele (o projeto e de uma versao anterior ou o autor nao # o versionou), o que muda o .pck a cada build. Criamos os faltantes com um valor derivado do caminho. python3 -I - "$out/tree" <<'PY' import hashlib, os, sys A = 'abcdefghijklmnopqrstuvwxyz01234567' for d, _, fs in os.walk(sys.argv[1]): for f in sorted(fs): if f.endswith(('.gd', '.gdshader', '.gdshaderinc')) and not os.path.exists(os.path.join(d, f + '.uid')): n = int.from_bytes(hashlib.sha256(os.path.relpath(os.path.join(d, f), sys.argv[1]).encode()).digest()[:8], 'big') >> 12 s = '' for _ in range(12): s += A[n % 34]; n //= 34 open(os.path.join(d, f + '.uid'), 'w').write('uid://' + s + '\n') PY # O Godot 4.7 sorteia um unique_id para cada no de .tscn que nao o traz, e isso muda o .scn exportado (e o .pck) a # cada build. Gravamos os faltantes com um valor derivado do caminho da cena e do no. python3 -I - "$out/tree" <<'PY' import hashlib, os, re, sys for d, _, fs in os.walk(sys.argv[1]): for f in sorted(fs): if not f.endswith('.tscn'): continue path = os.path.join(d, f) rel = os.path.relpath(path, sys.argv[1]) lines = open(path, encoding='utf-8').read().split('\n') used = {int(m) for l in lines for m in re.findall(r'unique_id=(\d+)', l)} for i, l in enumerate(lines): if l.startswith('[node ') and 'unique_id=' not in l and l.endswith(']'): n = int.from_bytes(hashlib.sha256(f'{rel}:{i}:{l}'.encode()).digest()[:8], 'big') % 2147483647 or 1 while n in used: n = n % 2147483646 + 1 used.add(n) lines[i] = l[:-1] + f' unique_id={n}]' open(path, 'w', encoding='utf-8').write('\n'.join(lines)) PY # Data fixa nos arquivos e fonte publicado em tar deterministico (ordem, dono e data fixos). TZ=UTC find "$out/tree" -exec touch -t 202001010000 {} + ( cd "$out/tree" && find . -type f | sed 's|^\./||' | LC_ALL=C sort > "$out/files.txt" ) ( cd "$out/tree" && COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n \ -cf - -T "$out/files.txt" ) | gzip -n -9 > "$out/stellar-highway-${COMMIT:0:7}.tar.gz" project="$out/tree/." cp "$here/stellar-highway/export_presets.cfg" "$project/export_presets.cfg" export HOME="$out/home" TZ=UTC LC_ALL=C templates="$HOME/Library/Application Support/Godot/export_templates/$GODOT.stable" mkdir -p "$templates" cp "$tools/godot-$GODOT/templates/web_nothreads_release.zip" "$tools/godot-$GODOT/templates/version.txt" "$templates/" godot="$tools/godot-$GODOT/Godot.app/Contents/MacOS/Godot" cd "$project" # A primeira passada importa os recursos (cria .godot/); a segunda exporta. "$godot" --headless --path . --import > "$out/import.log" 2>&1 || true # O cursor do mouse vem do project.godot, lido antes da importacao: a segunda passada ja o encontra. "$godot" --headless --path . --import > "$out/import2.log" 2>&1 || true "$godot" --headless --path . --export-release "Web" "$out/web/index.html" > "$out/export.log" 2>&1 ls -l "$out/web"