# HG changeset patch # User Simon Cross # Date 1302298063 -7200 # Node ID 78220c989e6a62f9d5d59812ebc6d9fa2d7cf1ed # Parent 922155cc0efd870c1c30d6d93fa87294f6263594 Add supporting for flicking between speaking NPCs. diff -r 922155cc0efd -r 78220c989e6a scripts/npc-test --- a/scripts/npc-test Fri Apr 08 23:16:11 2011 +0200 +++ b/scripts/npc-test Fri Apr 08 23:27:43 2011 +0200 @@ -57,8 +57,17 @@ dsm = DSM(npc_name, game.world, npc.dsm, npc.state) print " Loaded %s." % (npc.dsm) - my_locals = { "world": dsm.world, "state": dsm.states, "npcs": dsm.world.npcs } + def test_switch_to(npc_name): + assert npc_name in game.world.npcs + + my_locals = { + "world": dsm.world, + "state": dsm.states, + "npcs": dsm.world.npcs, + "switch_to": test_switch_to, + } my_locals.update(DsmEvent().items) + for state_name, state in dsm.states.items(): print " Testing triggers for state %s" % state_name for trigger in state.triggers: diff -r 922155cc0efd -r 78220c989e6a skaapsteker/dialogue.py --- a/skaapsteker/dialogue.py Fri Apr 08 23:16:11 2011 +0200 +++ b/skaapsteker/dialogue.py Fri Apr 08 23:27:43 2011 +0200 @@ -1,6 +1,7 @@ import json from . import data +from .engine import OpenDialog class DSM(object): @@ -32,11 +33,16 @@ self.poke() return bool(self.states[self.state].text) + def _switch_dialogue_to(self, npc_name): + """Switch dialogue to another npc.""" + OpenDialog.post(npc_name) + def event(self, ev): my_locals = { "state": self.states, "world": self.world, "npcs": self.world.npcs, + "switch_to": self._switch_dialogue_to, } my_locals.update(ev.items) state = self.states[self.state] diff -r 922155cc0efd -r 78220c989e6a skaapsteker/levelscene.py --- a/skaapsteker/levelscene.py Fri Apr 08 23:16:11 2011 +0200 +++ b/skaapsteker/levelscene.py Fri Apr 08 23:27:43 2011 +0200 @@ -37,7 +37,9 @@ for sprite in self._level.sprites: self._world.add(sprite) - for sprite in self.game_state.create_sprites(self._level.name): + npcs_and_items = game_state.create_sprites(self._level.name) + self._npcs = dict((s.name, s) for s in npcs_and_items if hasattr(s, 'dsm')) + for sprite in npcs_and_items: self._world.add(sprite) self._world.add(self._player) @@ -112,6 +114,8 @@ self._paused = True def _open_dialogue(self, npc): + if isinstance(npc, basestring): + npc = self._npcs[npc] if npc.dsm.has_text(): if self._dialogue is not None: self._dialogue.close() diff -r 922155cc0efd -r 78220c989e6a skaapsteker/sprites/base.py --- a/skaapsteker/sprites/base.py Fri Apr 08 23:16:11 2011 +0200 +++ b/skaapsteker/sprites/base.py Fri Apr 08 23:27:43 2011 +0200 @@ -204,6 +204,7 @@ self._layer = Layers.PLAYER def setup(self, name, world, dsm, state): + self.name = name self.dsm = dialogue.DSM(name, world, dsm, state) def player_action(self, player):