"""Mudancas do porte do Rusty's Mini Golf para a web (rodado por build-rustys-mini-golf.sh na arvore do jogo). python3 -I patch.py - tira os botoes de redes sociais do menu (links para fora, logos de marcas) e o script que os abre; - troca a fonte Cakecafe (sem licenca de redistribuicao) pela Lilita One (OFL); - tira o icone padrao do Godot do projeto (o preset de exportacao tambem nao o usa); - tira a pasta Assets/Audacity (sons brutos sem origem registrada, que ja nao sao usados) e o projeto de efeitos do FL. """ import hashlib, os, re, shutil, sys root = sys.argv[1] def read(p): return open(os.path.join(root, p), encoding='utf-8').read() def write(p, s): open(os.path.join(root, p), 'w', encoding='utf-8', newline='').write(s) # 1. menu sem redes sociais p = 'Src/MainMenu/MainMenu.tscn' s = read(p) blocks = re.split(r'\n(?=\[)', s) keep, dropped_ids = [], set() for b in blocks: head = b.split('\n', 1)[0] if head.startswith('[ext_resource') and ('SocialMediaButtons/' in head): dropped_ids.add(re.search(r'id="([^"]+)"', head).group(1)) continue if head.startswith('[node') and ('name="SocialMeadia"' in head or 'parent="SocialMeadia"' in head): continue if head.startswith('[connection') and 'SocialMeadia' in head: continue keep.append(b) assert len(dropped_ids) == 8, dropped_ids # 7 icones + OpenURL.gd s = '\n'.join(keep) for i in dropped_ids: assert f'ExtResource("{i}")' not in s s = re.sub(r'load_steps=(\d+)', lambda m: f'load_steps={int(m.group(1)) - len(dropped_ids)}', s, count=1) write(p, s) shutil.rmtree(os.path.join(root, 'Src/MainMenu/SocialMediaButtons')) os.remove(os.path.join(root, 'Src/MainMenu/Mai646A.tmp')) # arquivo temporario do editor, sem uso # 2. fonte n = 0 for d, _, fs in os.walk(os.path.join(root, 'Src')): for f in fs: if f.endswith(('.tscn', '.tres')): path = os.path.join(d, f) s = open(path, encoding='utf-8').read() t = s.replace('path="res://UI/Fonts/Cakecafe.ttf"', 'path="res://UI/Fonts/LilitaOne-Regular.ttf"') if t != s: n += 1 assert 'Cakecafe' not in t, path open(path, 'w', encoding='utf-8', newline='').write(t) assert n == 3, n # a .import da fonte nova e a do autor com o nome trocado (mesmo uid, as cenas o referenciam; o Godot sorteia um uid novo # para cada .import que nao existe, e isso mudaria o .pck a cada build) imp = open(os.path.join(root, 'Src/UI/Fonts/Cakecafe.ttf.import'), encoding='utf-8').read() old_md5 = hashlib.md5(b'res://UI/Fonts/Cakecafe.ttf').hexdigest() new_md5 = hashlib.md5(b'res://UI/Fonts/LilitaOne-Regular.ttf').hexdigest() assert old_md5 in imp imp = imp.replace(old_md5, new_md5).replace('Cakecafe.ttf', 'LilitaOne-Regular.ttf') assert 'Cakecafe' not in imp open(os.path.join(root, 'Src/UI/Fonts/LilitaOne-Regular.ttf.import'), 'w', encoding='utf-8', newline='').write(imp) os.remove(os.path.join(root, 'Src/UI/Fonts/Cakecafe.ttf')) os.remove(os.path.join(root, 'Src/UI/Fonts/Cakecafe.ttf.import')) # 3. icone padrao do Godot p = 'Src/project.godot' s = read(p) assert 'config/icon="res://icon.svg"\n' in s write(p, s.replace('config/icon="res://icon.svg"\n', '')) os.remove(os.path.join(root, 'Src/icon.svg')) if os.path.exists(os.path.join(root, 'Src/icon.svg.import')): os.remove(os.path.join(root, 'Src/icon.svg.import')) # 4. sons brutos e projeto de efeitos shutil.rmtree(os.path.join(root, 'Assets/Audacity')) os.remove(os.path.join(root, 'Assets/FL/RMG SFX.flp'))