def _create_window(): CONFIG_DB_CURSOR.execute( 'SELECT app_width, app_height FROM screen_resolution_config') screen_resolution_config = CONFIG_DB_CURSOR.fetchall() monitor_resolution_config = (windll.user32.GetSystemMetrics(0), windll.user32.GetSystemMetrics(1)) USER_DB_CURSOR.execute('SELECT fullscreen FROM graphics') if USER_DB_CURSOR.fetchone( )[0] and monitor_resolution_config in screen_resolution_config: window = Window(width=monitor_resolution_config[0], height=monitor_resolution_config[1], caption='Railway Station Simulator', style='borderless', fullscreen=False, vsync=False) window.set_fullscreen(True) return window USER_DB_CURSOR.execute('SELECT app_width, app_height FROM graphics') screen_resolution = USER_DB_CURSOR.fetchone() return Window(width=screen_resolution[0], height=screen_resolution[1], caption='Railway Station Simulator', style='borderless', fullscreen=False, vsync=False)
def get_signals_to_unlock_with_environment(self, tier): CONFIG_DB_CURSOR.execute( '''SELECT track, base_route FROM signal_config WHERE track_unlocked_with <= ? AND environment_unlocked_with = ? AND map_id = ?''', (self.unlocked_tracks, tier, self.map_id) ) return CONFIG_DB_CURSOR.fetchall()
def __init__(self, controller, view, map_id, shop_id): super().__init__( controller, view, map_id, logger=getLogger( f'root.app.game.map.{map_id}.shop.{shop_id}.constructor.model') ) self.shop_id = shop_id self.shop_stages_state_matrix = {} USER_DB_CURSOR.execute( '''SELECT stage_number, locked, under_construction, construction_time, unlock_condition_from_level, unlock_condition_from_previous_stage, unlock_available FROM shop_stages WHERE map_id = ? AND shop_id = ?''', (self.map_id, self.shop_id)) for stage_info in USER_DB_CURSOR.fetchall(): self.shop_stages_state_matrix[stage_info[0]] = [ *stage_info[1:6], 1, stage_info[6] ] CONFIG_DB_CURSOR.execute( '''SELECT price, max_construction_time, level_required, hourly_profit, storage_capacity, exp_bonus FROM shop_progress_config WHERE map_id = ? AND stage_number = ?''', (self.map_id, stage_info[0])) stage_progress_config = CONFIG_DB_CURSOR.fetchone() self.shop_stages_state_matrix[stage_info[0]].extend( [*stage_progress_config[:3], 0, *stage_progress_config[3:]]) USER_DB_CURSOR.execute( '''SELECT current_stage, shop_storage_money, internal_shop_time FROM shops WHERE map_id = ? AND shop_id = ?''', (self.map_id, self.shop_id)) self.current_stage, self.shop_storage_money, self.internal_shop_time = USER_DB_CURSOR.fetchone( )
def get_crossovers_to_unlock_with_environment(self, tier): CONFIG_DB_CURSOR.execute( '''SELECT track_param_1, track_param_2, crossover_type FROM crossovers_config WHERE track_unlocked_with <= ? AND environment_unlocked_with = ? AND map_id = ?''', (self.unlocked_tracks, tier, self.map_id) ) return CONFIG_DB_CURSOR.fetchall()
def get_switches_to_unlock_with_track(self, track): CONFIG_DB_CURSOR.execute( '''SELECT track_param_1, track_param_2, switch_type FROM switches_config WHERE track_unlocked_with = ? AND environment_unlocked_with <= ? AND map_id = ?''', (track, self.unlocked_environment, self.map_id) ) return CONFIG_DB_CURSOR.fetchall()
def __init__(self, logger, parent_viewport, map_id, shop_id): super().__init__(logger, parent_viewport) CONFIG_DB_CURSOR.execute( '''SELECT button_x, button_y FROM shops_config WHERE map_id = ? AND shop_id = ?''', (map_id, shop_id)) self.x, self.y = CONFIG_DB_CURSOR.fetchone() self.shop_id = shop_id
def __init__(self, controller, map_id, shop_id): def on_close_shop_details(button): self.controller.parent_controller.on_close_shop_details( self.shop_id) super().__init__( controller, map_id, logger=getLogger( f'root.app.game.map.{map_id}.shop.{shop_id}.view'), child_window=True) self.shop_id = shop_id CONFIG_DB_CURSOR.execute( '''SELECT level_required FROM shops_config WHERE map_id = ? AND shop_id = ?''', (self.map_id, self.shop_id)) self.level_required = CONFIG_DB_CURSOR.fetchone()[0] self.shader_sprite = ShopViewShaderSprite(view=self) self.title_label = ShopTitleLabel(parent_viewport=self.viewport) self.title_label.on_update_args((self.shop_id + 1, )) self.close_shop_details_button = CloseShopDetailsButton( on_click_action=on_close_shop_details, parent_viewport=self.viewport) self.buttons = [ self.close_shop_details_button, ] self.on_window_resize_handlers.extend([ self.title_label.on_window_resize, self.shader_sprite.on_window_resize ]) self.on_append_window_handlers()
def create_shops(self): shops = [] CONFIG_DB_CURSOR.execute('''SELECT COUNT(*) FROM shops_config WHERE map_id = ?''', (PASSENGER_MAP,)) for i in range(CONFIG_DB_CURSOR.fetchone()[0]): shops.append(PassengerMapShopController(self, i)) return shops
def __init__(self, controller, view, map_id, track, train_route): super().__init__( controller, view, map_id, logger=getLogger( f'root.app.game.map.{map_id}.train_route.{track}.{train_route}.model' )) self.track = track self.train_route = train_route USER_DB_CURSOR.execute( '''SELECT opened, last_opened_by, current_checkpoint, priority, cars FROM train_routes WHERE track = ? AND train_route = ? AND map_id = ?''', (self.track, self.train_route, self.map_id)) self.opened, self.last_opened_by, self.current_checkpoint, self.priority, self.cars = USER_DB_CURSOR.fetchone( ) USER_DB_CURSOR.execute( '''SELECT train_route_section_busy_state FROM train_routes WHERE track = ? AND train_route = ? AND map_id = ?''', (self.track, self.train_route, self.map_id)) self.train_route_section_busy_state = [ int(s) for s in USER_DB_CURSOR.fetchone()[0].split(',') ] CONFIG_DB_CURSOR.execute( '''SELECT start_point_v2, stop_point_v2, destination_point_v2, checkpoints_v2 FROM train_route_config WHERE track = ? AND train_route = ? AND map_id = ?''', (self.track, self.train_route, self.map_id)) for i in range(len(fetched_data := list(CONFIG_DB_CURSOR.fetchone()))):
def __init__(self, controller, view): super().__init__(controller, view, logger=getLogger('root.app.game.model')) self.game_paused = True USER_DB_CURSOR.execute('''SELECT exp, money_target, exp_multiplier FROM game_progress''') self.exp, self.money_target, self.exp_multiplier = USER_DB_CURSOR.fetchone() CONFIG_DB_CURSOR.execute( '''SELECT player_progress FROM player_progress_config WHERE level = ?''', (self.level, ) ) self.player_progress = CONFIG_DB_CURSOR.fetchone()[0]
def on_unlock_track(self, track): self.unlocked_tracks = track CONFIG_DB_CURSOR.execute( '''SELECT map_sprite_y FROM track_config WHERE map_id = ? AND track_number = ?''', (self.map_id, self.unlocked_tracks)) self.on_position_update(y=CONFIG_DB_CURSOR.fetchone()[0]) self.on_update_texture( get_map_tracks(map_id=self.map_id, tracks=max(self.unlocked_tracks, self.unlocked_tracks_by_default)))
def __init__(self, controller, view): super().__init__(controller, view, logger=getLogger('root.app.model')) USER_DB_CURSOR.execute('SELECT fullscreen FROM graphics') self.fullscreen_mode = USER_DB_CURSOR.fetchone()[0] CONFIG_DB_CURSOR.execute('SELECT app_width, app_height FROM screen_resolution_config') self.screen_resolution_config = CONFIG_DB_CURSOR.fetchall() if (monitor_resolution_config := (windll.user32.GetSystemMetrics(0), windll.user32.GetSystemMetrics(1))) \ in self.screen_resolution_config: self.fullscreen_mode_available = True self.fullscreen_resolution = monitor_resolution_config
def __init__(self, controller, view, map_id): super().__init__(controller, view, map_id, logger=getLogger(f'root.app.game.map.{map_id}.dispatcher.model')) self.trains = [] USER_DB_CURSOR.execute('''SELECT unlocked_tracks FROM map_progress WHERE map_id = ?''', (self.map_id, )) self.unlocked_tracks = USER_DB_CURSOR.fetchone()[0] USER_DB_CURSOR.execute('SELECT busy FROM tracks WHERE map_id = ?', (self.map_id, )) self.track_busy_status = [TRUE, *[t[0] for t in USER_DB_CURSOR.fetchall()]] CONFIG_DB_CURSOR.execute( '''SELECT supported_cars_min, supported_cars_max FROM track_config WHERE map_id = ?''', (self.map_id, ) ) self.supported_cars_by_track = ((0, 20), *CONFIG_DB_CURSOR.fetchall())
def on_level_up(self): super().on_level_up() self.exp -= self.player_progress if self.level == MAXIMUM_LEVEL: self.exp = 0.0 CONFIG_DB_CURSOR.execute( '''SELECT player_progress FROM player_progress_config WHERE level = ?''', (self.level, ) ) self.player_progress = CONFIG_DB_CURSOR.fetchone()[0] self.view.on_send_level_up_notification()
def __init__(self, controller, view, map_id, shop_id): super().__init__( controller, view, map_id, logger=getLogger( f'root.app.game.map.{map_id}.shop.{shop_id}.model')) self.shop_id = shop_id CONFIG_DB_CURSOR.execute( '''SELECT level_required FROM shops_config WHERE map_id = ? AND shop_id = ?''', (self.map_id, self.shop_id)) self.level_required = CONFIG_DB_CURSOR.fetchone()[0]
def on_update_min_supported_cars_by_direction(self): CONFIG_DB_CURSOR.execute( '''SELECT supported_cars_min FROM track_config WHERE track_number = ? AND map_id = ?''', (self.unlocked_tracks, self.map_id) ) min_supported_cars_for_track = CONFIG_DB_CURSOR.fetchone()[0] for direction in range(len(PASSENGER_MAP_MAIN_PRIORITY_TRACKS)): for new_direction in range(len(PASSENGER_MAP_MAIN_PRIORITY_TRACKS[direction])): if self.unlocked_tracks in PASSENGER_MAP_MAIN_PRIORITY_TRACKS[direction][new_direction] \ and min_supported_cars_for_track \ < self.min_supported_cars_by_direction[direction][new_direction]: self.min_supported_cars_by_direction[direction][new_direction] = min_supported_cars_for_track
def __init__(self, logger, parent_viewport, map_id, track, base_route): super().__init__(logger, parent_viewport, map_id) CONFIG_DB_CURSOR.execute( '''SELECT x, y, rotation FROM signal_config WHERE track = ? AND base_route = ? AND map_id = ?''', (track, base_route, self.map_id)) self.x, self.y, self.rotation = CONFIG_DB_CURSOR.fetchone() self.batch = BATCHES['main_batch'] self.group = GROUPS['signal'] USER_DB_CURSOR.execute( '''SELECT state FROM signals WHERE track = ? AND base_route = ? AND map_id = ?''', (track, base_route, self.map_id)) self.texture = RED_SIGNAL_IMAGE if (state := USER_DB_CURSOR.fetchone()[0]) == GREEN_SIGNAL: self.texture = GREEN_SIGNAL_IMAGE
def _shop_buttons(*args, **kwargs): f(*args, **kwargs) CONFIG_DB_CURSOR.execute( '''SELECT COUNT(*) FROM shops_config WHERE map_id = ?''', (args[0].map_id, )) shop_buttons_list = [ OpenShopDetailsButtonV2(logger=args[0].logger.getChild( f'shop_id.{shop_id}.open_shop_details_button_v2'), parent_viewport=args[0].viewport, map_id=args[0].map_id, shop_id=shop_id) for shop_id in range(CONFIG_DB_CURSOR.fetchone()[0]) ] args[0].__setattr__('shop_buttons', shop_buttons_list) args[0].ui_objects.extend(shop_buttons_list) for b in shop_buttons_list: def on_click(): args[0].__getattribute__( 'on_click_action_open_shop_details_button_v2')(b.shop_id) def on_hover(): args[0].__getattribute__( 'on_hover_action_open_shop_details_button_v2')() def on_leave(): args[0].__getattribute__( 'on_leave_action_open_shop_details_button_v2')() b.__setattr__('on_click', on_click) b.__setattr__('on_hover', on_hover) b.__setattr__('on_leave', on_leave) args[0].fade_out_animation.child_animations.append( b.fade_out_animation) args[0].on_mouse_press_handlers.extend(b.on_mouse_press_handlers) args[0].on_mouse_release_handlers.extend( b.on_mouse_release_handlers) args[0].on_mouse_motion_handlers.extend(b.on_mouse_motion_handlers) args[0].on_mouse_leave_handlers.extend(b.on_mouse_leave_handlers) args[0].on_window_resize_handlers.extend( b.on_window_resize_handlers)
def __init__(self, controller, map_id, shop_id): super().__init__( controller, map_id, logger=getLogger( f'root.app.game.map.{map_id}.shop.{shop_id}.placeholder.view'), child_window=True) self.shop_id = shop_id self.lock_label = ShopLockedLabel(parent_viewport=self.viewport) self.description_label = ShopLevelPlaceholderLabel( parent_viewport=self.viewport) CONFIG_DB_CURSOR.execute( '''SELECT level_required FROM shops_config WHERE map_id = ? AND shop_id = ?''', (self.map_id, self.shop_id)) self.level_required = CONFIG_DB_CURSOR.fetchone()[0] self.description_label.on_update_args((self.level_required, )) self.on_window_resize_handlers.extend([ self.lock_label.on_window_resize, self.description_label.on_window_resize ]) self.on_append_window_handlers()
def on_level_up(self): super().on_level_up() # determines if some tracks require level which was just hit CONFIG_DB_CURSOR.execute( 'SELECT track_number FROM track_config WHERE level = ? AND map_id = ?', (self.level, self.map_id)) tracks_parsed = [t[0] for t in CONFIG_DB_CURSOR.fetchall()] # adjusts "unlock_from_level" condition for all tracks for track in tracks_parsed: CONSTRUCTION_STATE_MATRIX[ self.map_id][TRACKS][track][UNLOCK_CONDITION_FROM_LEVEL] = TRUE # if all three conditions are met, track is available for construction self.on_check_track_unlock_conditions(track) self.view.on_update_construction_state(TRACKS, track) # same for environment CONFIG_DB_CURSOR.execute( 'SELECT tier FROM environment_config WHERE level = ? AND map_id = ?', (self.level, self.map_id)) tiers_parsed = [t[0] for t in CONFIG_DB_CURSOR.fetchall()] for tier in tiers_parsed: CONSTRUCTION_STATE_MATRIX[self.map_id][ENVIRONMENT][tier][ UNLOCK_CONDITION_FROM_LEVEL] = TRUE self.on_check_environment_unlock_conditions(tier) self.view.on_update_construction_state(ENVIRONMENT, tier)
def __init__(self, logger, parent_viewport, map_id, track_param_1, track_param_2, crossover_type): super().__init__(logger, parent_viewport, map_id) CONFIG_DB_CURSOR.execute( '''SELECT offset_x, offset_y FROM crossovers_config WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (track_param_1, track_param_2, crossover_type, self.map_id)) self.x, self.y = CONFIG_DB_CURSOR.fetchone() self.batch = BATCHES['main_batch'] self.group = GROUPS['main_map'] CONFIG_DB_CURSOR.execute( '''SELECT region_x, region_y, region_w, region_h FROM crossovers_config WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (track_param_1, track_param_2, crossover_type, self.map_id)) self.crossover_region = CONFIG_DB_CURSOR.fetchone() self.textures = [ SWITCHES_STRAIGHT.get_region(*self.crossover_region), SWITCHES_DIVERGING.get_region(*self.crossover_region) ] USER_DB_CURSOR.execute( '''SELECT current_position_1, current_position_2 FROM crossovers WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (track_param_1, track_param_2, crossover_type, self.map_id)) current_position_1, current_position_2 = USER_DB_CURSOR.fetchone() self.texture = self.textures[int( current_position_1 == current_position_2)]
def __init__(self, controller, map_id, track_param_1, track_param_2, crossover_type): super().__init__( controller, map_id, logger=getLogger( f'root.app.game.map.{map_id}.crossover.{track_param_1}.{track_param_2}.{crossover_type}.view' ) ) self.track_param_1, self.track_param_2, self.crossover_type = track_param_1, track_param_2, crossover_type CONFIG_DB_CURSOR.execute( '''SELECT region_x, region_y, region_w, region_h FROM crossovers_config WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.map_id) ) self.crossover_region = CONFIG_DB_CURSOR.fetchone() USER_DB_CURSOR.execute( '''SELECT current_position_1, current_position_2 FROM crossovers WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.map_id) ) self.current_position_1, self.current_position_2 = USER_DB_CURSOR.fetchone() self.images = { self.track_param_1: { self.track_param_1: SWITCHES_STRAIGHT.get_region(*self.crossover_region), self.track_param_2: SWITCHES_DIVERGING.get_region(*self.crossover_region) }, self.track_param_2: { self.track_param_1: SWITCHES_DIVERGING.get_region(*self.crossover_region), self.track_param_2: SWITCHES_STRAIGHT.get_region(*self.crossover_region) } } USER_DB_CURSOR.execute( '''SELECT locked FROM crossovers WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.map_id) ) self.locked = USER_DB_CURSOR.fetchone()[0] self.sprite = CrossoverSprite( self.map_id, self.track_param_1, self.track_param_2, self.crossover_type, parent_viewport=self.viewport ) self.sprite.on_update_texture(self.images[self.current_position_1][self.current_position_2]) self.on_append_window_handlers()
def __init__(self, controller, view, map_id): super().__init__(controller, view, map_id, logger=getLogger(f'root.app.game.map.{map_id}.model')) USER_DB_CURSOR.execute( '''SELECT locked, unlocked_tracks, unlocked_environment FROM map_progress WHERE map_id = ?''', (self.map_id, ) ) self.locked, self.unlocked_tracks, self.unlocked_environment = USER_DB_CURSOR.fetchone() USER_DB_CURSOR.execute( '''SELECT unlocked_car_collections FROM map_progress WHERE map_id = ?''', (self.map_id, ) ) car_collections = USER_DB_CURSOR.fetchone()[0] self.unlocked_car_collections = [int(c) for c in car_collections.split(',')] if len(car_collections) > 0 else [] USER_DB_CURSOR.execute( '''SELECT last_known_base_offset FROM map_position_settings WHERE map_id = ?''', (self.map_id, ) ) self.last_known_base_offset = tuple(int(p) for p in USER_DB_CURSOR.fetchone()[0].split(',')) USER_DB_CURSOR.execute( '''SELECT last_known_zoom FROM map_position_settings WHERE map_id = ?''', (self.map_id, ) ) self.last_known_zoom = USER_DB_CURSOR.fetchone()[0] CONFIG_DB_CURSOR.execute( '''SELECT unlocked_tracks_by_default FROM map_progress_config WHERE map_id = ?''', (self.map_id, ) ) self.unlocked_tracks_by_default = CONFIG_DB_CURSOR.fetchone()[0]
def __init__(self, controller, view, map_id, track_param_1, track_param_2, switch_type): super().__init__( controller, view, map_id, logger=getLogger( f'root.app.game.map.{map_id}.railroad_switch.{track_param_1}.{track_param_2}.{switch_type}.model' )) self.track_param_1 = track_param_1 self.track_param_2 = track_param_2 self.switch_type = switch_type USER_DB_CURSOR.execute( '''SELECT busy, force_busy FROM switches WHERE track_param_1 = ? AND track_param_2 = ? AND switch_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.switch_type, self.map_id)) self.busy, self.force_busy = USER_DB_CURSOR.fetchone() USER_DB_CURSOR.execute( '''SELECT last_entered_by, current_position FROM switches WHERE track_param_1 = ? AND track_param_2 = ? AND switch_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.switch_type, self.map_id)) self.last_entered_by, self.current_position = USER_DB_CURSOR.fetchone() CONFIG_DB_CURSOR.execute( '''SELECT track, train_route, section_number FROM train_route_sections WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.switch_type, self.map_id)) self.state_change_listeners = CONFIG_DB_CURSOR.fetchall() USER_DB_CURSOR.execute( '''SELECT locked FROM switches WHERE track_param_1 = ? AND track_param_2 = ? AND switch_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.switch_type, self.map_id)) self.locked = USER_DB_CURSOR.fetchone()[0]
def create_signals(self): signals = {} signals_list = [] CONFIG_DB_CURSOR.execute('''SELECT DISTINCT track FROM signal_config WHERE map_id = ?''', (PASSENGER_MAP,)) for i in CONFIG_DB_CURSOR.fetchall(): signals[i[0]] = {} CONFIG_DB_CURSOR.execute('''SELECT track, base_route FROM signal_config WHERE map_id = ?''', (PASSENGER_MAP,)) for i in CONFIG_DB_CURSOR.fetchall(): signals[i[0]][i[1]] = PassengerMapSignalController(self, *i) signals_list.append(signals[i[0]][i[1]]) return signals, signals_list
def create_train_routes(self): train_routes = {} train_routes_sorted_list = [] CONFIG_DB_CURSOR.execute( '''SELECT DISTINCT track FROM train_route_config WHERE map_id = ?''', (FREIGHT_MAP, )) for i in CONFIG_DB_CURSOR.fetchall(): train_routes[i[0]] = {} CONFIG_DB_CURSOR.execute( '''SELECT track, train_route FROM train_route_config WHERE map_id = ?''', (FREIGHT_MAP, )) for i in CONFIG_DB_CURSOR.fetchall(): train_routes[i[0]][i[1]] = FreightTrainRouteController(self, *i) train_routes_sorted_list.append(train_routes[i[0]][i[1]]) return train_routes, train_routes_sorted_list
def __init__(self, logger, parent_viewport, map_id): super().__init__(logger, parent_viewport, map_id) USER_DB_CURSOR.execute( '''SELECT unlocked_tracks FROM map_progress WHERE map_id = ?''', (self.map_id, )) self.unlocked_tracks = USER_DB_CURSOR.fetchone()[0] CONFIG_DB_CURSOR.execute( '''SELECT unlocked_tracks_by_default FROM map_progress_config WHERE map_id = ?''', (self.map_id, )) self.unlocked_tracks_by_default = CONFIG_DB_CURSOR.fetchone()[0] self.texture = get_map_tracks(map_id=self.map_id, tracks=max( self.unlocked_tracks, self.unlocked_tracks_by_default)) self.batch = BATCHES['main_batch'] self.group = GROUPS['main_map'] CONFIG_DB_CURSOR.execute( '''SELECT map_sprite_y FROM track_config WHERE map_id = ? AND track_number = ?''', (self.map_id, self.unlocked_tracks)) self.y = CONFIG_DB_CURSOR.fetchone()[0]
int(s) for s in USER_DB_CURSOR.fetchone()[0].split(',') ] CONFIG_DB_CURSOR.execute( '''SELECT start_point_v2, stop_point_v2, destination_point_v2, checkpoints_v2 FROM train_route_config WHERE track = ? AND train_route = ? AND map_id = ?''', (self.track, self.train_route, self.map_id)) for i in range(len(fetched_data := list(CONFIG_DB_CURSOR.fetchone()))): if fetched_data[i] is not None: fetched_data[i] = tuple( int(p) for p in fetched_data[i].split(',')) self.start_point_v2, self.stop_point_v2, self.destination_point_v2, self.checkpoints_v2 = fetched_data self.trail_points_v2 = TrailPointsV2(self.map_id, self.track, self.train_route) CONFIG_DB_CURSOR.execute( '''SELECT section_type, track_param_1, track_param_2 FROM train_route_sections WHERE track = ? and train_route = ? AND map_id = ?''', (self.track, self.train_route, self.map_id)) self.train_route_sections = CONFIG_DB_CURSOR.fetchall() self.signal_base_route, self.signal_track = None, None if len(self.train_route_sections) > 1: self.signal_base_route, self.signal_track = self.train_route_sections[ 0][:2] CONFIG_DB_CURSOR.execute( '''SELECT position_1, position_2 FROM train_route_sections WHERE track = ? and train_route = ? AND map_id = ?''', (self.track, self.train_route, self.map_id)) self.train_route_section_positions = CONFIG_DB_CURSOR.fetchall() @final def on_save_state(self):
def __init__(self, controller, view, map_id, track_param_1, track_param_2, crossover_type): super().__init__( controller, view, map_id, logger=getLogger( f'root.app.game.map.{map_id}.crossover.{track_param_1}.{track_param_2}.{crossover_type}.model' )) self.track_param_1 = track_param_1 self.track_param_2 = track_param_2 self.crossover_type = crossover_type self.busy = {track_param_1: {}, track_param_2: {}} self.force_busy = {track_param_1: {}, track_param_2: {}} self.last_entered_by = {track_param_1: {}, track_param_2: {}} self.state_change_listeners = {track_param_1: {}, track_param_2: {}} USER_DB_CURSOR.execute( '''SELECT busy_1_1, busy_1_2, busy_2_1, busy_2_2, force_busy_1_1, force_busy_1_2, force_busy_2_1, force_busy_2_2 FROM crossovers WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.map_id)) self.busy[self.track_param_1][self.track_param_1], self.busy[self.track_param_1][self.track_param_2], \ self.busy[self.track_param_2][self.track_param_1], self.busy[self.track_param_2][self.track_param_2], \ self.force_busy[self.track_param_1][self.track_param_1], \ self.force_busy[self.track_param_1][self.track_param_2], \ self.force_busy[self.track_param_2][self.track_param_1], \ self.force_busy[self.track_param_2][self.track_param_2] = USER_DB_CURSOR.fetchone() USER_DB_CURSOR.execute( '''SELECT last_entered_by_1_1, last_entered_by_1_2, last_entered_by_2_1, last_entered_by_2_2, current_position_1, current_position_2 FROM crossovers WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.map_id)) self.last_entered_by[self.track_param_1][self.track_param_1], \ self.last_entered_by[self.track_param_1][self.track_param_2], \ self.last_entered_by[self.track_param_2][self.track_param_1], \ self.last_entered_by[self.track_param_2][self.track_param_2], \ self.current_position_1, self.current_position_2 = USER_DB_CURSOR.fetchone() CONFIG_DB_CURSOR.execute( '''SELECT track, train_route, section_number FROM train_route_sections WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ? AND position_1 = ? AND position_2 = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.track_param_1, self.track_param_1, self.map_id)) self.state_change_listeners[self.track_param_1][ self.track_param_1] = CONFIG_DB_CURSOR.fetchall() CONFIG_DB_CURSOR.execute( '''SELECT track, train_route, section_number FROM train_route_sections WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ? AND position_1 = ? AND position_2 = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.track_param_1, self.track_param_2, self.map_id)) self.state_change_listeners[self.track_param_1][ self.track_param_2] = CONFIG_DB_CURSOR.fetchall() CONFIG_DB_CURSOR.execute( '''SELECT track, train_route, section_number FROM train_route_sections WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ? AND position_1 = ? AND position_2 = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.track_param_2, self.track_param_1, self.map_id)) self.state_change_listeners[self.track_param_2][ self.track_param_1] = CONFIG_DB_CURSOR.fetchall() CONFIG_DB_CURSOR.execute( '''SELECT track, train_route, section_number FROM train_route_sections WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ? AND position_1 = ? AND position_2 = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.track_param_2, self.track_param_2, self.map_id)) self.state_change_listeners[self.track_param_2][ self.track_param_2] = CONFIG_DB_CURSOR.fetchall() USER_DB_CURSOR.execute( '''SELECT locked FROM crossovers WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''', (self.track_param_1, self.track_param_2, self.crossover_type, self.map_id)) self.locked = USER_DB_CURSOR.fetchone()[0]
def __init__(self, controller): def on_accept_changes(button): self.controller.parent_controller.on_accept_changes( self.temp_windowed_resolution, self.temp_display_fps, self.temp_fade_animations_enabled, self.temp_clock_24h_enabled, self.temp_level_up_notification_enabled, self.temp_feature_unlocked_notification_enabled, self.temp_construction_completed_notification_enabled, self.temp_enough_money_notification_enabled, self.temp_bonus_expired_notification_enabled, self.temp_shop_storage_notification_enabled, self.temp_voice_not_found_notification_enabled, self.temp_master_volume, self.temp_announcements_enabled ) self.controller.on_save_and_commit_state() self.controller.parent_controller.on_close_settings() def on_reject_changes(button): self.controller.parent_controller.on_close_settings() def on_update_windowed_resolution_state(index): self.on_change_temp_windowed_resolution(self.available_windowed_resolutions[index]) def on_update_display_fps_state(new_state): self.temp_display_fps = new_state def on_update_fade_animations_state(new_state): self.temp_fade_animations_enabled = new_state def on_update_clock_24h_state(new_state): self.temp_clock_24h_enabled = new_state def on_update_level_up_notifications_state(new_state): self.temp_level_up_notification_enabled = new_state def on_update_feature_unlocked_notifications_state(new_state): self.temp_feature_unlocked_notification_enabled = new_state def on_update_construction_completed_notifications_state(new_state): self.temp_construction_completed_notification_enabled = new_state def on_update_enough_money_notifications_state(new_state): self.temp_enough_money_notification_enabled = new_state def on_update_bonus_expired_notifications_state(new_state): self.temp_bonus_expired_notification_enabled = new_state def on_update_shop_storage_notifications_state(new_state): self.temp_shop_storage_notification_enabled = new_state def on_update_voice_not_found_notifications_state(new_state): self.temp_voice_not_found_notification_enabled = new_state def on_update_master_volume(master_volume): self.temp_master_volume = master_volume def on_update_announcements_state(new_state): self.temp_announcements_enabled = new_state super().__init__(controller, logger=getLogger('root.app.settings.view')) self.temp_windowed_resolution = (0, 0) self.temp_display_fps = FALSE self.temp_fade_animations_enabled = FALSE self.temp_clock_24h_enabled = FALSE self.temp_master_volume = 0 self.temp_announcements_enabled = TRUE self.display_fps_checkbox = DisplayFPSCheckbox( column=-1, row=2, on_update_state_action=on_update_display_fps_state, parent_viewport=self.viewport ) self.fade_animations_checkbox = FadeAnimationsEnabledCheckbox( column=-1, row=0, on_update_state_action=on_update_fade_animations_state, parent_viewport=self.viewport ) self.clock_24h_checkbox = Clock24HCheckbox( column=-1, row=-2, on_update_state_action=on_update_clock_24h_state, parent_viewport=self.viewport ) self.master_volume_knob = MasterVolumeSettingsKnob( column=-1, row=-5, on_update_state_action=on_update_master_volume, parent_viewport=self.viewport ) self.announcements_checkbox = AnnouncementsEnabledCheckbox( column=-1, row=-8, on_update_state_action=on_update_announcements_state, parent_viewport=self.viewport ) self.temp_level_up_notification_enabled = FALSE self.temp_feature_unlocked_notification_enabled = FALSE self.temp_construction_completed_notification_enabled = FALSE self.temp_enough_money_notification_enabled = FALSE self.temp_bonus_expired_notification_enabled = FALSE self.temp_shop_storage_notification_enabled = FALSE self.temp_voice_not_found_notification_enabled = FALSE self.game_progress_notifications_checkbox_group = GameProgressNotificationsCheckboxGroup( column=1, row=9, on_update_state_actions=[ on_update_level_up_notifications_state, on_update_feature_unlocked_notifications_state, on_update_construction_completed_notifications_state, on_update_enough_money_notifications_state, on_update_bonus_expired_notifications_state, on_update_shop_storage_notifications_state ], parent_viewport=self.viewport ) self.malfunction_notifications_checkbox_group = MalfunctionNotificationsCheckboxGroup( column=1, row=-7, on_update_state_actions=[ on_update_voice_not_found_notifications_state ], parent_viewport=self.viewport ) CONFIG_DB_CURSOR.execute( '''SELECT app_width, app_height FROM screen_resolution_config WHERE manual_setup = 1 AND app_width <= ?''', (windll.user32.GetSystemMetrics(0),) ) self.available_windowed_resolutions = CONFIG_DB_CURSOR.fetchall() self.available_windowed_resolutions_position = 0 self.screen_resolution_control = ScreenResolutionControl( column=-1, row=8, possible_values_list=self.available_windowed_resolutions, on_update_state_action=on_update_windowed_resolution_state, parent_viewport=self.viewport ) self.accept_settings_button = AcceptSettingsButton( on_click_action=on_accept_changes, parent_viewport=self.viewport ) self.reject_settings_button = RejectSettingsButton( on_click_action=on_reject_changes, parent_viewport=self.viewport ) self.buttons = [ self.accept_settings_button, self.reject_settings_button, *self.screen_resolution_control.buttons, *self.display_fps_checkbox.buttons, *self.fade_animations_checkbox.buttons, *self.clock_24h_checkbox.buttons, *self.game_progress_notifications_checkbox_group.buttons, *self.malfunction_notifications_checkbox_group.buttons, *self.announcements_checkbox.buttons ] self.shader_sprite = SettingsViewShaderSprite(view=self) self.on_mouse_motion_handlers.extend(self.master_volume_knob.on_mouse_motion_handlers) self.on_mouse_press_handlers.extend(self.master_volume_knob.on_mouse_press_handlers) self.on_mouse_release_handlers.extend(self.master_volume_knob.on_mouse_release_handlers) self.on_mouse_drag_handlers.extend(self.master_volume_knob.on_mouse_drag_handlers) self.on_window_resize_handlers.extend( [ *self.display_fps_checkbox.on_window_resize_handlers, *self.fade_animations_checkbox.on_window_resize_handlers, *self.clock_24h_checkbox.on_window_resize_handlers, *self.game_progress_notifications_checkbox_group.on_window_resize_handlers, *self.malfunction_notifications_checkbox_group.on_window_resize_handlers, *self.screen_resolution_control.on_window_resize_handlers, *self.master_volume_knob.on_window_resize_handlers, *self.announcements_checkbox.on_window_resize_handlers, self.shader_sprite.on_window_resize ] ) self.on_append_window_handlers()