#!/usr/bin/env bash # Prepara o Gomoku (MIT, Yao Yujian / yyjhao; jQuery Mobile + um Web Worker com a IA nega-scout) a partir do commit a664ec1 de # github.com/yyjhao/HTML5-Gomoku. Nao precisa de build; o HTML puxava jQuery 1.8.2 e jQuery Mobile 1.2.0 (MIT) de code.jquery.com # por http://, e aqui os tres arquivos sao baixados de la uma vez (SHA-256 conferido) e servidos junto do jogo. # # Mudancas, todas feitas aqui (cada uma falha se o texto esperado nao existir): # - jQuery e jQuery Mobile vendorizados em js/ e style/ (o ajax-loader.gif do jQuery Mobile, que o repositorio nao traz, aponta # para o ajax-loader.png que ele traz); o atributo manifest (offline.appcache, arquivo que nao existe) sai; # - sai tudo que nao tem origem declarada: as texturas de madeira (woodfloor.jpg, wood.jpg, small-wood.jpg) viram gradientes CSS, # as imagens happy.png e sad.png (desenhos de memes de internet) viram os SVG nossos de Builds/gomoku/ e o icon.png, a pasta # splash e o splash.xcf (7,5 MB) ficam de fora; # - a pagina "About" (links para o site e a loja de extensoes do autor) vira um texto sem links. # O jogo nao faz outras requisicoes. # # src/FredGames.Bundler/Builds/build-gomoku.sh # # Saida: artifacts/build/gomoku-a664ec1/gomoku-a664ec1-site.tar.gz (pasta site/); dois builds seguidos dao os mesmos bytes. set -euo pipefail COMMIT=a664ec1e7788c7cbdfbe223fb86f34162f9e006d SHA256=27c77b4a6d30fa0834a99dd70f8a00231f6405f6e1d2f7ae025d4b5ad27c94c3 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" slug=gomoku out="$root/artifacts/build/$slug-${COMMIT:0:7}" cache="$root/artifacts/build/cache" mkdir -p "$cache" fetch() { # url nome sha256 [ -f "$cache/$2" ] || { curl -fsSL --retry 4 "$1" -o "$cache/$2.partial" && mv "$cache/$2.partial" "$cache/$2"; } echo "$3 $cache/$2" | shasum -a 256 -c - } fetch "https://github.com/yyjhao/HTML5-Gomoku/archive/$COMMIT.tar.gz" "gomoku-${COMMIT:0:7}.tar.gz" "$SHA256" fetch "https://code.jquery.com/jquery-1.8.2.min.js" gomoku-jquery-1.8.2.min.js f554d2f09272c6f71447ebfe4532d3b1dd1959bce669f9a5ccc99e64ef511729 fetch "https://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js" gomoku-jquery.mobile-1.2.0.min.js b434e7b06d1e76c8ecf4b8fb260010f4b414c03da3ce0ee7fcc2391478bde1be fetch "https://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" gomoku-jquery.mobile-1.2.0.min.css faaee33c7cfb995dfab3449df81498dd40a0e5c508e264a2129eeda64019e960 rm -rf "$out" mkdir -p "$out/site" tar -xzf "$cache/gomoku-${COMMIT:0:7}.tar.gz" -C "$out/site" --strip-components 1 cd "$out/site" rm -rf .gitignore fuser_config.json ga.html README.md images style/woodfloor.jpg style/wood.jpg style/small-wood.jpg mkdir images cp "$here/gomoku/happy.svg" "$here/gomoku/sad.svg" images/ cp "$cache/gomoku-jquery-1.8.2.min.js" js/jquery-1.8.2.min.js cp "$cache/gomoku-jquery.mobile-1.2.0.min.js" js/jquery.mobile-1.2.0.min.js sed 's#images/ajax-loader\.gif#images/ajax-loader.png#' "$cache/gomoku-jquery.mobile-1.2.0.min.css" > style/jquery.mobile-1.2.0.min.css cmp -s "$cache/gomoku-jquery.mobile-1.2.0.min.css" style/jquery.mobile-1.2.0.min.css && { echo "ajax-loader nao trocado" >&2; exit 1; } python3 -I - <<'PY' import re def edit(path, fn): s = open(path, encoding="utf-8").read() n = fn(s) assert n != s, path open(path, "w", encoding="utf-8", newline="").write(n) def index(s): def rep(old, new): nonlocal s assert s.count(old) == 1, old s = s.replace(old, new) rep('', "") a = s.index('\t', '') rep('', '') rep('', '') rep("images/happy.png", "images/happy.svg") rep("images/sad.png", "images/sad.svg") a = s.index("\t\t
I am Yujian") b = s.index("
\n", s.index("Or, install this game", a)) + len("\n") s = s[:a] + "\t\tGomoku (five in a row) with a computer opponent, by Yao Yujian. Get five stones in a row, column or diagonal before your opponent does. The computer searches with a nega-scout algorithm in a background worker, at three levels of difficulty.
\n" + s[b:] return s edit("index.html", index) WOOD_FLOOR = "repeating-linear-gradient(90deg, #6b4423 0 38px, #4f3017 38px 40px, #744b29 40px 78px, #4f3017 78px 80px)" def css(s): out = [] for line in s.split("\n"): if "woodfloor.jpg" in line: if "radial-gradient" in line: line = re.sub(r"url\(woodfloor\.jpg\)", WOOD_FLOOR, line) else: line = "\tbackground: " + WOOD_FLOOR + ";" elif "small-wood.jpg" in line: line = "\tbackground: linear-gradient(#a8743c, #8d5d2e);" elif "url('wood.jpg')" in line: line = "\tbackground: repeating-linear-gradient(100deg, rgba(120,70,20,0.12) 0 2px, rgba(0,0,0,0) 2px 7px), linear-gradient(135deg, #e2b872, #d3a35c 50%, #dcb06a);" out.append(line) n = "\n".join(out) assert ".jpg" not in n return n + "\n.happy-face, .sad-face { width: 200px; height: 200px; margin-left: -100px; margin-top: -100px; }\n" edit("style/style.css", css) PY grep -rn "http://\|https://\|\.jpg\|\.xcf" index.html style/style.css js/Player.js js/Board.js js/Game.js js/layout.js js/interface.js js/storage.js js/ai-worker.js && { echo "restou referencia externa/imagem" >&2; exit 1; } cd "$out" find site -exec touch -t 202611010000 {} + find site -type f | LC_ALL=C sort > files.txt COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n -cf - -T files.txt | gzip -n -9 > "$slug-${COMMIT:0:7}-site.tar.gz" cat files.txt; rm -rf files.txt site shasum -a 256 "$slug-${COMMIT:0:7}-site.tar.gz"