Add attribute lock buttons to the switchbot window
Five per-slot toggles next to start/stop, shown only when the server sends the MTSB1 lock line; locked attributes are marked in the current attribute line. Server side: metin2-server docs/FEATURE-ATTR-LOCK.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ffe097ec57
commit
a22c064587
@@ -118,11 +118,40 @@ class SwitchbotTests(unittest.TestCase):
|
||||
text=server.read_text(encoding='latin1')
|
||||
reasons=set(re.findall(r'return "([a-z_]+)"',text))|{'running','stopped','idle'}
|
||||
errors=set(re.findall(r'error [a-z%]+ ([a-z_]+)"',text))|{'invalid','rate'}
|
||||
self.assertTrue(reasons-{'invalid','running','item','equipped','no_attr','scroll','target','busy'}<=set(self.ns['REASONS']))
|
||||
lock_errors={'slot','max','db'}
|
||||
self.assertTrue(reasons-{'invalid','running','item','equipped','no_attr','scroll','target','busy'}-lock_errors<=set(self.ns['REASONS']))
|
||||
self.assertTrue(lock_errors<=set(self.ns['ERRORS']))
|
||||
self.assertTrue(errors<=set(self.ns['ERRORS']))
|
||||
self.assertIn('kPortSwitchLimit=1000',text);self.assertEqual(max(self.ns['LIMITS']),1000)
|
||||
self.assertEqual(self.ns['MAX_TARGETS'],5)
|
||||
|
||||
def test_lock_protocol_and_buttons(self):
|
||||
self.bot.Lock(10,0);self.assertEqual(self.sent,[]) # no lock line yet: old server, no request
|
||||
self.load(self.bot);self.bot.Receive('MTSB1 lock 10 11209 2')
|
||||
self.assertEqual(self.bot.LockMask(10,11209),2);self.assertIsNone(self.bot.LockMask(10,11210))
|
||||
self.bot.Lock(10,5);self.bot.Lock(10,0);self.advance()
|
||||
self.assertEqual(self.sent[-1],'/mt_switchbot 1 lock 10 0')
|
||||
self.bot.Receive('MTSB1 lock 10 11209 3');self.assertIsNone(self.bot.waiting);self.assertEqual(self.bot.LockMask(10,11209),3)
|
||||
self.bot.Lock(10,1);self.advance();self.bot.Receive('MTSB1 error lock max');self.assertEqual(self.bot.error,'max')
|
||||
for bad in ('MTSB1 lock 10 11209','MTSB1 lock 10 11209 32'):self.bot.Receive(bad)
|
||||
self.assertEqual(self.bot.LockMask(10,11209),3)
|
||||
# Window: one button per filled slot, hidden while picking, locked attributes marked.
|
||||
game=sys.modules['game'];gw=game.GameWindow();gw.interface=types.SimpleNamespace(wndMiniMap=Widget())
|
||||
game.GameWindow.Open(gw);w=self.ns['g_window'];w.Open()
|
||||
self.assertFalse(any(b.shown for b in w.lockButtons))
|
||||
self.load(w.bot);w.bot.Receive('MTSB1 lock 10 11209 2')
|
||||
self.assertEqual([b.shown for b in w.lockButtons],[True,True,False,False,False])
|
||||
self.assertEqual([b.text for b in w.lockButtons[:2]],['锁1','【锁2】']);self.assertIn('[锁]',w.current.text.split(' / ')[1])
|
||||
self.assertIn('保持不变',w.status.text)
|
||||
self.time+=.5;w.OnUpdate();w.bot.Receive('MTSB1 state 0 0 0 0 0 0 0 idle') # answers the status request
|
||||
sent=len(self.sent);w.lockButtons[0].event();self.time+=.5;w.OnUpdate()
|
||||
self.assertEqual(self.sent[sent:],['/mt_switchbot 1 lock 10 0'])
|
||||
w.TogglePick();self.assertFalse(any(b.shown for b in w.lockButtons));w.TogglePick()
|
||||
w.bot.Receive('MTSB1 state 1 10 11209 0 100 71084 9 running');self.assertFalse(w.lockButtons[0].enabled)
|
||||
sent=len(self.sent);w.lockButtons[0].event();self.time+=.5;w.OnUpdate()
|
||||
self.assertNotIn('/mt_switchbot 1 lock 10 0',self.sent[sent:])
|
||||
game.GameWindow.Close(gw)
|
||||
|
||||
def test_window_scan_pick_start_and_notify(self):
|
||||
game=sys.modules['game'];window_type=game.GameWindow
|
||||
gw=window_type();gw.interface=types.SimpleNamespace(wndMiniMap=Widget())
|
||||
|
||||
Reference in New Issue
Block a user