You've already forked pokecrystal-board
mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-09-08 08:13:02 -07:00
vba - keyboard input optimization
This commit is contained in:
@@ -104,6 +104,11 @@ Gb.loadVBA()
|
|||||||
|
|
||||||
from vba_config import *
|
from vba_config import *
|
||||||
|
|
||||||
|
try:
|
||||||
|
import vba_keyboard as keyboard
|
||||||
|
except ImportError:
|
||||||
|
print "Not loading the keyboard module (which uses networkx)."
|
||||||
|
|
||||||
if not os.path.exists(rom_path):
|
if not os.path.exists(rom_path):
|
||||||
raise Exception("rom_path is not configured properly; edit vba_config.py?")
|
raise Exception("rom_path is not configured properly; edit vba_config.py?")
|
||||||
|
|
||||||
@@ -163,6 +168,10 @@ def button_combiner(buttons):
|
|||||||
buttons.replace("select", "")
|
buttons.replace("select", "")
|
||||||
result |= button_masks["select"]
|
result |= button_masks["select"]
|
||||||
|
|
||||||
|
if isinstance(buttons, list):
|
||||||
|
if len(buttons) > 9:
|
||||||
|
raise Exception("can't combine more than 9 buttons at a time")
|
||||||
|
|
||||||
for each in buttons:
|
for each in buttons:
|
||||||
result |= button_masks[each]
|
result |= button_masks[each]
|
||||||
|
|
||||||
@@ -826,6 +835,25 @@ class crystal:
|
|||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def keyboard_apply(button_sequence):
|
||||||
|
"""
|
||||||
|
Applies a sequence of buttons to the on-screen keyboard.
|
||||||
|
"""
|
||||||
|
for buttons in button_sequence:
|
||||||
|
press(buttons)
|
||||||
|
nstep(2)
|
||||||
|
press([])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def write(something="TrAiNeR"):
|
||||||
|
"""
|
||||||
|
Uses a planning algorithm to type out a word in the most efficient way
|
||||||
|
possible.
|
||||||
|
"""
|
||||||
|
button_sequence = keyboard.plan_typing(something)
|
||||||
|
crystal.keyboard_apply([[x] for x in button_sequence])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_partymon2():
|
def set_partymon2():
|
||||||
"""
|
"""
|
||||||
@@ -896,6 +924,14 @@ class TestEmulator(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertTrue("TRAINER" in text)
|
self.assertTrue("TRAINER" in text)
|
||||||
|
|
||||||
|
class TestWriter(unittest.TestCase):
|
||||||
|
def test_very_basic(self):
|
||||||
|
button_sequence = keyboard.plan_typing("an")
|
||||||
|
expected_result = ["select", "a", "d", "r", "r", "r", "r", "a"]
|
||||||
|
|
||||||
|
self.assertEqual(len(expected_result), len(button_sequence))
|
||||||
|
self.assertEqual(expected_result, button_sequence)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
563
extras/vba_keyboard.py
Normal file
563
extras/vba_keyboard.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user