summaryrefslogtreecommitdiff
path: root/vba.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-03-04 03:08:00 -0600
committerBryan Bishop <kanzure@gmail.com>2013-03-04 03:08:00 -0600
commitee4a7b53dd80651d526b7786c7fe9888741642f3 (patch)
tree558230564839ec8d95f82c1a8de5ccb647130dcc /vba.py
parentbb839a1f9e83e6855c27ff61f782cc8bb41a14d4 (diff)
vba - keyboard input optimization
original-commit-id: 0fa5d9a16217993922c88f7ec83ae99857a31267
Diffstat (limited to 'vba.py')
-rw-r--r--vba.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/vba.py b/vba.py
index c1ff353..b8c3dc9 100644
--- a/vba.py
+++ b/vba.py
@@ -104,6 +104,11 @@ Gb.loadVBA()
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):
raise Exception("rom_path is not configured properly; edit vba_config.py?")
@@ -163,6 +168,10 @@ def button_combiner(buttons):
buttons.replace("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:
result |= button_masks[each]
@@ -827,6 +836,25 @@ class crystal:
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
def set_partymon2():
"""
This causes corruption, so it's not working yet.
@@ -896,6 +924,14 @@ class TestEmulator(unittest.TestCase):
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__":
unittest.main()