31 lines
1.8 KiB
Python
31 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Stage a chooser in the existing owned Source direct-create Lua asset."""
|
|
import argparse
|
|
from pathlib import Path
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
def patch(source):
|
|
if "function GW_SourceChallengeStage()" in source:
|
|
raise ValueError("chooser already installed")
|
|
def replace(old,new):
|
|
nonlocal source
|
|
if source.count(old)!=1: raise ValueError("creation anchor changed: "+old[:70])
|
|
source=source.replace(old,new)
|
|
replace(' if api(8, 0, 0) ~= 1 then return false, "stage"; end',
|
|
' if not GW_SourceChallengeStage() then GW_SourceChallengeReset(); return false, "challenges"; end\n'
|
|
' local staged = api(8, 0, 0);\n'
|
|
' GW_SourceChallengeReset();\n'
|
|
' if staged ~= 1 then return false, "stage"; end')
|
|
replace('local ok, reason = GW_SourceDirectCreate(self:GetSelectedName());',
|
|
'local ok, reason = GW_SourceDirectCreate(self:GetSelectedName());\n'
|
|
'\t\t\tif not ok then GW_SourceChallengeReset(); end')
|
|
replace('function CharacterCreateMixin:OnShow()\n',
|
|
'function CharacterCreateMixin:OnShow()\n\tGW_SourceChallengeAttach(self, GW_SourceSingleNameCreation());\n')
|
|
replace('function CharacterCreateMixin:OnEvent(event, ...)\n',
|
|
'function CharacterCreateMixin:OnEvent(event, ...)\n'
|
|
'\tif event == "CHARACTER_CREATION_RESULT" then GW_SourceChallengeReset(); end\n')
|
|
return (ROOT/'compat/glue/challenge_creation.lua').read_text()+'\n'+source
|
|
if __name__=='__main__':
|
|
ap=argparse.ArgumentParser();ap.add_argument('source',type=Path);ap.add_argument('output',type=Path)
|
|
a=ap.parse_args();a.output.parent.mkdir(parents=True,exist_ok=True)
|
|
a.output.write_text(patch(a.source.read_text()))
|