def test_scripts_bad_scenefile(self): folder = SceneScript.Folder( "turberfield.dialogue.sequences.battle.logic", "test", None, ["not_there.rst"], None ) rv = list(SceneScript.scripts(**folder._asdict())) self.assertFalse(rv)
def test_scripts_bad_pkg(self): folder = SceneScript.Folder( "turberfield.dialogue.sequences.not_there", "test", None, ["combat.rst"], None ) rv = list(SceneScript.scripts(**folder._asdict())) self.assertFalse(rv)
def dialogue(self, folders, ensemble, strict=True, roles=2): """ Return the next selected scene script as compiled dialogue.""" for folder in folders: for script in SceneScript.scripts(**folder._asdict()): with script as dialogue: try: selection = dialogue.select(ensemble, roles=roles) except Exception as e: self.log.error( "Unable to process {0.fP}".format(script)) self.log.exception(e) continue if selection and all(selection.values()): self.log.debug("Selection made strictly") elif not strict and any(selection.values()): self.log.debug("Selection made") else: continue try: return dialogue.cast(selection).run() except Exception as e: self.log.error("Unable to run {0.fP}".format(script)) self.log.exception(e) continue
def test_scripts(self): folder = SceneScript.Folder( "turberfield.dialogue.sequences.battle.logic", "test", None, ["combat.rst"], None ) rv = list(SceneScript.scripts(**folder._asdict())) self.assertEqual(1, len(rv)) self.assertIsInstance(rv[0], SceneScript)
def setUp(self): self.personae = { Animal(name="Itchy").set_state(1), Animal(name="Scratchy").set_state(1), Tool(name="Rusty Chopper").set_state(1), } folder = SceneScript.Folder( "turberfield.dialogue.sequences.battle.logic", "test", None, ["combat.rst"], None ) self.script = next(SceneScript.scripts(**folder._asdict()))
def next(folders, ensemble, strict=True, roles=1): for folder in folders: scripts = SceneScript.scripts(**folder._asdict()) interludes = folder.interludes or itertools.repeat(None) for index, script, interlude in zip(itertools.count(), scripts, interludes): with script as dialogue: selection = dialogue.select(ensemble, roles=roles) if selection and all(selection.values()): return (folder, index, script, selection, interlude) elif not strict and any(selection.values()): return (folder, index, script, selection, interlude) else: return None
def entity_states(folder): for script in SceneScript.scripts(**folder._asdict()): with script as dialogue: entities = group_by_type(dialogue.doc)[Entity.Declaration] for entity in entities: yield from entity["options"].get("states", [])