summaryrefslogtreecommitdiff
path: root/pokemontools/vba/autoplayer.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-09-22 00:28:43 -0500
committerBryan Bishop <kanzure@gmail.com>2013-09-22 00:28:43 -0500
commitc44ab9b5565a46004b17d87fdfefcd515b0adbf9 (patch)
treef441a552e7b742c74727bdac0359fd5ca83cbcf8 /pokemontools/vba/autoplayer.py
parent713c4ceb7736c620cb1626745d0c5bbfec3e22b1 (diff)
make the skippable decorator use config
Use the pokemontools configuration to determine where to save the save states.
Diffstat (limited to 'pokemontools/vba/autoplayer.py')
-rw-r--r--pokemontools/vba/autoplayer.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/pokemontools/vba/autoplayer.py b/pokemontools/vba/autoplayer.py
index a63caa8..ee1a0c7 100644
--- a/pokemontools/vba/autoplayer.py
+++ b/pokemontools/vba/autoplayer.py
@@ -4,6 +4,8 @@ Programmatic speedrun of Pokémon Crystal
"""
import os
+import pokemontools.configuration as configuration
+
# bring in the emulator and basic tools
import vba as _vba
@@ -11,11 +13,11 @@ def skippable(func):
"""
Makes a function skippable.
- Saves the state before and after the function runs.
- Pass "skip=True" to the function to load the previous save
- state from when the function finished.
+ Saves the state before and after the function runs. Pass "skip=True" to the
+ function to load the previous save state from when the function finished.
"""
def wrapped_function(*args, **kwargs):
+ self = args[0]
skip = True
if "skip" in kwargs.keys():
@@ -25,17 +27,17 @@ def skippable(func):
# override skip if there's no save
if skip:
full_name = func.__name__ + "-end.sav"
- if not os.path.exists(os.path.join(vba.save_state_path, full_name)):
+ if not os.path.exists(os.path.join(self.config.save_state_path, full_name)):
skip = False
return_value = None
if not skip:
- _vba.save_state(func.__name__ + "-start", override=True)
+ self.cry.save_state(func.__name__ + "-start", override=True)
return_value = func(*args, **kwargs)
- _vba.save_state(func.__name__ + "-end", override=True)
+ self.cry.save_state(func.__name__ + "-end", override=True)
elif skip:
- _vba.set_state(vba.load_state(func.__name__ + "-end"))
+ self.cry.vba.set_state(self.cry.vba.load_state(func.__name__ + "-end"))
return return_value
return wrapped_function
@@ -48,8 +50,17 @@ class Runner(object):
pass
class SpeedRunner(Runner):
+ def __init__(self, cry=None, config=None):
+ self.cry = cry
+
+ if not config:
+ config = configuration.Config()
+
+ self.config = config
+
def setup(self):
- self.cry = _vba.crystal()
+ if not self.cry:
+ self.cry = _vba.crystal(config=config)
def main(self):
"""