Permalink
Browse files

car's selection

  • Loading branch information...
cflavio committed Jul 11, 2018
1 parent 281e473 commit 6692d8590e7eb241115f475e6e87b48d9429944e
Showing with 77 additions and 54 deletions.
  1. +52 −44 menu/carpage.py
  2. +6 −5 menu/driverpage.py
  3. +10 −5 menu/menu.py
  4. +3 −0 project.py
  5. +6 −0 yorg/client.py
@@ -13,11 +13,12 @@
class CarPageGui(ThanksPageGui):
def __init__(self, mediator, carpage_props, track_path):
def __init__(self, mediator, carpage_props, track_path, yorg_client):
self.car = None
self.current_cars = None
self.track_path = track_path
self.props = carpage_props
self.yorg_client = yorg_client
ThanksPageGui.__init__(self, mediator, carpage_props.gameprops.menu_args)
def build(self, exit_behav=False):
@@ -118,11 +119,14 @@ def build(self):
def on_car(self, car):
self.eng.log_mgr.log('car selected: ' + car)
name = JID(self.eng.xmpp.client.boundjid).bare
self.eng.server.send([NetMsgs.car_selection, car, name])
#name = JID(self.eng.xmpp.client.boundjid).bare
#self.eng.server.send([NetMsgs.car_selection, car, name])
self.eng.client.register_rpc('car_request')
ret = self.eng.client.car_request(car)
if ret != 'ok': return
for btn in self._buttons(car):
btn.disable()
btn._name_txt['text'] = name
btn._name_txt['text'] = self.yorg_client.myid
if self in self.current_cars:
curr_car = self.current_cars[self]
self.eng.log_mgr.log('car deselected: ' + curr_car)
@@ -132,24 +136,24 @@ def on_car(self, car):
btn._name_txt['text'] = ''
self.current_cars[self] = car
self.eng.car_mapping['self'] = car
self.evaluate_starting()
def evaluate_starting(self):
connections = [conn for conn in self.eng.server.connections] + [self]
if not all(conn in self.current_cars for conn in connections): return
packet = [NetMsgs.start_drivers, len(self.current_cars)]
def process(k):
'''Processes a car.'''
return 'server' if k == self else k.getpeername()
for i, (k, val) in enumerate(self.current_cars.items()):
packet += [process(k), val,
self.props.gameprops.drivers_info[i].name]
self.eng.server.send(packet)
self.eng.log_mgr.log('start drivers: ' + str(packet))
curr_car = self.current_cars[self]
page_args = [self.track_path, curr_car, self.props]
self.notify('on_push_page', 'driverpageserver', page_args)
#self.evaluate_starting()
#def evaluate_starting(self):
# connections = [conn for conn in self.eng.server.connections] + [self]
# if not all(conn in self.current_cars for conn in connections): return
# packet = [NetMsgs.start_drivers, len(self.current_cars)]
# def process(k):
# '''Processes a car.'''
# return 'server' if k == self else k.getpeername()
# for i, (k, val) in enumerate(self.current_cars.items()):
# packet += [process(k), val,
# self.props.gameprops.drivers_info[i].name]
# self.eng.server.send(packet)
# self.eng.log_mgr.log('start drivers: ' + str(packet))
# curr_car = self.current_cars[self]
# page_args = [self.track_path, curr_car, self.props]
# self.notify('on_push_page', 'driverpageserver', page_args)
def car_request(self, car, sender):
self.eng.log_mgr.log('car requested: ' + car)
@@ -200,8 +204,11 @@ class CarPageGuiClient(CarPageGui):
def build(self):
CarPageGui.build(self, exit_behav=True)
self.eng.client.register_cb(self.process_client)
#self.eng.client.register_cb(self.process_client)
self.eng.client.register_rpc('car_request')
self.yorg_client.attach(self.on_car_selection)
self.yorg_client.attach(self.on_car_deselection)
self.yorg_client.attach(self.on_start_drivers)
def on_car(self, car):
self.eng.log_mgr.log('car request: ' + car)
@@ -214,36 +221,37 @@ def on_car(self, car):
self.eng.log_mgr.log('car confirmed: ' + car)
btn = self._buttons(car)[0]
btn.disable()
btn._name_txt['text'] = JID(self.eng.xmpp.client.boundjid).bare
btn._name_txt['text'] = self.yorg_client.myid
else: self.eng.log_mgr.log('car denied')
def process_client(self, data_lst, sender):
if data_lst[0] == NetMsgs.car_selection:
car = data_lst[1]
name = data_lst[2]
self.eng.log_mgr.log('car selection: ' + car)
btn = self._buttons(car)[0]
btn.disable()
btn._name_txt['text'] = name
if data_lst[0] == NetMsgs.car_deselection:
car = data_lst[1]
self.eng.log_mgr.log('car deselection: ' + car)
btn = self._buttons(car)[0]
btn.enable()
btn._name_txt['text'] = ''
if data_lst[0] == NetMsgs.start_drivers:
self.eng.log_mgr.log('start_drivers: ' + str(data_lst))
page_args = [self.track_path, self.car, self.props]
self.notify('on_push_page', 'driverpageclient', page_args)
def on_car_selection(self, data_lst):
car = data_lst[0]
name = data_lst[1]
self.eng.log_mgr.log('car selection: ' + car)
btn = self._buttons(car)[0]
btn.disable()
btn._name_txt['text'] = name
def on_car_deselection(self, data_lst):
car = data_lst[0]
self.eng.log_mgr.log('car deselection: ' + car)
btn = self._buttons(car)[0]
btn.enable()
btn._name_txt['text'] = ''
def on_start_drivers(self, data_lst):
self.eng.log_mgr.log('start_drivers: ' + str(data_lst))
page_args = [self.track_path, self.car, self.props]
self.notify('on_push_page', 'driverpageclient', page_args)
class CarPage(Page):
gui_cls = CarPageGui
def __init__(self, carpage_props, track_path):
def __init__(self, carpage_props, track_path, yorg_client):
init_lst = [
[('event', self.event_cls, [self])],
[('gui', self.gui_cls, [self, carpage_props, track_path])]]
[('gui', self.gui_cls, [self, carpage_props, track_path, yorg_client])]]
GameObject.__init__(self, init_lst)
PageFacade.__init__(self)
# invoke Page's __init__
@@ -33,10 +33,11 @@
class DriverPageGui(ThanksPageGui):
def __init__(self, mediator, driverpage_props):
def __init__(self, mediator, driverpage_props, yorg_client):
self.props = driverpage_props
self.sel_drv_img = None
self.driver = None
self.yorg_client = yorg_client
ThanksPageGui.__init__(self, mediator, driverpage_props.gameprops.menu_args)
def build(self, exit_behav):
@@ -196,7 +197,7 @@ def build(self):
self.current_drivers_dct = {}
self.name['align'] = TextNode.ACenter
self.name['pos'] = (-.2, .6)
self.name['text'] += ' ' + self.eng.xmpp.client.boundjid.bare
self.name['text'] += ' ' + self.yorg_client.myid
#self.eng.xmpp.attach(self.on_presence_unavailable)
self.eng.xmpp.attach(self.on_presence_unavailable_room)
self.eng.server.register_rpc(self.drv_request)
@@ -305,7 +306,7 @@ def build(self):
self.eng.client.register_cb(self.process_client)
self.name['align'] = TextNode.ACenter
self.name['pos'] = (-.2, .6)
self.name['text'] += ' ' + self.eng.xmpp.client.boundjid.bare
self.name['text'] += ' ' + self.yorg_client.myid
self.eng.client.register_rpc('drv_request')
def this_name(self): return self.eng.xmpp.client.boundjid.bare
@@ -354,12 +355,12 @@ def process_client(self, data_lst, sender):
class DriverPage(Page):
gui_cls = DriverPageGui
def __init__(self, track, car, driverpage_props):
def __init__(self, track, car, driverpage_props, yorg_client):
self.track = track
self.car = car
init_lst = [
[('event', self.event_cls, [self])],
[('gui', self.gui_cls, [self, driverpage_props])]]
[('gui', self.gui_cls, [self, driverpage_props, yorg_client])]]
GameObject.__init__(self, init_lst)
PageFacade.__init__(self)
# invoke Page's __init__
@@ -32,6 +32,10 @@ def __init__(self, gameprops, opt_file, title_img, feed_url, site_url,
class YorgMenuLogic(MenuLogic):
def __init__(self, mediator, yorg_client):
MenuLogic.__init__(self, mediator)
self.yorg_client = yorg_client
def on_push_page(self, page_code, args=[]):
if page_code == 'singleplayer':
self.eng.log('single player')
@@ -65,23 +69,24 @@ def on_push_page(self, page_code, args=[]):
page.gui.attach(self.on_car_selected)
if page_code == 'carpageserver':
self.eng.log('car page server')
page = CarPageServer(args[0], self.mediator.track)
#page = CarPageServer(args[0], self.mediator.track, self.yorg_client)
page = CarPageClient(args[0], self.mediator.track, self.yorg_client)
page.gui.attach(self.on_car_selected)
if page_code == 'carpageclient':
self.eng.log('car page client')
page = CarPageClient(args[0], self.mediator.track)
page = CarPageClient(args[0], self.mediator.track, self.yorg_client)
page.gui.attach(self.on_car_selected)
if page_code == 'driver_page':
self.eng.log('driver page')
page = DriverPageSinglePlayer(args[0], args[1], args[2])
page.gui.attach(self.on_driver_selected)
if page_code == 'driverpageserver':
self.eng.log('driver page server')
page = DriverPageServer(args[0], args[1], args[2])
page = DriverPageServer(args[0], args[1], args[2], self.yorg_client)
page.gui.attach(self.on_driver_selected_server)
if page_code == 'driverpageclient':
self.eng.log('driver page client')
page = DriverPageClient(args[0], args[1], args[2])
page = DriverPageClient(args[0], args[1], args[2], self.yorg_client)
page.gui.attach(self.on_driver_selected)
page.gui.attach(self.on_car_start_client)
if page_code == 'options':
@@ -180,7 +185,7 @@ class YorgMenu(Menu):
def __init__(self, menu_args, yorg_client):
comps = [
[('logic', self.logic_cls, [self])],
[('logic', self.logic_cls, [self, yorg_client])],
[('gui', self.gui_cls, [self, menu_args, yorg_client])]]
GameObject.__init__(self, comps)
MenuFacade.__init__(self)
@@ -3,6 +3,9 @@
# TODO LIST =====
# 0.10
# clean rooms when people exit
# 0.11 (local multiplayer)
# local multiplayer
@@ -46,6 +46,12 @@ def on_msg(self, data_lst, sender):
self.notify('on_presence_available_room', data_lst[1], data_lst[2])
if data_lst[0] == 'track_selected':
self.notify('on_track_selected_msg', data_lst[1])
if data_lst[0] == 'car_selection':
self.notify('on_car_selection', data_lst[1:])
if data_lst[0] == 'car_deselection':
self.notify('on_car_deselection', data_lst[1:])
if data_lst[0] == 'start_drivers':
self.notify('on_start_drivers', data_lst[1:])
def find_usr(self, uid):
return [usr for usr in self.users if usr.uid == uid][0]

0 comments on commit 6692d85

Please sign in to comment.