Esempio n. 1
0
 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)]
Esempio n. 2
0
 def on_unlock_track(self, track):
     self.unlocked_tracks = track
     self.on_update_texture(
         get_map_tracks(map_id=self.map_id,
                        tracks=max(track, self.unlocked_tracks_by_default)))
     CONFIG_DB_CURSOR.execute(
         '''SELECT map_sprite_y FROM track_config WHERE map_id = ? AND track_number = ?''',
         (self.map_id, self.unlocked_tracks))
     if self.y_margin != (new_margin := CONFIG_DB_CURSOR.fetchone()[0]):
         self.y_margin = new_margin
         self.on_position_update()
Esempio n. 3
0
    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()
Esempio n. 4
0
 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()))):
Esempio n. 5
0
    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
Esempio n. 6
0
 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
Esempio n. 7
0
    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(
        )
Esempio n. 8
0
 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]
Esempio n. 9
0
    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()
Esempio n. 10
0
 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]
Esempio n. 11
0
 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
Esempio n. 13
0
 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
Esempio n. 14
0
    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)
Esempio n. 15
0
 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()
Esempio n. 16
0
 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()
Esempio n. 17
0
 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]
Esempio n. 18
0
    def __init__(self, controller, map_id):
        def on_leave_action():
            self.on_map_move_mode_available()

        def on_hover_action():
            self.on_map_move_mode_unavailable()

        def on_open_schedule(button):
            button.on_deactivate(instant=True)
            button.state = 'normal'
            self.controller.on_open_schedule()

        def on_open_constructor(button):
            button.on_deactivate(instant=True)
            button.state = 'normal'
            self.controller.on_open_constructor()

        def on_open_shop_details(button):
            self.controller.on_open_shop_details(
                self.shop_buttons.index(button))

        super().__init__(controller,
                         map_id,
                         logger=getLogger(f'root.app.game.map.{map_id}.view'))
        USER_DB_CURSOR.execute(
            '''SELECT unlocked_tracks FROM map_progress WHERE map_id = ?''',
            (self.map_id, ))
        self.unlocked_tracks = USER_DB_CURSOR.fetchone()[0]
        self.mini_map_offset = (0, 0)
        self.main_map_sprite = MainMapSprite(map_id=self.map_id,
                                             parent_viewport=self.viewport)
        self.environment_sprite = MainEnvironmentSprite(
            map_id=self.map_id, parent_viewport=self.viewport)
        self.mini_map_timer = 0.0
        USER_DB_CURSOR.execute(
            '''SELECT last_known_base_offset FROM map_position_settings WHERE map_id = ?''',
            (self.map_id, ))
        self.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.zoom = USER_DB_CURSOR.fetchone()[0]
        self.base_offset_lower_left_limit = (0, 0)
        self.base_offset_upper_right_limit = (0, 0)
        self.open_schedule_button = OpenScheduleButton(
            on_click_action=on_open_schedule, parent_viewport=self.viewport)
        self.open_constructor_button = OpenConstructorButton(
            on_click_action=on_open_constructor, parent_viewport=self.viewport)
        self.buttons = [
            self.open_schedule_button, self.open_constructor_button
        ]
        self.shader_sprite = MapViewShaderSprite(view=self)
        self.on_window_resize_handlers.append(
            self.shader_sprite.on_window_resize)
        self.on_append_window_handlers()
        self.shop_buttons = []
        CONFIG_DB_CURSOR.execute(
            '''SELECT COUNT(*) FROM shops_config WHERE map_id = ?''',
            (self.map_id, ))
        for shop_id in range(CONFIG_DB_CURSOR.fetchone()[0]):
            self.shop_buttons.append(
                OpenShopDetailsButton(map_id=self.map_id,
                                      shop_id=shop_id,
                                      on_click_action=on_open_shop_details,
                                      on_hover_action=on_hover_action,
                                      on_leave_action=on_leave_action))

        CONFIG_DB_CURSOR.execute(
            '''SELECT track_required FROM shops_config WHERE map_id = ?''',
            (self.map_id, ))
        self.shops_track_required_state = tuple(
            s[0] for s in CONFIG_DB_CURSOR.fetchall())
        self.buttons.extend(self.shop_buttons)
        for b in self.shop_buttons:
            b.position = b.get_position()
            b.on_change_scale()

        self.map_move_mode_available = False
        self.map_move_mode = False
        self.on_mouse_press_handlers.append(self.on_mouse_press)
        self.on_mouse_release_handlers.append(self.on_mouse_release)
        self.on_mouse_drag_handlers.append(self.on_mouse_drag)
        self.on_mouse_scroll_handlers.append(self.on_mouse_scroll)
        USER_DB_CURSOR.execute(
            '''SELECT SUM(t.constructions_locked) FROM (
                    SELECT COUNT(track_number) AS constructions_locked FROM tracks 
                    WHERE locked = 1 AND map_id = ?
                    UNION
                    SELECT COUNT(tier) AS constructions_locked FROM environment 
                    WHERE locked = 1 AND map_id = ?
            ) AS t''', (self.map_id, self.map_id))
        self.constructions_locked = USER_DB_CURSOR.fetchone()[0]
        self.is_mini_map_timer_activated = False