-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobals.py
250 lines (238 loc) · 6.51 KB
/
globals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import gettext
langstring=""
try:
with open("locale/savedlng", "r") as f:
langstring=f.read()
except Exception as e:
langstring="en"
lang=gettext.translation(langstring, localedir='locale', languages=[langstring])
lang.install()
import ast
# We use this module to evaluate strings as python expretions. At least for now
import random
import movement
import os
import map
import pyglet
from pyglet.window import key
import sys
import wx
import os
from logger import Logger
from AGK.speech import auto
from AGK.mainframe import timer
from openal import *
NICK=""
c=None
me=movement.vector(0, 0, 32)
class TextEntryDialog(wx.Dialog):
def __init__(self, parent, title, caption):
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
super(TextEntryDialog, self).__init__(parent, -1, title, style=style)
text = wx.StaticText(self, -1, caption)
input = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
input.SetInitialSize((400, 300))
buttons = self.CreateButtonSizer(wx.OK|wx.CANCEL)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(text, 0, wx.ALL, 5)
sizer.Add(buttons, 0, wx.EXPAND|wx.ALL, 5)
sizer.Add(input, 1, wx.EXPAND|wx.ALL, 5)
input.SetFocus()
self.SetSizerAndFit(sizer)
self.input = input
def SetValue(self, value):
self.input.SetValue(value)
def GetValue(self):
return self.input.GetValue()
mapname=""
jumping=0
falling=0
falldamage=0
falldistance=0
ascenddistance=0
descenddistance=0
lastzone=""
zonestatus=1
zone=""
turntime=timer.timer()
falltime=timer.timer()
jumptime=timer.timer()
landtime=timer.timer()
fallingwind=oalOpen("sounds/misk/fallingwind.wav", ".wav")
fallingwind.set_source_relative(True)
fallingwind.set_gain(0.01)
fallingwind.set_looping(True)
WalkTime=40
MainWalkTime=40
airtime=10
ascending=False
loaded=False
walktimer=timer.timer()
roomsound=oalOpen("sounds/relative/room2.wav")
roomsound.set_looping(True)
currentroom=""
direction=270
listener=oalGetListener()
log=Logger()
sourcelist=[]
input=[]
connected=False
connecting=False
mainmenu=['play', 'change language', 'exit']
menupos=-1
menulist=[]
menu=False
menumusic=oalOpen("sounds/relative/menu.wav")
menumusic.set_looping(True)
menumusic.set_gain(0.3)
step=0
can_press_escape=False
def cleanup():
try:
for a in sourcelist:
if a == None or a.get_state()==AL_STOPPED:
a.destroy()
sourcelist.remove(a)
except Exception as e:
log.add_entry("\r\nError acurd on cleaning up sound sources: {0}".format(str(e)))
def getinput(title, message, multiline=False, value=""):
if multiline:
input=TextEntryDialog(None, message, title)
else:
input=wx.TextEntryDialog(None, message, title)
input.SetValue(value)
input.ShowModal()
text=input.GetValue()
input.Destroy()
return text
def reset():
global mapname, currentroom, roomsound, jumping, falling, falldamage, ascenddistance, descenddistance, falldistance, lastzone, zonestatus, ascending, loaded, WalkTime, MainWalkTime, airtime, zone, me, direction
mapname=""
jumping=0
falling=0
falldamage=0
falldistance=0
ascenddistance=0
descenddistance=0
lastzone=""
zonestatus=1
zone=""
fallingwind.set_source_relative(True)
fallingwind.set_gain(0.01)
fallingwind.set_looping(True)
WalkTime=40
MainWalkTime=40
airtime=10
ascending=False
loaded=False
walktimer=timer.timer()
currentroom=""
roomsound.stop()
direction=270
me=movement.vector(0, 0, 32)
map.door=list()
map.tiles={}
map.rooms={}
map.consoles=list()
map.randomambs=list()
def main_menu():
global menu, menulist, menupos, can_press_escape
reset()
menulist=['play', 'change language', 'exit']
menupos=-1
menu=True
can_press_escape=False
if menumusic.get_state() != AL_PLAYING:
menumusic.play()
auto.speak(_("Main menu. Select an item with up and down. Press enter to activate the item"))
def perform_action(what):
global c, menu, menumusic, menulist, menupos, can_press_escape
try:
if what == 'play':
map.parsedata("inderion station")
menumusic.stop()
menu=False
menulist=list()
elif what == 'change language':
langlist=[]
for x in find_dirs("locale"):
langlist.append("language: "+x)
langlist.append("exit to main menu")
menulist=langlist
menupos=-1
speak(_("select a language"))
menu=True
can_press_escape=False
elif what[0:10] == "language: ":
language = what.replace("language: ", "")
global lang
lang=gettext.translation(language, localedir='locale', languages=[language])
lang.install()
auto.speak(_("language set to ")+_(language))
with open("locale/savedlng", "w") as f:
f.write(language)
main_menu()
elif what == "exit to main menu":
main_menu()
elif what == "exit":
exit()
except Exception as e:
auto.speak(str(e))
def find_dirs(path):
ourlist=[]
for dir in os.listdir(path):
if os.path.isdir(os.path.join(path, dir)):
ourlist.append(dir)
return ourlist
def find_files(path):
ourlist=[]
for file in os.listdir(path):
if os.path.isfile(os.path.join(path, file)):
ourlist.append(file)
return ourlist
def checkplatform():
try:
global jumping, WalkTime
if map.tile(me.x, me.y, me.z) != "" and jumping == 1:
if "wall" not in map.tile(me.x, me.y, me.z):
tempsplit=map.mytile().split("|")
landingsounds=list()
for x in tempsplit:
landingsounds.append("sounds/footsteps/"+x+"/landing/"+str(random.randint(1, len(find_files("sounds/footsteps/"+x+"/landing"))))+".wav")
for x in landingsounds:
landsound=oalOpen(x, ".wav")
landsound.set_source_relative(True)
sourcelist.append(landsound)
landsound.play()
jumping=0
WalkTime=MainWalkTime
global step
step=0
walktimer.restart()
global ascenddistance, descenddistance
ascenddistance=0
descenddistance=0
except Exception as e:
auto.speak("\r\nError acurd on landing: {0}".format(str(e)))
def falldown():
try:
if falltime.elapsed()>=60 and falling==1:
falltime.restart()
me.z-=1
global falldistance
falldistance+=1
if fallingwind.get_state() != AL_PLAYING:
fallingwind.play()
if fallingwind.gain<2.0:
fallingwind.set_gain(fallingwind.gain+0.01)
except Exception as e:
auto.speak("\r\nError acurd while falling down: {0}".format(str(e)))
# This function tries to translate a text and then speak the translated text. If you don't want any translation use auto.speak. For more info on translation read the help file and then the persian.lng file which can be a good instance.
def speak(text):
try:
auto.speak(text)
except Exception as e:
auto.speak("Error on speaking a text: "+str(e))
def exit():
log.write("log.log")
sys.exit()