Changeset 302:78220c989e6a


Ignore:
Timestamp:
04/08/11 21:27:43 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Rebase:
62363337396264616137333461316663343730323031343463376430376139393735646262616266
Message:

Add supporting for flicking between speaking NPCs.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • scripts/npc-test

    r281 r302  
    5858    print "  Loaded %s." % (npc.dsm)
    5959
    60     my_locals = { "world": dsm.world, "state": dsm.states, "npcs": dsm.world.npcs }
     60    def test_switch_to(npc_name):
     61        assert npc_name in game.world.npcs
     62
     63    my_locals = {
     64        "world": dsm.world,
     65        "state": dsm.states,
     66        "npcs": dsm.world.npcs,
     67        "switch_to": test_switch_to,
     68    }
    6169    my_locals.update(DsmEvent().items)
     70
    6271    for state_name, state in dsm.states.items():
    6372        print "  Testing triggers for state %s" % state_name
  • skaapsteker/dialogue.py

    r291 r302  
    22
    33from . import data
     4from .engine import OpenDialog
    45
    56
     
    3334        return bool(self.states[self.state].text)
    3435
     36    def _switch_dialogue_to(self, npc_name):
     37        """Switch dialogue to another npc."""
     38        OpenDialog.post(npc_name)
     39
    3540    def event(self, ev):
    3641        my_locals = {
     
    3843            "world": self.world,
    3944            "npcs": self.world.npcs,
     45            "switch_to": self._switch_dialogue_to,
    4046        }
    4147        my_locals.update(ev.items)
  • skaapsteker/levelscene.py

    r290 r302  
    3838        for sprite in self._level.sprites:
    3939            self._world.add(sprite)
    40         for sprite in self.game_state.create_sprites(self._level.name):
     40        npcs_and_items = game_state.create_sprites(self._level.name)
     41        self._npcs = dict((s.name, s) for s in npcs_and_items if hasattr(s, 'dsm'))
     42        for sprite in npcs_and_items:
    4143            self._world.add(sprite)
    4244        self._world.add(self._player)
     
    113115
    114116    def _open_dialogue(self, npc):
     117        if isinstance(npc, basestring):
     118            npc = self._npcs[npc]
    115119        if npc.dsm.has_text():
    116120            if self._dialogue is not None:
  • skaapsteker/sprites/base.py

    r296 r302  
    205205
    206206    def setup(self, name, world, dsm, state):
     207        self.name = name
    207208        self.dsm = dialogue.DSM(name, world, dsm, state)
    208209
Note: See TracChangeset for help on using the changeset viewer.