-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
yorg.py
executable file
·334 lines (315 loc) · 13.1 KB
/
yorg.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import argparse, sys
from sys import platform, path
from logging import info
from importlib import reload
from copy import deepcopy
from os import walk
from os.path import exists, dirname
from json import load
from panda3d.core import Filename
from yyagl.game import Game
from yyagl.dictfile import DctFile
from yyagl.engine.configuration import Cfg, GuiCfg, ProfilingCfg, LangCfg, \
CursorCfg, DevCfg
from yyagl.engine.gui.menu import MenuProps, NavInfo, NavInfoPerPlayer
from yyagl.engine.logic import EngineLogic
from yyagl.lib.p3d.p3d import LibP3d
from yracing.gameprops import GameProps
from yracing.driver.driver import Driver
from .logic import YorgLogic
from .event import YorgEvent
from .fsm import YorgFsm
from .audio import YorgAudio
from .client import YorgClient
from .thanksnames import ThanksNames
class DriverPaths:
def __init__(self, path, path_sel):
self.path = path
self.path_sel = path_sel
class DamageInfo:
def __init__(self, low, hi):
self.low = low
self.hi = hi
class WheelGfxNames:
def __init__(self, front, rear, both):
self.front = front
self.rear = rear
self.both = both
class Yorg(Game):
def __init__(self):
default_opt = {
'settings': {
'lang': 'en',
'volume': 1,
'fullscreen': 0,
'resolution': '1280 720',
'antialiasing': 0,
'cars_number': 8,
'keys': {
'forward1': 'raw-arrow_up',
'rear1': 'raw-arrow_down',
'left1': 'raw-arrow_left',
'right1': 'raw-arrow_right',
'fire1': 'raw-rcontrol',
'respawn1': 'raw-rshift',
'forward2': 'raw-w',
'rear2': 'raw-s',
'left2': 'raw-a',
'right2': 'raw-d',
'fire2': 'raw-x',
'respawn2': 'raw-c',
'forward3': 'raw-i',
'rear3': 'raw-k',
'left3': 'raw-j',
'right3': 'raw-l',
'fire3': 'raw-n',
'respawn3': 'raw-m',
'forward4': 'raw-t',
'rear4': 'raw-g',
'left4': 'raw-f',
'right4': 'raw-h',
'fire4': 'raw-v',
'respawn4': 'raw-b'
},
'joystick': {
'forward1': 'rtrigger',
'rear1': 'ltrigger',
'fire1': 'face_x',
'respawn1': 'face_y',
'menu1': 'rshoulder',
'forward2': 'rtrigger',
'rear2': 'ltrigger',
'fire2': 'face_x',
'respawn2': 'face_y',
'menu2': 'rshoulder',
'forward3': 'rtrigger',
'rear3': 'ltrigger',
'fire3': 'face_x',
'respawn3': 'face_y',
'menu3': 'rshoulder',
'forward4': 'rtrigger',
'rear4': 'ltrigger',
'fire4': 'face_x',
'respawn4': 'face_y',
'menu4': 'rshoulder'},
'last_version': '0.7.0-x',
'player_names': [],
'stored_player_names': [],
'shaders': 1,
'camera': 'top',
'login':
{'usr': '', 'pwd': ''}},
'development': {
'multithreaded_render': 1,
'ai': 0,
'ai_debug': 0,
'fps': 0,
'cars': '',
'track': '',
'start_wp': '',
'shaders_dev': 0,
'pbr': 0,
'gamma': 2.2,
'show_waypoints': 0,
'show_exit': 1,
'menu_joypad': 1,
'win_orig': '',
'port': 9099,
'profiling': 0,
'pyprof_percall': 0,
'verbose': '',
'verbose_log': 0,
'race_start_time': 3.5,
'countdown_seconds': 3,
'xmpp_debug': 0,
'xmpp_server': 'ya2_yorg@jabb3r.org',
'server': 'ya2tech.it:9099',
'server_dev': 'ya2tech.it:9098',
'mp_srv_usr': '',
'fixed_fps': 0,
'srgb': 0,
'opengl_3_2': 0}}
opt_path = ''
if platform in ['win32', 'linux'] and not exists('main.py'):
# it is the deployed version for windows
opt_path = str(Filename.get_user_appdata_directory()) + '/Yorg'
parser = argparse.ArgumentParser()
parser.add_argument('--win_orig')
parser.add_argument('--user')
parser.add_argument('--pwd')
parser.add_argument('--cars')
parser.add_argument('--server')
parser.add_argument('--optfile')
args = parser.parse_args(EngineLogic.cmd_line())
optfile = args.optfile if args.optfile else 'options.json'
#old_def = deepcopy(default_opt)
self.options = DctFile(
LibP3d.fixpath(opt_path + '/' + optfile) if opt_path else optfile,
default_opt)
#if self._get_server() == '':
# self.options['development']['server'] = \
# old_def['development']['server']
# self.options['development']['server_dev'] = \
# old_def['development']['server']
opt_dev = self.options['development']
win_orig = opt_dev['win_orig']
if args.win_orig: win_orig = args.win_orig
if args.cars: opt_dev['cars'] = args.cars
if args.server:
opt_dev['server'] = args.server
opt_dev['server_dev'] = args.server
gui_cfg = GuiCfg(
win_title='Yorg', win_orig=win_orig,
win_size=self.options['settings']['resolution'],
fullscreen=self.options['settings']['fullscreen'],
antialiasing=self.options['settings']['antialiasing'],
fps=opt_dev['fps'], shaders=self.options['settings']['shaders'],
volume=self.options['settings']['volume'],
fixed_fps=self.options['development']['fixed_fps'])
profiling_cfg = ProfilingCfg(
profiling=opt_dev['profiling'],
pyprof_percall=opt_dev['pyprof_percall'])
lang_cfg = LangCfg(lang=self.options['settings']['lang'],
lang_domain='yorg',
languages=[('English', 'en'), ('Deutsch', 'de'),
(u'Espa\u00F1ol', 'es'),
(u'Fran\u00E7ais', 'fr'),
(u'G\u00E0idhlig', 'gd'),
('Galego', 'gl'), ('Italiano', 'it')])
cursor_cfg = CursorCfg(
cursor_path='assets/images/gui/cursor.txo',
cursor_scale=((256/352.0) * .08, 1, .08),
cursor_hotspot=(.1, .06))
dev_cfg = DevCfg(
mt_render=opt_dev['multithreaded_render'],
shaders_dev=opt_dev['shaders_dev'],
pbr=opt_dev['pbr'],
gamma=opt_dev['gamma'],
menu_joypad=opt_dev['menu_joypad'], verbose=opt_dev['verbose'],
verbose_log=opt_dev['verbose_log'],
xmpp_server=opt_dev['xmpp_server'],
start_wp=opt_dev['start_wp'], port=opt_dev['port'],
server=opt_dev['server'],
srgb=opt_dev['srgb'],
opengl_3_2=opt_dev['opengl_3_2'])
conf = Cfg(gui_cfg, profiling_cfg, lang_cfg, cursor_cfg, dev_cfg)
keys = self.options['settings']['keys']
nav1 = NavInfoPerPlayer(
keys['left1'], keys['right1'], keys['forward1'], keys['rear1'],
keys['fire1'])
nav2 = NavInfoPerPlayer(
keys['left2'], keys['right2'], keys['forward2'], keys['rear2'],
keys['fire2'])
nav3 = NavInfoPerPlayer(
keys['left3'], keys['right3'], keys['forward3'], keys['rear3'],
keys['fire3'])
nav4 = NavInfoPerPlayer(
keys['left4'], keys['right4'], keys['forward4'], keys['rear4'],
keys['fire4'])
nav = NavInfo([nav1, nav2, nav3, nav4])
menu_props = MenuProps(
'assets/fonts/Hanken-Book.ttf', (.75, .75, .25, 1),
(.75, .75, .75, 1), (.75, .25, .25, 1), .1,
(-4.6, 4.6, -.32, .88), (0, 0, 0, .2),
'assets/images/gui/menu_background.txo',
'assets/sfx/menu_over.wav', 'assets/sfx/menu_clicked.ogg',
'assets/images/icons/%s.txo', nav)
damage_info = DamageInfo('assets/cars/%s/models/cardamage1',
'assets/cars/%s/models/cardamage2')
Game.__init__(self, conf, YorgClient)
self.fsm = YorgFsm(self)
self.logic = YorgLogic(self)
self.audio = YorgAudio(self)
self.event = YorgEvent(self)
cars_names = self.__compute_cars()
wheel_gfx_names = ['wheelfront', 'wheelrear', 'wheel']
wheel_gfx_names = [
self.eng.curr_path + 'assets/cars/%s/models/' + wname
for wname in wheel_gfx_names]
wheel_gfx_names = WheelGfxNames(*wheel_gfx_names)
social_sites = [
('facebook', 'https://www.facebook.com/Ya2Tech'),
('twitter', 'https://twitter.com/ya2tech'),
#('google_plus', 'https://plus.google.com/118211180567488443153'),
('youtube',
'https://www.youtube.com/user/ya2games?sub_confirmation=1'),
#('pinterest', 'https://www.pinterest.com/ya2tech'),
#('tumblr', 'https://ya2tech.tumblr.com'),
('feed', 'https://www.ya2.it/pages/feed_following.html')]
tracks = self.__compute_tracks()
tracks_tr = self.__compute_tracks_tr()
self.gameprops = GameProps(
menu_props, cars_names, self.drivers(), tracks, tracks_tr,
'assets/tracks/%s/images/menu.txo',
self.options['settings']['player_names'],
self.options['settings']['stored_player_names'],
DriverPaths('assets/images/drivers/driver%s.txo',
'assets/images/drivers/driver%s_sel.txo'),
'assets/cars/%s/images/car_sel.txo',
'assets/cars/%s/images/car.txo',
self.eng.curr_path + 'assets/cars/%s/phys.json',
'assets/cars/%s/models/car',
damage_info, wheel_gfx_names, opt_dev['xmpp_debug'],
social_sites)
self.log_conf(self.options.dct)
self.eng.lib.set_icon('assets/images/icon/yorg.ico')
def log_conf(self, dct, pref=''):
for key, val in dct.items():
if isinstance(val, dict):
self.log_conf(val, pref + key + '::')
elif key != 'pwd':
info('option %s%s = %s' % (pref, key, val))
def __compute_tracks(self):
curr_path = dirname(__file__) + '/'
if __file__.endswith('.py'): curr_path += '../'
if sys.platform == 'darwin': curr_path += '../Resources/'
tracks = [r for r in next(walk(curr_path + 'assets/tracks'))[1]
if r not in ['__pycache__', 'models']]
tracks_i = []
for track in tracks:
with open(self.eng.curr_path + 'assets/tracks/' + track +
'/track.json') as ftrack:
sorting = load(ftrack)['sorting']
tracks_i += [(track, sorting)]
tracks_i = sorted(tracks_i, key=lambda elm: elm[1])
return [track[0] for track in tracks_i]
def __compute_tracks_tr(self):
translated = []
for track in self.__compute_tracks():
path.insert(0, self.eng.curr_path + 'assets/tracks/' + track)
mod = __import__('track_tr')
reload(mod)
translated += [mod.translated]
path.pop(0)
return lambda: translated
def __compute_cars(self):
curr_path = dirname(__file__) + '/'
if __file__.endswith('.py'): curr_path += '../'
if sys.platform == 'darwin': curr_path += '../Resources/'
cars = [r for r in next(walk(curr_path + 'assets/cars'))[1]]
cars_i = []
for car in cars:
with open(self.eng.curr_path + 'assets/cars/' + car +
'/phys.json') as fcar:
sorting = load(fcar)['sorting']
cars_i += [(car, sorting)]
cars_i = sorted(cars_i, key=lambda elm: elm[1])
return [car[0] for car in cars_i]
def reset_drivers(self):
self.gameprops.drivers_info = self.drivers()
def kill(self):
self.eng.server.destroy()
self.eng.client.destroy()
@staticmethod
def drivers():
names = ThanksNames.get_thanks(8, 5)
_drivers = [
Driver(0, names[0], 4, -2, -2),
Driver(1, names[1], -2, 4, -2),
Driver(2, names[2], 0, 4, -4),
Driver(3, names[3], 4, -4, 0),
Driver(4, names[4], -2, -2, 4),
Driver(5, names[5], -4, 0, 4),
Driver(6, names[6], 4, 0, -4),
Driver(7, names[7], -4, 4, 0)]
return _drivers