PythonSwitchbot + PythonNetworkStreamPhaseGameSwitchbot from AVA2 (CG/GC 171, SWITCHBOT window 7, SLOT_TYPE_SWITCHBOT), uiswitchbot.py verbatim in SwitchbotScript.inc plus its ENABLE_SWITCHBOT glue (tooltip, mouse/inventory drag-back, interface/game hooks, zh strings, server switchbot_* messages). Entry is the minimap 洗练 button; F9 stays with auto-hunt. The client version timestamp is now "mt20261016" so the server enables the switchbot. 50348/50349 no longer open the window. Adds docs/AVA2-PARITY-PLAN.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
4.2 KiB
Python
79 lines
4.2 KiB
Python
import sys
|
|
import types
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
|
|
|
|
class Widget:
|
|
def __init__(self,*args):self.shown=False;self.page=0;self.inventoryPageIndex=0;self.size=(360,400)
|
|
def __getattr__(self,name):return lambda *args:None
|
|
def Show(self):self.shown=True
|
|
def Hide(self):self.shown=False
|
|
def IsShow(self):return self.shown
|
|
def GetGlobalPosition(self):return (10,20)
|
|
def GetHeight(self):return self.size[1]
|
|
def GetWidth(self):return self.size[0]
|
|
def SetSize(self,w,h):self.size=w,h
|
|
|
|
|
|
class Action(Widget):
|
|
def __init__(self,parent,x,y,width,label,event):super().__init__();self.label=label;self.event=event
|
|
|
|
|
|
class ItemActionsTests(unittest.TestCase):
|
|
def setUp(self):
|
|
names=('game','grp','player','ui','wndMgr','mt_biolog','mt_preview','mt_chest','mt_wiki','uiInventory','mt_battlepass')
|
|
mods={name:types.ModuleType(name) for name in names};self.mods=mods;self.actions=[];self.bag={3:(50011,2),4:(19,1)}
|
|
mods['game'].GameWindow=type('GameWindow',(),dict(Open=lambda s:None,Close=lambda s:None))
|
|
mods['uiInventory'].InventoryWindow=type('InventoryWindow',(),dict(UseItemSlot=lambda owner,cell:self.actions.append(('use',cell)),_InventoryWindow__InventoryLocalSlotPosToGlobalSlotPos=lambda owner,cell:cell))
|
|
mods['mt_battlepass'].g_window=types.SimpleNamespace(OfferTicket=lambda c,v:self.actions.append(('ticket',c,v)))
|
|
mods['ui'].Window=Widget;mods['mt_biolog'].Action=Action
|
|
mods['player'].GetItemIndex=lambda cell:self.bag.get(cell,(0,0))[0]
|
|
mods['player'].GetItemCount=lambda cell:self.bag.get(cell,(0,0))[1]
|
|
mods['wndMgr'].GetScreenWidth=lambda:1280;mods['wndMgr'].GetScreenHeight=lambda:720
|
|
mods['mt_preview'].ItemSpec=lambda v:v==19
|
|
mods['mt_preview'].Preview=lambda kind,v:self.actions.append(('preview',v))
|
|
mods['mt_chest'].Batchable=lambda v:v==50011
|
|
mods['mt_chest'].g_window=types.SimpleNamespace(Select=lambda c,v:self.actions.append(('chest',c,v)))
|
|
mods['mt_wiki'].OpenItem=lambda v:self.actions.append(('wiki',v))
|
|
self.previous={n:sys.modules.get(n) for n in mods};sys.modules.update(mods)
|
|
text=(ROOT/'src/platform/ScriptLib/ItemActionsScript.inc').read_text().split('R"PY(',1)[1].rsplit(')PY";',1)[0]
|
|
self.ns={'__name__':'mt_item_actions'};exec(text,self.ns)
|
|
self.game=mods['game'].GameWindow();self.game.Open();self.window=self.ns['g_window'];self.owner=Widget();self.owner.Show()
|
|
|
|
def tearDown(self):
|
|
self.game.Close()
|
|
for n,value in self.previous.items():
|
|
if value is None:sys.modules.pop(n,None)
|
|
else:sys.modules[n]=value
|
|
|
|
def test_chest_and_preview_actions(self):
|
|
self.ns['ShowInventory'](self.owner,3)
|
|
self.assertEqual([b.label for b in self.window.buttons],['百科','批量开箱','关闭'])
|
|
self.window.buttons[1].event();self.assertEqual(self.actions,[('chest',3,50011)])
|
|
self.ns['ShowInventory'](self.owner,4)
|
|
self.window.buttons[1].event();self.assertEqual(self.actions[-1],('preview',19))
|
|
|
|
def test_ticket_and_original_use(self):
|
|
inventory=self.mods['uiInventory'].InventoryWindow()
|
|
for vnum in (25159,50348,50349,27001):
|
|
self.bag[5]=(vnum,1);inventory.UseItemSlot(5)
|
|
self.assertEqual(self.actions,[('ticket',5,25159),('use',5),('use',5),('use',5)]) # 50348/50349 no longer open the switchbot window
|
|
|
|
def test_stale_actions_never_fire(self):
|
|
for change in ('page','vnum','count','closed'):
|
|
self.owner.Show();self.owner.inventoryPageIndex=0;self.bag[3]=(50011,2)
|
|
self.ns['ShowInventory'](self.owner,3);button=self.window.buttons[1]
|
|
if change=='page':self.owner.inventoryPageIndex=1
|
|
elif change=='vnum':self.bag[3]=(19,2)
|
|
elif change=='count':self.bag[3]=(50011,1)
|
|
else:self.owner.Hide()
|
|
button.event();self.assertEqual(self.actions,[]);self.assertFalse(self.window.IsShow())
|
|
self.owner.Show();self.ns['ShowInventory'](self.owner,3);self.owner.Hide();self.window.OnUpdate()
|
|
self.assertFalse(self.window.IsShow())
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|