annotate clients/rio_de_hola/run.py @ 363:714673208050

Adding the CameraEdit plugin to the editor. You must enable it in your settings.xml file. Still not fully tested.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 21 Oct 2009 15:19:59 +0000
parents ff8bc835260c
children
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
299
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
23 from fife_utils import getUserDataDirectory
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
25 TDS = Setting()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 class ApplicationListener(eventlistenerbase.EventListenerBase):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 def __init__(self, engine, world):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 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
30 self.engine = engine
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 self.world = world
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 engine.getEventManager().setNonConsumableKeys([
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
33 fife.Key.ESCAPE,])
116
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
34
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 self.quit = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 self.aboutWindow = None
116
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
37
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 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
39 self.rootpanel.mapEvents({
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 'quitButton' : self.onQuitButtonPress,
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 'aboutButton' : self.onAboutButtonPress,
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
42 'optionsButton' : TDS.onOptionsPress
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 })
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 self.rootpanel.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 def keyPressed(self, evt):
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
47 print evt
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 keyval = evt.getKey().getValue()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 keystr = evt.getKey().getAsString().lower()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 consumed = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 if keyval == fife.Key.ESCAPE:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 self.quit = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 evt.consume()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 elif keyval == fife.Key.F10:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 self.engine.getGuiManager().getConsole().toggleShowHide()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 evt.consume()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 elif keystr == 'p':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 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
59 evt.consume()
116
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
60
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 def onCommand(self, command):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 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
63 if self.quit:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 command.consume()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 def onConsoleCommand(self, command):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 result = ''
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 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
69 self.quit = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 result = 'quitting'
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 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
72 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
73 result = "-- End of help --"
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 result = self.world.onConsoleCommand(command)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 if not result:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 try:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 result = str(eval(command))
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 except:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 if not result:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 result = 'no result'
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 return result
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 def onQuitButtonPress(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 cmd = fife.Command()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 cmd.setSource(None)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 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
89 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
90
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 def onAboutButtonPress(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 if not self.aboutWindow:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 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
94 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
95 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
96 self.aboutWindow.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 class IslandDemo(ApplicationBase):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 def __init__(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 super(IslandDemo,self).__init__()
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
101 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
102 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
103 self.listener = ApplicationListener(self.engine, self.world)
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
104 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
105
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 self.soundmanager = self.engine.getSoundManager()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 self.soundmanager.init()
116
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
108
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
109 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
110 # play track as background music
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 emitter = self.soundmanager.createEmitter()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 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
113 emitter.setSoundClip(id)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 emitter.setLooping(True)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115 emitter.play()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
117 def loadSettings(self):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
118 """
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
119 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
120 Called in the ApplicationBase constructor.
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
121 """
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
122 import settings
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
123 self.settings = settings
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
124
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
125 engineSetting = self.engine.getSettings()
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
126 engineSetting.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs", strip=False)))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
127 engineSetting.setDefaultFontPath(str(TDS.readSetting("Font")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
128 engineSetting.setDefaultFontSize(12)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
129 engineSetting.setBitsPerPixel(int(TDS.readSetting("BitsPerPixel")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
130 engineSetting.setInitialVolume(float(TDS.readSetting("InitialVolume")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
131 engineSetting.setSDLRemoveFakeAlpha(int(TDS.readSetting("SDLRemoveFakeAlpha")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
132 engineSetting.setScreenWidth(int(TDS.readSetting("ScreenWidth")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
133 engineSetting.setScreenHeight(int(TDS.readSetting("ScreenHeight")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
134 engineSetting.setRenderBackend(str(TDS.readSetting("RenderBackend")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
135 engineSetting.setFullScreen(int(TDS.readSetting("FullScreen")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
136
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
137 try:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
138 engineSetting.setWindowTitle(str(TDS.readSetting("WindowTitle")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
139 engineSetting.setWindowIcon(str(TDS.readSetting("WindowIcon")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
140 except:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
141 pass
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
142 try:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
143 engineSetting.setImageChunkingSize(int(TDS.readSetting("ImageChunkSize")))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
144 except:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
145 pass
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
146
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
147 def initLogging(self):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
148 """
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
149 Initialize the LogManager.
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
150 """
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
151 LogModules = TDS.readSetting("LogModules", type='list')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
152 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
153 if LogModules:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
154 self.log.setVisibleModules(*LogModules)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
155
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 def createListener(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 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
158
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 def _pump(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 if self.listener.quit:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 self.breakRequested = True
299
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
162
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
163 # get the correct directory to save the map file to
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
164 mapSaveDir = getUserDataDirectory("fife", "rio_de_hola") + "/maps"
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
165
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
166 # create the directory structure if it does not exist
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
167 if not os.path.isdir(mapSaveDir):
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
168 os.makedirs(mapSaveDir)
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
169
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
170 # save map file to directory
ff8bc835260c Changed the location where rio_de_hola client puts the savefile.xml by using the getUserDataDirectory utility function to fix the permission denied error seen by LinuxDonald.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 273
diff changeset
171 self.world.save(mapSaveDir + "/savefile.xml")
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173 self.world.pump()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 def main():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 app = IslandDemo()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 app.run()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 if __name__ == '__main__':
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
181 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
182 import hotshot, hotshot.stats
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
183 print "Starting profiler"
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
184 prof = hotshot.Profile("fife.prof")
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
185 prof.runcall(main)
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
186 prof.close()
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
187 print "analysing profiling results"
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
188 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
189 stats.strip_dirs()
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
190 stats.sort_stats('time', 'calls')
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
191 stats.print_stats(20)
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
192 else:
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 117
diff changeset
193 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
194 # Import Psyco if available
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
195 try:
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
196 import psyco
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
197 psyco.full()
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
198 print "Psyco acceleration in use"
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
199 except ImportError:
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
200 print "Psyco acceleration not used"
c6b9e63a51d8 * Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
201 else:
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
202 print "Psyco acceleration not used"
117
5f32bfdc4232 fix for profiling crash
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 116
diff changeset
203 main()