Mercurial > fife-parpg
annotate clients/rio_de_hola/run.py @ 273:815354ba295e
* Added function to fife_utils: getUserDataDirectory. Returns the proper path to save setting and data files depending on OS.
* Made rio_de_hola save its settings in the proper location.
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 16 Jun 2009 14:24:26 +0000 |
parents | bb9902910067 |
children | ff8bc835260c |
rev | line source |
---|---|
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 #!/usr/bin/env python |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 # coding: utf-8 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # This is the rio de hola client for FIFE. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
5 import sys, os, re, math, random, shutil |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 def _jp(path): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 return os.path.sep.join(path.split('/')) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 _paths = ('../../engine/swigwrappers/python', '../../engine/extensions') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 for p in _paths: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 if p not in sys.path: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 sys.path.append(_jp(p)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
121
diff
changeset
|
15 import fife_compat |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 import fife, fifelog |
98
214e3eb81eb2
better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
17 from scripts import world |
214e3eb81eb2
better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
18 from scripts.common import eventlistenerbase |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 from basicapplication import ApplicationBase |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 import pychan |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 import pychan.widgets as widgets |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
22 from settings import Setting |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
24 TDS = Setting() |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 class ApplicationListener(eventlistenerbase.EventListenerBase): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 def __init__(self, engine, world): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 self.engine = engine |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 self.world = world |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 engine.getEventManager().setNonConsumableKeys([ |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
121
diff
changeset
|
32 fife.Key.ESCAPE,]) |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
33 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 self.quit = False |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 self.aboutWindow = None |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
36 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 self.rootpanel = pychan.loadXML('gui/rootpanel.xml') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 self.rootpanel.mapEvents({ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 'quitButton' : self.onQuitButtonPress, |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 'aboutButton' : self.onAboutButtonPress, |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
41 'optionsButton' : TDS.onOptionsPress |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 }) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 self.rootpanel.show() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 def keyPressed(self, evt): |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
121
diff
changeset
|
46 print evt |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 keyval = evt.getKey().getValue() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 keystr = evt.getKey().getAsString().lower() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 consumed = False |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 if keyval == fife.Key.ESCAPE: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 self.quit = True |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 evt.consume() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 elif keyval == fife.Key.F10: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 self.engine.getGuiManager().getConsole().toggleShowHide() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 evt.consume() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 elif keystr == 'p': |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 self.engine.getRenderBackend().captureScreen('screenshot.png') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 evt.consume() |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
59 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 def onCommand(self, command): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 if self.quit: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 command.consume() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 def onConsoleCommand(self, command): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 result = '' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 if command.lower() in ('quit', 'exit'): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 self.quit = True |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 result = 'quitting' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 elif command.lower() in ( 'help', 'help()' ): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 self.engine.getGuiManager().getConsole().println( open( 'misc/infotext.txt', 'r' ).read() ) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 result = "-- End of help --" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 result = self.world.onConsoleCommand(command) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 if not result: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 try: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 result = str(eval(command)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 except: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 pass |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 if not result: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 result = 'no result' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 return result |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 def onQuitButtonPress(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 cmd = fife.Command() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 cmd.setSource(None) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 cmd.setCommandType(fife.CMD_QUIT_GAME) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 self.engine.getEventManager().dispatchCommand(cmd) |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
89 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 def onAboutButtonPress(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 if not self.aboutWindow: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 self.aboutWindow = pychan.loadXML('gui/help.xml') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 self.aboutWindow.mapEvents({ 'closeButton' : self.aboutWindow.hide }) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 self.aboutWindow.distributeData({ 'helpText' : open("misc/infotext.txt").read() }) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 self.aboutWindow.show() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 class IslandDemo(ApplicationBase): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 def __init__(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 super(IslandDemo,self).__init__() |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
100 pychan.init(self.engine, debug=TDS.readSetting("PychanDebug", type='bool')) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 self.world = world.World(self.engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 self.listener = ApplicationListener(self.engine, self.world) |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
103 self.world.load(str(TDS.readSetting("MapFile"))) |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
104 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 self.soundmanager = self.engine.getSoundManager() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 self.soundmanager.init() |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
107 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
108 if int(TDS.readSetting("PlaySounds")): |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 # play track as background music |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 emitter = self.soundmanager.createEmitter() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 id = self.engine.getSoundClipPool().addResourceFromFile('music/rio_de_hola.ogg') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 emitter.setSoundClip(id) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 emitter.setLooping(True) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 emitter.play() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
116 def loadSettings(self): |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
117 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
118 Load the settings from a python file and load them into the engine. |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
119 Called in the ApplicationBase constructor. |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
120 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
121 import settings |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
122 self.settings = settings |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
123 |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
124 engineSetting = self.engine.getSettings() |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
125 engineSetting.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs", strip=False))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
126 engineSetting.setDefaultFontPath(str(TDS.readSetting("Font"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
127 engineSetting.setDefaultFontSize(12) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
128 engineSetting.setBitsPerPixel(int(TDS.readSetting("BitsPerPixel"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
129 engineSetting.setInitialVolume(float(TDS.readSetting("InitialVolume"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
130 engineSetting.setSDLRemoveFakeAlpha(int(TDS.readSetting("SDLRemoveFakeAlpha"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
131 engineSetting.setScreenWidth(int(TDS.readSetting("ScreenWidth"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
132 engineSetting.setScreenHeight(int(TDS.readSetting("ScreenHeight"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
133 engineSetting.setRenderBackend(str(TDS.readSetting("RenderBackend"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
134 engineSetting.setFullScreen(int(TDS.readSetting("FullScreen"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
135 |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
136 try: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
137 engineSetting.setWindowTitle(str(TDS.readSetting("WindowTitle"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
138 engineSetting.setWindowIcon(str(TDS.readSetting("WindowIcon"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
139 except: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
140 pass |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
141 try: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
142 engineSetting.setImageChunkingSize(int(TDS.readSetting("ImageChunkSize"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
143 except: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
144 pass |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
145 |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
146 def initLogging(self): |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
147 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
148 Initialize the LogManager. |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
149 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
150 LogModules = TDS.readSetting("LogModules", type='list') |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
151 self.log = fifelog.LogManager(self.engine, int(TDS.readSetting("LogToPrompt")), int(TDS.readSetting("LogToFile"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
152 if LogModules: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
153 self.log.setVisibleModules(*LogModules) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
154 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
155 def createListener(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
156 pass # already created in constructor |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
157 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 def _pump(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 if self.listener.quit: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 self.breakRequested = True |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 self.world.save('maps/savefile.xml') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 self.world.pump() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 def main(): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 app = IslandDemo() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 app.run() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 if __name__ == '__main__': |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
171 if TDS.readSetting("ProfilingOn", type='bool'): |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
172 import hotshot, hotshot.stats |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
173 print "Starting profiler" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
174 prof = hotshot.Profile("fife.prof") |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
175 prof.runcall(main) |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
176 prof.close() |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
177 print "analysing profiling results" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
178 stats = hotshot.stats.load("fife.prof") |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
179 stats.strip_dirs() |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
180 stats.sort_stats('time', 'calls') |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
181 stats.print_stats(20) |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
182 else: |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
183 if TDS.readSetting("UsePsyco", type='bool'): |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
184 # Import Psyco if available |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
185 try: |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
186 import psyco |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
187 psyco.full() |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
188 print "Psyco acceleration in use" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
189 except ImportError: |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
190 print "Psyco acceleration not used" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
191 else: |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
192 print "Psyco acceleration not used" |
117
5f32bfdc4232
fix for profiling crash
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
116
diff
changeset
|
193 main() |