95 lines
7.5 KiB
Python
95 lines
7.5 KiB
Python
"""Selected Camelot template + actual nav factory and persistent realm adapter."""
|
|
from pathlib import Path
|
|
import hashlib, os, subprocess, tempfile, unittest, xml.etree.ElementTree as ET
|
|
import source_realm_change_test as prior
|
|
ROOT=prior.ROOT
|
|
STOCK=Path(os.environ.get('Q105_STOCK','/mnt/Games/@project/build/q105-stock-picker-20261128/files'))
|
|
NAV=STOCK/'6796719-characterselectnavbar.lua'
|
|
XML=STOCK/'7373118-characterselectnavtemplates.xml'
|
|
|
|
def callback(path,anchor):
|
|
return prior.callback(path.read_text(),anchor)
|
|
|
|
def run(script):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
p=Path(d)/'gate.lua';p.write_text(script)
|
|
return subprocess.run(['lua',str(p),str(ROOT/'compat/glue/source_realm_district_adapter.lua'),str(ROOT/'compat/glue/source_realm_exit.lua')],capture_output=True,text=True)
|
|
|
|
class VisibleNavigation(unittest.TestCase):
|
|
def persistent_body(self,handlers,invoke):
|
|
district=prior.INPUT/'SuperDistrict.lua'
|
|
for name in ['OnShow','OnEvent','RefreshSuperDistrictButtons','ConfirmSuperDistrict']:
|
|
handlers+='\n'+callback(district,'function SuperDistrictMixin:'+name+'(')
|
|
body=prior.BODY.replace('__CALLBACK__',handlers).replace('__INVOKE__',invoke)
|
|
body=body.replace('local nextSession,nf=session();','local nextSession,nf=automatic,af;')
|
|
at="assert(nextSession.Confirm(nf,'source:1')"
|
|
body=body.replace(at,"for i=1,8 do nextSession.Refresh(nf);nextSession.OnUpdate(nf,.6);nextSession.CharacterListReceived();end;assert(#requests==1 and saved==nil,'picker did not remain open through automatic callbacks');nf.selectedSuperDistrictID='source:1';\n"+at)
|
|
body=body.replace("for i=1,8 do nextSession.Refresh(nf);nextSession.OnUpdate(nf,.6);nextSession.CharacterListReceived();end;", "SourceRealmDistrict=nextSession;nf.RefreshSuperDistrictButtons=SuperDistrictMixin.RefreshSuperDistrictButtons;NarrationUtil={TriggerType={Notification=1},RegionToNarrationInfo=function()end};C_DistrictUtils={GetAvailableSuperDistricts=function()error('pending source picker fell into native realm data')end};SuperDistrictMixin.OnShow(nf);for i=1,8 do SuperDistrictMixin.OnEvent(nf,'SUPER_DISTRICT_LIST_UPDATED');nextSession.OnUpdate(nf,.6);SuperDistrictMixin.OnEvent(nf,'CHARACTER_LIST_UPDATE');end;")
|
|
body=body.replace("assert(nextSession.Confirm(nf,'source:1') and #requests==2 and requests[2][1]==1);", "SuperDistrictMixin.ConfirmSuperDistrict(nf);assert(#requests==2 and requests[2][1]==1);")
|
|
return prior.PRE+body
|
|
|
|
def check_script(self,script):
|
|
for count in [2,1]:
|
|
with self.subTest(realms=count):
|
|
current=script
|
|
if count==1:
|
|
current=current.replace("rows={[0]=wanted,[1]=other};", "rows={[0]=wanted};provider.GetRealmsInCategory=function()return {0};end;")
|
|
current=current.replace('#nf.districtButtons==2','#nf.districtButtons==1').replace("nf.selectedSuperDistrictID='source:1'","nf.selectedSuperDistrictID='source:0'")
|
|
current=current.replace('requests[2][1]==1','requests[2][1]==0').replace('status.state,status.selected_index,status.transport_prepared=2,1,1','status.state,status.selected_index,status.transport_prepared=2,0,1')
|
|
current=current.replace("saved=='v2|Other|6'", "saved=='v2|Octo%20PvE|5'").replace('requests[3][1]==1','requests[3][1]==0')
|
|
result=run(current);self.assertEqual(result.returncode,0,result.stdout+result.stderr)
|
|
|
|
def test_actual_visible_back_reopens_picker(self):
|
|
raw=(prior.INPUT/'CharacterSelect.lua').read_bytes()
|
|
if 'back' in prior.ui.REALM_EXIT_INPUTS:raw=prior.ui.transform_realm_exit(raw,consumer='back')
|
|
body=prior.callback(raw.decode().replace('\r\n','\n'),'function CharacterSelectBackButtonMixin:OnClick()')
|
|
script=self.persistent_body('CharacterSelectBackButtonMixin={};\n'+body,'CharacterSelectBackButtonMixin:OnClick()')
|
|
self.check_script(script)
|
|
|
|
def test_selected_template_native_factory_and_click(self):
|
|
self.assertEqual(hashlib.sha256(NAV.read_bytes()).hexdigest(),'7b06e7f1a8534c06556e35b88068174e0f3597e115922bb9ded3255b59aeb9f9')
|
|
raw=XML.read_bytes()
|
|
if hasattr(prior.ui,'transform_realm_nav'):raw=prior.ui.transform_realm_nav(raw)
|
|
root=ET.fromstring(raw);template=next(n for n in root if n.get('name')=='CharacterSelectNavBarCustomTemplate')
|
|
base_xml = ET.parse(STOCK / '6796715-characterselectnavbar.xml')
|
|
base = next(node for node in base_xml.getroot() if node.get('name') == template.get('inherits'))
|
|
settings = {}
|
|
for frame in (base, template):
|
|
for key in frame.findall('{*}KeyValues/{*}KeyValue'):
|
|
settings[key.get('key')] = key.get('value')
|
|
self.assertEqual([settings[k] for k in ('realmsButtonAvailable', 'storeButtonAvailable',
|
|
'superDistrictsButtonAvailable', 'menuButtonAvailable')],
|
|
['true', 'false', 'false', 'true'])
|
|
options = ','.join(f'{key}={value}' for key, value in settings.items() if value in ('true', 'false'))
|
|
change=prior.ui.transform_realm_exit((prior.INPUT/'CharacterSelectUtil.lua').read_bytes(),consumer='character').decode().replace('\r\n','\n')
|
|
handlers=prior.callback(change,'function CharacterSelectUtil.ChangeRealm()')
|
|
handlers+='\nCharacterSelectNavBarMixin={NavBarButtonWidthBuffer=70};\n'
|
|
for name in ['OnLoad','AddButton','TrySetUpStoreButton','TrySetUpMenuButton','TrySetUpRealmsButton','TrySetUpSuperDistrictsButton','SetRealmsButtonEnabled']:
|
|
handlers+=callback(NAV,'function CharacterSelectNavBarMixin:'+name+'(')+'\n'
|
|
setup=r'''
|
|
C_RealmList.ShouldShowRealmsAsCheatButton=function()return false;end;
|
|
function GenerateFlatClosure(f)return function()return f();end;end;
|
|
function SmartNavigation_UseVerticalCursorForFrame(f)f.nativeCursor=true;end;
|
|
CHARACTER_SELECT_NAV_BAR_REALMS='Realms';CHARACTER_SELECT_NAV_BAR_SUPER_DISTRICTS='Ruleset';SOUNDKIT.GS_TITLE_OPTIONS=2;
|
|
CHARACTER_SELECT_NAV_BAR_MENU='Menu';GlueMenuFrameUtil={ShowMenu=function()end};
|
|
FrameUtil={RegisterFrameForEvents=function()end};CallbackRegistrantMixin={};
|
|
EventRegistry.RegisterCallback=function()end;
|
|
local nav=setmetatable({__NAV_OPTIONS__},{__index=CharacterSelectNavBarMixin});
|
|
for _,name in ipairs({'TrySetUpGameModeButton','TrySetUpCampsButton','SetButtonVisuals','UpdateButtonDividerState'})do nav[name]=function()end;end;
|
|
nav.ButtonTray={count=0,SetButtonSetup=function(self,fn)self.setup=fn;end,
|
|
AddControl=function(self,label,cb,...)
|
|
self.count=self.count+1;local b={SetText=function(self,v)self.text=v;end,SetWidth=function()end,GetTextWidth=function()return 50;end,
|
|
SetScript=function(self,k,v)self[k]=v;end,SetEnabled=function(self,v)self.enabled=v;end};self.setup(b,label,cb,...);return b;
|
|
end};
|
|
nav:OnLoad();assert(nav.RealmsButton,'selected Camelot template hides native Change Realm');
|
|
assert(nav.ButtonTray.count==2 and nav.RealmsButton.nativeCursor and nav.RealmsButton.text=='Realms','stock factory not used');
|
|
nav:TrySetUpRealmsButton();assert(nav.ButtonTray.count==2,'duplicate native Realms button');
|
|
nav:SetRealmsButtonEnabled(false);assert(not nav.RealmsButton.enabled);nav:SetRealmsButtonEnabled(true);assert(nav.RealmsButton.enabled);
|
|
assert(nav.MenuButton and nav.MenuButton.text=='Menu','ordinary menu is missing');
|
|
assert(not nav.StoreButton and not nav.PlunderstoreButton and not nav.SuperDistrictsButton,'hidden controls were created');
|
|
nav.RealmsButton.OnClick();
|
|
'''.replace('__NAV_OPTIONS__',options)
|
|
self.check_script(self.persistent_body(handlers,setup))
|
|
|
|
if __name__=='__main__':unittest.main()
|