#!/usr/bin/env python3 # Mudancas no projeto Bugged Racing (esensar/bugged-racing, commit de0f97c) feitas por build-bugged-racing.sh: # 1. O multiplayer em rede (ENet) sai: network/multiplayer_controller.gd vira um autoload offline (so is_online() # = false, peers vazio e o sinal peers_updated, que o resto do jogo consulta), menu/multiplayer_menu.* e o # botao "Multiplayer" do menu principal somem. # 2. O menu principal perde o botao "Exit" (nao faz nada na web) e a fileira "Built with" com os logos do # Godot, Blender, Krita e Kenney, cujos botoes abriam sites externos (OS.shell_open). # 3. Os links da tela "About" (OS.shell_open) deixam de abrir paginas; o texto e os creditos ficam. # 4. O campo "Multiplayer name" das opcoes vira "Player name". # Uso: python3 -I patch.py import re, sys, os root = sys.argv[1] def p(*a): return os.path.join(root, *a) def read(f): return open(p(f), encoding='utf-8').read() def write(f, s): open(p(f), 'w', encoding='utf-8').write(s) # 1. Multiplayer offline. write('network/multiplayer_controller.gd', '''extends Node # Versao offline (fredygames): o codigo de rede (ENet) do projeto original foi retirado. O resto do jogo ainda # consulta este autoload (is_online(), peers, peers_updated, quit()), que agora responde sempre "offline". signal peers_updated var peers = {} func is_online() -> bool: return false func quit() -> void: pass ''') os.remove(p('menu/multiplayer_menu.gd')) os.remove(p('menu/multiplayer_menu.tscn')) # Remove um no do .tscn (e os descendentes) e as conexoes que partem dele. def drop_nodes(text, paths): blocks = re.split(r'(?m)^(?=\[)', text) out = [] for b in blocks: m = re.match(r'\[node name="([^"]+)"(?: type="[^"]+")?(?: parent="([^"]*)")?', b) if m: name, parent = m.group(1), m.group(2) full = name if parent is None else (name if parent == '.' else parent + '/' + name) if parent is not None and any(full == x or full.startswith(x + '/') for x in paths): continue m = re.match(r'\[connection signal="[^"]+" from="([^"]+)"', b) if m and any(m.group(1) == x or m.group(1).startswith(x + '/') for x in paths): continue out.append(b) return ''.join(out) base = 'MarginContainer/VSplitContainer/VSplitContainer' t = read('menu/main_menu.tscn') n0 = t.count('[node ') t = drop_nodes(t, [base + '/CenterContainer/VBoxContainer/MultiplayerButton', base + '/CenterContainer/VBoxContainer/ExitButton', base + '/HBoxContainer']) assert n0 - t.count('[node ') == 8, (n0, t.count('[node ')) for res in ('kenneylogo', 'kritaicon', 'blendericon'): t, k = re.subn(r'(?m)^\[ext_resource path="res://assets/%s\.png"[^\n]*\n' % res, '', t) assert k == 1 write('menu/main_menu.tscn', t) g = read('menu/main_menu.gd') for fn in ('_on_MultiplayerButton_pressed', '_on_ExitButton_pressed', '_on_GodotButton_pressed', '_on_BlenderButton_pressed', '_on_KritaButton_pressed', '_on_KenneyButton_pressed'): g, k = re.subn(r'(?ms)^func %s\(\).*?(?=^func |\Z)' % fn, '', g) assert k == 1, fn g = g.rstrip('\n') + '\n' assert 'shell_open' not in g and 'multiplayer' not in g.lower() write('menu/main_menu.gd', g) # 3. Links da tela About. a = read('menu/about.gd') a, k = re.subn(r'OS\.shell_open\(meta\)', 'pass # fredygames: os links nao abrem paginas externas', a) assert k == 1 write('menu/about.gd', a) # 4. Rotulo das opcoes. s = read('menu/settings_menu.tscn') assert s.count('text = "Multiplayer name"') == 1 write('menu/settings_menu.tscn', s.replace('text = "Multiplayer name"', 'text = "Player name"')) # Nada de OS.shell_open nem de rede de verdade no que sobrou. for dp, dn, fn in os.walk(root): for f in fn: if f.endswith('.gd'): body = open(os.path.join(dp, f), encoding='utf-8').read() assert 'NetworkedMultiplayerENet' not in body and 'OS.shell_open' not in body, f