def setUp(self): self.folders = [ SceneScript.Folder( "turberfield.dialogue.test", "Folder 2", {"pos": 1}, ["two.rst"], None), SceneScript.Folder( "turberfield.dialogue.test", "Folder 1", {"pos": 0.5}, ["one.rst"], None), SceneScript.Folder( "turberfield.dialogue.test", "Folder 4", {"pos": 3}, ["four.rst"], None), SceneScript.Folder( "turberfield.dialogue.test", "Folder 3", {"pos": 2}, ["three.rst"], None), ]
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 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 build_folder(pkg, **kwargs): path = importlib.resources.files(pkg) description = kwargs.get("description", "") return SceneScript.Folder(pkg=pkg, description=description, metadata={}, paths=sorted(i.name for i in path.glob("*.rst")), interludes=None)
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 setUp(self): self.folders = [ SceneScript.Folder(pkg="bluemonday78", description="A Spike for Folder patterns.", metadata={"location": "inner"}, paths=[ "dialogue/outer/inner/story/scene_01.rst", ], interludes=itertools.repeat(None)) ] self.ensemble = [ Character(name="A Test Actor").set_state(10), bluemonday78.story.build_narrator() ] self.presenter = Presenter(None, self.ensemble)
def setUp(self): self.folders = [ SceneScript.Folder(pkg=None, description=None, paths=None, interludes=None, metadata=i) for i in [ { "arc": "a_01", "pathways": frozenset((("w12_latimer", "lockup"), )), "min_t": datetime.date(2020, 5, 1), "max_t": datetime.date(2020, 5, 3), }, { "arc": "a_10", "pathways": frozenset((("w12_latimer", "tavern"), )) }, { "arc": "a_11", "pathways": frozenset(( ("w12_latimer", "lockup"), ("w12_latimer", "tavern"), )), "min_t": datetime.date(2020, 5, 5), "max_t": datetime.date(2020, 5, 7), }, { "arc": "a_12", "pathways": frozenset(( ("w12_latimer", "cafe"), ("w12_latimer", "lockup"), )), "min_t": 1, "max_t": 4, }, ] ]
def generate_folders(pkg, path): root_path = pathlib.Path(pkg_resources.resource_filename(pkg, path)) yield from ( SceneScript.Folder( pkg="bluemonday78", description="Story arc: '{0}'".format(asset.arc.capitalize()), metadata={ "id": asset.id, "arc": asset.arc, "pathways": asset.pathways }, paths=[os.path.join(root_path.name, i) for i in asset.scripts], interludes=None ) for asset in bluemonday78.utils.publisher.find_assets( root_path, prefix="{0}.{1}".format(pkg, path.replace("/", ".")) ) )
def test_run_filters_conditional_content(self): parent = str(Path(__file__).parent) with tempfile.NamedTemporaryFile(dir=parent, suffix=".rst") as scriptFile: scriptFile.write( ConditionDirectiveTests.content.replace( "test_model", "test_performer").encode("utf8")) scriptFile.flush() folder = SceneScript.Folder( pkg=__name__, description="Test dialogue", metadata={}, paths=[str(Path(scriptFile.name).relative_to(parent))], interludes=None) performer = Performer([folder], ConditionDirectiveTests.effects[0:1]) output = list(performer.run()) self.assertEqual( 2, len([i for i in output if isinstance(i, Model.Line)]))
prize.set_state(0) elif locn == Location.cloakroom_space: while action not in ("c", "h", "e"): action = parse_command(cmd or input("Enter a command: ")) if action == "c": if cloak.get_state(Location) == Location.cloakroom_space: cloak.set_state(Location.cloakroom_floor) else: cloak.set_state(Location.cloakroom_space) elif action == "h": cloak.set_state(Location.cloakroom_hook) else: narrator.set_state(Location.foyer) if cloak.get_state(Location) != locn: cloak.set_state(0) if cloak.get_state(Location) == locn: cloak.set_state(narrator.get_state(Location)) cloak.set_state(1) return folder.metadata references = ensemble + [Location] folder = SceneScript.Folder(pkg=__name__, description="The 'Hello World' of text games.", metadata={}, paths=["foyer.rst", "bar.rst", "cloakroom.rst"], interludes=repeat(interaction))
from itertools import repeat from turberfield.dialogue.model import SceneScript from turberfield.dialogue.types import Persona from turberfield.dialogue.types import Stateful class Animal(Stateful, Persona): pass class Tool(Stateful, Persona): pass references = [ Animal(name="Itchy").set_state(1), Animal(name="Scratchy").set_state(1), Tool(name="Ol' Rusty Chopper").set_state(1), ] folder = SceneScript.Folder(pkg=__name__, description="Cartoon battle demo", metadata=None, paths=["combat.rst"], interludes=repeat(None))
( finder.search(label="Common house") | finder.search(label="Kitchen") ) ), ] episodes = [ SceneScript.Folder( pkg="carmen", description="Dialogue for a game episode 1.", metadata={"episode": Decimal(1)}, paths=sorted([ str(i.relative_to( pkg_resources.resource_filename("carmen", "") )) for i in pathlib.Path( pkg_resources.resource_filename("carmen", "dialogue/ep_01") ).glob("*/*.rst") ]), interludes=itertools.repeat(Rules()) ), SceneScript.Folder( pkg="carmen", description="Dialogue for game episode 2.", metadata={"episode": Decimal(2)}, paths=sorted([ str(i.relative_to( pkg_resources.resource_filename("carmen", "") )) for i in pathlib.Path(
from turberfield.dialogue.types import Stateful from turberfield.utils.assembly import Assembly __doc__ = """ A simple drama for demonstration. """ class Animal(Stateful, Persona): pass class Tool(Stateful, Persona): pass def ensemble(): return [ Animal(name="Itchy").set_state(1), Animal(name="Scratchy").set_state(1), Tool(name="Ol' Rusty Chopper").set_state(1), ] references = ensemble() folder = SceneScript.Folder( "turberfield.dialogue.sequences.battle", __doc__, None, ["combat.rst"], None ) Assembly.register(Animal, Tool)
prize.message = prize.message.replace(random.choice(prize.message), " ", 1) prize.set_state(0) elif locn == Location.cloakroom_space: while action not in ("c", "h", "e"): action = parse_command(cmd or input("Enter a command: ")) if action == "c": if cloak.get_state(Location) == Location.cloakroom_space: cloak.set_state(Location.cloakroom_floor) else: cloak.set_state(Location.cloakroom_space) elif action == "h": cloak.set_state(Location.cloakroom_hook) else: narrator.set_state(Location.foyer) if cloak.get_state(Location) != locn: cloak.set_state(0) if cloak.get_state(Location) == locn: cloak.set_state(narrator.get_state(Location)) cloak.set_state(1) return folder.metadata references = ensemble + [Location] game = SceneScript.Folder("turberfield.dialogue.sequences.cloak", __doc__, {}, ["foyer.rst", "bar.rst", "cloakroom.rst"], repeat(interaction))