annotate demos/rpg/scripts/rpg.py @ 550:d0282579668c

Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code. Started adding more comments.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 15 Jun 2010 17:53:20 +0000
parents cb7ec12214a9
children 69d50e751c9a
rev   line source
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 #!/usr/bin/env python
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # -*- coding: utf-8 -*-
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # ####################################################################
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # Copyright (C) 2005-2010 by the FIFE team
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 # http://www.fifengine.net
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # This file is part of FIFE.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 #
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # FIFE is free software; you can redistribute it and/or
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # modify it under the terms of the GNU Lesser General Public
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 # License as published by the Free Software Foundation; either
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # version 2.1 of the License, or (at your option) any later version.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 #
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # This library is distributed in the hope that it will be useful,
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # Lesser General Public License for more details.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 #
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # You should have received a copy of the GNU Lesser General Public
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # License along with this library; if not, write to the
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # Free Software Foundation, Inc.,
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 # ####################################################################
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 # This is the rio de hola client for FIFE.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
27 import sys, os, re, math, random, shutil, time
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
28 from datetime import datetime
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 from fife import fife
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 from fife.extensions import *
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 from scripts.gamecontroller import GameController
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 from fife.extensions.basicapplication import ApplicationBase
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 from fife.extensions import pychan
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 from fife.extensions.pychan import widgets
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 from fife.extensions.fife_utils import getUserDataDirectory
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 class KeyFilter(fife.IKeyFilter):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
39 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
40 This is the implementation of the fife.IKeyFilter class.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
41
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
42 Prevents any filtered keys from being consumed by guichan.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
43 """
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 def __init__(self, keys):
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 fife.IKeyFilter.__init__(self)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 self._keys = keys
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 def isFiltered(self, event):
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 return event.getKey().getValue() in self._keys
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
51 class ApplicationListener(fife.IKeyListener, fife.ICommandListener, fife.ConsoleExecuter):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
52 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
53 Listens for window commands, console commands and keyboard input.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
54
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
55 Does not process game related input.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
56 """
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 def __init__(self, engine, gamecontroller):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
58 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
59 Initializes all listeners and registers itself with the eventmanager.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
60 """
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 self._engine = engine
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 self._gamecontroller = gamecontroller
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
63 self._eventmanager = self._engine.getEventManager()
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
65 fife.IKeyListener.__init__(self)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
66 self._eventmanager.addKeyListener(self)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
67
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
68 fife.ICommandListener.__init__(self)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
69 self._eventmanager.addCommandListener(self)
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
71 fife.ConsoleExecuter.__init__(self)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
72 self._engine.getGuiManager().getConsole().setConsoleExecuter(self)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
73
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
74 keyfilter = KeyFilter([fife.Key.ESCAPE, fife.Key.BACKQUOTE, fife.Key.PRINT_SCREEN])
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
75 keyfilter.__disown__()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
76
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
77 self._eventmanager.setKeyFilter(keyfilter)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
78
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 self.quit = False
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
81 def keyPressed(self, event):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
82 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
83 Processes any non game related keyboar input.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
84 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
85 if event.isConsumed():
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
86 return
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
87
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
88 keyval = event.getKey().getValue()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
89 keystr = event.getKey().getAsString().lower()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
90
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 if keyval == fife.Key.ESCAPE:
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 self.quit = True
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
93 event.consume()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
94 elif keyval == fife.Key.BACKQUOTE:
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
95 self._engine.getGuiManager().getConsole().toggleShowHide()
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
96 event.consume()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
97 elif keyval == fife.Key.PRINT_SCREEN:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
98 self._engine.getRenderBackend().captureScreen(time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".png")
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
99 event.consume()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
100
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
101 def keyReleased(self, event):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
102 pass
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 def onCommand(self, command):
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 if self.quit:
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 command.consume()
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 def onConsoleCommand(self, command):
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
110 result = ""
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
111
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
112 args = command.split(" ")
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
113 cmd = []
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
114 for arg in args:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
115 arg = arg.strip()
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
116 if arg != "":
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
117 cmd.append(arg)
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
118
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
119 if cmd[0].lower() in ('quit', 'exit'):
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 self.quit = True
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 result = 'quitting'
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
122 elif cmd[0].lower() in ( 'help' ):
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
123 helptextfile = self._gamecontroller.settings.get("RPG", "HelpText", "misc/help.txt")
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
124 self._engine.getGuiManager().getConsole().println( open( helptextfile, 'r' ).read() )
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
125 result = "--OK--"
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
126 elif cmd[0].lower() in ( 'eval' ):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
127 try:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
128 result = str(eval(command.lstrip(cmd[0])))
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
129 except:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
130 result = "Invalid eval statement..."
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 else:
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
132 result = self._gamecontroller.onConsoleCommand(command)
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
133
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 if not result:
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
135 result = 'Command Not Found...'
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
136
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 return result
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
138
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
139 def onToolsClick(self):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
140 print "No tools set up yet"
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 class RPGApplication(ApplicationBase):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
143 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
144 The main application. It inherits fife.extensions.ApplicationBase.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
145
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
146 Implements ApplicationBase._pump().
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
147 """
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 def __init__(self, TDS):
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 super(RPGApplication,self).__init__(TDS)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 self._settings = TDS
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 pychan.init(self.engine, debug=self._settings.get("FIFE", "PychanDebug", False))
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 self._gamecontroller = GameController(self, self.engine, self._settings)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 def createListener(self):
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 """
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 @note: This function had to be overloaded otherwise the default
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 listener would have been created.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 """
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 self._listener = ApplicationListener(self.engine, self._gamecontroller)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162 return self._listener
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 def requestQuit(self):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
165 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
166 Sends the quit command to the application's listener. We could set
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
167 self.quitRequested to true also but this is a good example on how
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
168 to build and dispatch a fife.Command.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
169 """
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 cmd = fife.Command()
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 cmd.setSource(None)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 cmd.setCommandType(fife.CMD_QUIT_GAME)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173 self.engine.getEventManager().dispatchCommand(cmd)
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 def _pump(self):
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 if self._listener.quit:
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
177 self._gamecontroller.endGame()
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
178 self.quitRequested = True
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 else:
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 self._gamecontroller.pump()
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
181
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
182
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
183 def _getLogManager(self):
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
184 return self._log
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
185
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
186 logger = property(_getLogManager)