# Biblioteca compartilhada dos scripts de build dos jogos feitos com a SGE (Pygame SGE, de onpon4, LGPL-3.0 ou # posterior; as extensoes xSGE tambem, LGPL-3.0+). Hoje: Hexoshi, ReTux, Pacewar e Tangomon. # # O SGE roda o laco principal e os dialogos de forma bloqueante, o que trava o navegador (pygbag). Dois patches nossos, # publicados junto do fonte de cada jogo, trocam isso por corrotinas: # sge-async.patch sge/dsp.py: Game.start() vira "async def" e cede ao navegador uma vez por quadro # (_wait_frame no lugar de regulate_speed, que nao dorme mais); Game.pause() so marca a pausa e o # laco principal roda um quadro dela por vez (_paused_frame); ganchos modal_active/modal_step. # xsge_gui-async.patch xsge_gui/__init__.py: Dialog.show() nao tem mais laco proprio: entra numa fila (_ModalRunner), # que o laco do SGE avanca um quadro por vez. show() volta logo; "on_close" roda depois que o # dialogo fecha (show_message, get_text_entry e get_menu_selection tambem aceitam on_close). # O uniseg (so quebra de linha, opcional no SGE) nao e incluido. # # Uso: source sge-libs.sh; sge_libs sge xsge_gui ... (baixa, confere o sha256, extrai so os pacotes # Python e aplica os patches). Os tarballs e os patches vao no bundle.yaml de cada jogo como fonte hospedado. SGE_PATCHES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # nome|arquivo|sha256|url sge_lib_info() { case "$1" in sge) echo "sge-2.0.2.tar.gz|1719ae32e4ac57b491cc10c211489177b4e76ecc2a3220c5eec6572dd9d5e4ae|https://files.pythonhosted.org/packages/b6/4e/693535e888e1eb040a0265e35dbcfff466af8dc928a83cb554e407847d8c/sge-2.0.2.tar.gz" ;; xsge_gui) echo "xsge_gui-2.0.tar.gz|3d2006bd1e87cd8886fb2558b6c51f1250d4f6b5430127b997cea49b63401fc4|https://files.pythonhosted.org/packages/99/60/e59cd358ded0bff68627d058cd6b94f23e27bcbb3841a5246693ddeb38b3/xsge_gui-2.0.tar.gz" ;; xsge_lighting) echo "xsge_lighting-1.0.3.tar.gz|9775ebf60b1003d86d965f692f5ea0539da00e66a4126eac86dfd57f13f96201|https://files.pythonhosted.org/packages/fd/06/91b0b204ae62c84ccbe1e5c67480d305fa202fb0277b8bb33cd730f7364d/xsge_lighting-1.0.3.tar.gz" ;; xsge_particle) echo "xsge_particle-1.0.1.tar.gz|fb8600b428f1d22c40dc1e7ac4c6beaedd4ee77e7aa2853300480bed56c476d5|https://files.pythonhosted.org/packages/6f/76/a21d8db6cfccc927a960f1e39fd13702ae0911755a384ac24a3c7f309597/xsge_particle-1.0.1.tar.gz" ;; xsge_path) echo "xsge_path-1.0.3.tar.gz|09cd6da5219beea683f7f7055ac9453791b11da684d998da3582ea0df77839a3|https://files.pythonhosted.org/packages/88/5f/a7042f2f4e5a1793fcb9f683d2105a6dff4893bb5a990c3a32fd2960aef5/xsge_path-1.0.3.tar.gz" ;; xsge_physics) echo "xsge_physics-0.13.3.tar.gz|59d44fefc031a8c24208655c346a9947de5bef0381e687f19a8edbb89eaeb6ba|https://files.pythonhosted.org/packages/3b/40/53abe3da331d16397f0ac14f68f61cb07f3a1b5b505d2770fc6a99ec2c7f/xsge_physics-0.13.3.tar.gz" ;; xsge_tiled) echo "xsge_tiled-2.0.tar.gz|22573749624dec607ddeb7d77c5702936dd5c60acef689d7927272aca7f1c8b3|https://files.pythonhosted.org/packages/2b/00/9c4ab4f19b7f18715a51249d2fc34359db36f307a8e7c8b7b7fcb750f4c0/xsge_tiled-2.0.tar.gz" ;; *) echo "biblioteca SGE desconhecida: $1" >&2; return 1 ;; esac } sge_fetch() { # : deixa o tarball em / e imprime o caminho local info file sha url info="$(sge_lib_info "$2")" || return 1 IFS='|' read -r file sha url <<< "$info" [ -f "$1/$file" ] || curl -fsSL "$url" -o "$1/$file" echo "$sha $1/$file" | shasum -a 256 -c - >&2 echo "$1/$file" } sge_libs() { # ... local cache="$1" dest="$2" lib tar tmp shift 2 mkdir -p "$cache" "$dest" for lib in "$@"; do tar="$(sge_fetch "$cache" "$lib")" || return 1 tmp="$(mktemp -d "$dest/.lib.XXXXXX")" tar -xzf "$tar" -C "$tmp" --strip-components 1 case "$lib" in sge) patch -d "$tmp" -p1 < "$SGE_PATCHES_DIR/sge-async.patch" >&2 ;; xsge_gui) patch -d "$tmp" -p1 < "$SGE_PATCHES_DIR/xsge_gui-async.patch" >&2 ;; esac cp -R "$tmp/$lib" "$dest/$lib" rm -rf "$tmp" done }