# HG changeset patch # User Simon Cross # Date 1302119094 -7200 # Node ID 897eec397cbbc149f60addfadbfc9526331d314e # Parent 52344e9cab8265b8ce6f82b4e3116bf0cf7ef232 Fix state checks for hattori, ichiro, kaneda and kumiko. In the process provide easier access to other npcs. diff -r 52344e9cab82 -r 897eec397cbb data/npcs/hattori.json --- a/data/npcs/hattori.json Wed Apr 06 21:39:30 2011 +0200 +++ b/data/npcs/hattori.json Wed Apr 06 21:44:54 2011 +0200 @@ -2,31 +2,31 @@ "start" : { "text" : "Ichiro, there is nothing to fear. Uesugi will light the signal fire if they come close.", "events" : [ - { "matches" : "world.npc_is('ichiro', 'prepared')", "next": "state.wait" } + { "matches" : "npcs.ichiro.state == 'prepared'", "next": "state.wait" } ] }, "wait" : { "text" : "There’s nothing more for us to do but sit and wait. Sasuke will arrive with our cannon in a while. We can’t take on the entire Hayashi clan without it.", "events" : [ - { "matches" : "world.npc_is('ichiro', 'sitting')", "next": "state.relax" } + { "matches" : "npcs.ichiro.state == 'sitting'", "next": "state.relax" } ] }, "relax" : { "text" : "Relax! You’re with me, the most fearsome katana in the East. We’re not moving from this spot until we have to. Besides, I need to meditate.", "events" : [ - { "matches" : "world.npc_is('ichiro', 'but')", "next": "state.omm" } + { "matches" : "npcs.ichiro.state == 'but'", "next": "state.omm" } ] }, "omm" : { "text" : "Ommmmm...", "events" : [ - { "matches" : "world.npc_is('ichiro', 'wakeup')", "next": "state.letsgo" } + { "matches" : "npcs.ichiro.state == 'wakeup'", "next": "state.letsgo" } ] }, "letsgo" : { "text" : "Ha- huh? Uesugi’s fire! Let’s go!", "events" : [ - { "matches" : "world.npc_is('ichiro', 'cannon')", "next": "state.attack" } + { "matches" : "npcs.ichiro.state == 'cannon'", "next": "state.attack" } ] }, "attack" : { diff -r 52344e9cab82 -r 897eec397cbb data/npcs/ichiro.json --- a/data/npcs/ichiro.json Wed Apr 06 21:39:30 2011 +0200 +++ b/data/npcs/ichiro.json Wed Apr 06 21:44:54 2011 +0200 @@ -2,43 +2,43 @@ "start" : { "text" : "I’m telling you, Hattori. The Hayashi clan will arrive any minute now.", "events" : [ - { "matches" : "world.npc_is('hattori', 'start')", "next": "state.prepared" } + { "matches" : "world.npcs.hattori.state == 'start'", "next": "state.prepared" } ] }, "prepared" : { "text" : "It doesn’t hurt to be prepared.", "events" : [ - { "matches" : "world.npc_is('hattori', 'wait')", "next": "state.sitting" } + { "matches" : "npcs.hattori.state == 'wait'", "next": "state.sitting" } ] }, "sitting" : { "text" : "I just don’t like sitting out in the open like this.", "events" : [ - { "matches" : "world.npc_is('hattori', 'relax')", "next": "state.but" } + { "matches" : "npcs.hattori.state == 'relax'", "next": "state.but" } ] }, "but" : { "text" : "But-", "events" : [ - { "matches" : "world.npc_is('hattori', 'omm')", "next": "state.sigh" } + { "matches" : "npcs.hattori.state == 'omm'", "next": "state.sigh" } ] }, "sigh" : { "text" : "Sigh.", "events" : [ - { "matches" : "world.fire_started()", "next": "state.wakeup" } + { "matches" : "world.fire_started", "next": "state.wakeup" } ] }, "wakeup" : { "text" : "Hattori, wake up! Look! Smoke coming over the rise.", "events" : [ - { "matches" : "world.npc_is('hattori', 'letsgo')", "next": "state.cannon" } + { "matches" : "npcs.hattori.state == 'letsgo'", "next": "state.cannon" } ] }, "cannon" : { "text" : "What about the cannon?", "events" : [ - { "matches" : "world.npc_is('hattori', 'attack')", "next": "state.gone" } + { "matches" : "npcs.hattori.state == 'attack'", "next": "state.gone" } ] }, "gone" : { diff -r 52344e9cab82 -r 897eec397cbb data/npcs/kaneda.json --- a/data/npcs/kaneda.json Wed Apr 06 21:39:30 2011 +0200 +++ b/data/npcs/kaneda.json Wed Apr 06 21:44:54 2011 +0200 @@ -1,44 +1,44 @@ { "start" : { "events" : [ - { "matches" : "world.npc_is('kumiko', 'torn')", "next": "state.kumiko" } + { "matches" : "npcs.kumiko.state == 'torn'", "next": "state.kumiko" } ] }, "kumiko" : { "text" : "Ah, here is the fabled beauty, Kumiko.", "auto_next": "state." "events" : [ - { "matches" : "world.npc_is('kumiko', 'kaneda')", "next": "state.tear" } + { "matches" : "npcs.kumiko.state == 'kaneda'", "next": "state.tear" } ] }, "tear" : { "text" : "When I heard of your legendary charm, I rushed to your home right away. It is true what they say about your radiant glow. Ah, but what’s this? A tear?", "events" : [ - { "matches" : "world.npc_is('kumiko', 'jumped')", "next": "state.vase" } + { "matches" : "npcs.kumiko.state == 'jumped'", "next": "state.vase" } ] }, "vase" : { "text" : "Hmm, well, never mind that. Do show me around your charming home. Hmm? Is that a broken vase I see?", "events" : [ - { "matches" : "world.npc_is('kumiko', 'fallen')", "next": "state.hmm" } + { "matches" : "npcs.kumiko.state == 'fallen'", "next": "state.hmm" } ] }, "hmm" : { "text" : "Hmm.", "events" : [ - { "matches" : "world.npc_is('kumiko', 'shallwe')", "next": "state.smell" } + { "matches" : "npcs.kumiko.state == 'shallwe'", "next": "state.smell" } ] }, "smell" : { "text" : "Yes. But only if you explain that horrible smell!", "events" : [ - { "matches" : "world.npc_is('kumiko', 'dropped')", "next": "state.wontstand" } + { "matches" : "npcs.kumiko.state == 'dropped'", "next": "state.wontstand" } ] }, "wontstand" : { "text" : "Kumiko-san, I won’t stand for this! A torn kimono, a house in disarray, dirt everywhere and that pungent stench. You are clearly no home maker! And to blame it all on a fox?", "events" : [ - { "matches" : "world.npc_is('kumiko', 'but')", "next": "state.wonthear" } + { "matches" : "npcs.kumiko.state == 'but'", "next": "state.wonthear" } ] }, "wonthear" : { diff -r 52344e9cab82 -r 897eec397cbb data/npcs/kumiko.json --- a/data/npcs/kumiko.json Wed Apr 06 21:39:30 2011 +0200 +++ b/data/npcs/kumiko.json Wed Apr 06 21:44:54 2011 +0200 @@ -6,61 +6,61 @@ "temptingfate" : { "text" : "The room smells fresh, I have my best kimono on and I’ve set out my most magnificent vase. Everything is perfect (just like me)!", "events" : [ - { "matches" : "world.vase_broken()", "next": "state.broken" } + { "matches" : "world.vase_broken", "next": "state.broken" } ] }, "broken" : { "text" : "Oh no, my beautiful vase! What will the businessman think to see it broken on the floor?", "events" : [ - { "matches" : "world.fish_in_house()", "next": "state.badsmell" } + { "matches" : "world.fish_in_house", "next": "state.badsmell" } ] }, "badsmell" : { "text" : "Oh my, what is that terrible smell? Rotten fish? Oh, this won’t do at all!", "events" : [ - { "matches" : "world.torn_kimono()", "next": "state.torn" } + { "matches" : "world.torn_kimono", "next": "state.torn" } ] }, "torn" : { "text" : "Shoo, dirty fox! Oh, look what you’ve done – you’ve made a great big tear in my finest silk kimono. What will the businessman think of a ragged dress like this?", "events" : [ - { "matches" : "world.npc_is('kaneda','kumiko')", "next": "state.kaneda" } + { "matches" : "npcs.kaneda.state == 'kumiko'", "next": "state.kaneda" } ] }, "kaneda" : { "text" : "Kaneda-san! I have been waiting for you.", "events" : [ - { "matches" : "world.npc_is('kaneda','tear')", "next": "state.jumped" } + { "matches" : "npcs.kaneda.state == 'tear'", "next": "state.jumped" } ] }, "jumped" : { "text" : "Oh, Kaneda-san, a dirty little fox jumped on me just as you were approaching and ripped my kimono.", "events" : [ - { "matches" : "world.npc_is('kaneda','vase')", "next": "state.fallen" } + { "matches" : "npcs.kaneda.state == 'vase'", "next": "state.fallen" } ] }, "fallen" : { "text" : "I am sorry, Kaneda-san, it must just have fallen over. It was probably pushed by that mean-spirited fox.", "events" : [ - { "matches" : "world.npc_is('kaneda','hmm')", "next": "state.shallwe" } + { "matches" : "npcs.kaneda.state == 'hmm'", "next": "state.shallwe" } ] }, "shallwe" : { "text" : "Shall we- go on?", "events" : [ - { "matches" : "world.npc_is('kaneda','smell')", "next": "state.dropped" } + { "matches" : "npcs.kaneda.state == 'smell'", "next": "state.dropped" } ] }, "dropped" : { "text" : "I- A fox came in and dropped an old fish?", "events" : [ - { "matches" : "world.npc_is('kaneda','wontstand')", "next": "state.but" } + { "matches" : "npcs.kaneda.state == 'wontstand'", "next": "state.but" } ] }, "but" : { "text" : "But-", "events" : [ - { "matches" : "world.npc_is('kaneda','wonthear')", "next": "state.curse" } + { "matches" : "npcs.kaneda.state == 'wonthear'", "next": "state.curse" } ] }, "curse" : { diff -r 52344e9cab82 -r 897eec397cbb skaapsteker/dialogue.py --- a/skaapsteker/dialogue.py Wed Apr 06 21:39:30 2011 +0200 +++ b/skaapsteker/dialogue.py Wed Apr 06 21:44:54 2011 +0200 @@ -15,9 +15,11 @@ Something to allow states to introspect the game state with. """ - def __init__(self, json_filename, world): + def __init__(self, name, world, json_filename): + me = getattr(world.npcs, name) + self.state = getattr(me, 'state', 'start') + me.state = self.state self.world = world - self.state = "start" self.states = AttrDict() src = json.loads(data.load(json_filename).read()) for state, state_src in src.iteritems(): @@ -31,7 +33,8 @@ def event(self, ev): my_locals = { "state": self.states, - "world" : self.world, + "world": self.world, + "npcs": self.world.npcs, } my_locals.update(ev.items) state = self.states[self.state] diff -r 52344e9cab82 -r 897eec397cbb skaapsteker/gamestate.py --- a/skaapsteker/gamestate.py Wed Apr 06 21:39:30 2011 +0200 +++ b/skaapsteker/gamestate.py Wed Apr 06 21:44:54 2011 +0200 @@ -48,13 +48,13 @@ def create_sprites(self, level): sprites = [] - for stype, key, needs_world in [ - ('items', 'items', False), - ('npcs', 'npcs', True)]: - for sprite_dict in self.data[key].values(): + for stype, key in [ + ('items', 'items'), + ('npcs', 'npcs')]: + for sprite_name, sprite_dict in self.data[key].items(): sprite_dict = sprite_dict.copy() - if needs_world: - sprite_dict['world'] = self.world + sprite_dict['name'] = sprite_name + sprite_dict['world'] = self.world if sprite_dict.pop('level') == level: sprites.append(find_sprite(sprite_dict, stype)) return sprites diff -r 52344e9cab82 -r 897eec397cbb skaapsteker/sprites/base.py --- a/skaapsteker/sprites/base.py Wed Apr 06 21:39:30 2011 +0200 +++ b/skaapsteker/sprites/base.py Wed Apr 06 21:44:54 2011 +0200 @@ -60,8 +60,8 @@ self._layer = Layers.PLAYER self.setup(**opts) - def setup(self, dsm, world): - self.dsm = dialogue.DSM(dsm, world) + def setup(self, name, world, dsm): + self.dsm = dialogue.DSM(name, world, dsm) class Projectile(Sprite): @@ -88,7 +88,7 @@ self.setup(**opts) - def setup(self): + def setup(self, name, world): pass