Exemplo n.º 1
0
    def __init__(
        self,
        actor: 'Actor',
        config: Config,
    ) -> None:
        self.config = config
        self.actor = actor

        self.path_manager = PathManager(
            config.resolve('global.include_path.graphics'))
        self.animation_cache = AnimationImageCache()
Exemplo n.º 2
0
 def __init__(
     self,
     config: Config,
     actor: 'BaseActor',
 ) -> None:
     self.actor = actor
     self._images_scheme = self.get_rest_images_scheme()
     self._firing_images_scheme = self.get_firing_images_scheme()
     self.path_manager = PathManager(config.resolve('global.include_path.graphics'))
     self._cache = {}  # type: typing.Dict[str, Image.Image]
     self._firing_cache = {}  # type: typing.Dict[str, Image.Image]
Exemplo n.º 3
0
    def __init__(self,
                 image_path: str,
                 subject: Subject,
                 position=(0, 0),
                 rotation=0,
                 scale=1,
                 opacity=255,
                 color=(255, 255, 255),
                 anchor=None,
                 properties: dict = None,
                 config: Config = None,
                 **kwargs):
        # Note: Parameter required, but we want to modify little as possible parent init
        assert config, "Config is a required parameter"
        self.config = config
        self.path_manager = PathManager(
            config.resolve('global.include_path.graphics'))
        self.animation_images = {
        }  # type: typing.Dict[str, typing.List[pyglet.image.TextureRegion]]  # nopep8

        default_texture = self._get_default_image_texture()
        super().__init__(default_texture, position, rotation, scale, opacity,
                         color, anchor, **kwargs)

        self.logger = get_logger('Actor', config)

        self.subject = subject
        self.cshape = None  # type: collision_model.AARectShape
        self.update_cshape()
        self.default_texture = default_texture
        self.need_update_cshape = False
        self.properties = properties or {}
        self._freeze = False

        self.animation_textures_cache = {
        }  # type: typing.Dict[str, typing.List[pyglet.image.TextureRegion]]  # nopep8
        self.mode_texture_cache = {
        }  # type: typing.Dict[str, pyglet.image.TextureRegion]  # nopep8

        self.default_image_path = image_path
        self.image_cache_manager = self.get_image_cache_manager()
        self.image_cache_manager.build()

        self.build_textures_cache()
Exemplo n.º 4
0
def main(
    map_dir_path: str,
    seed_value: int=None,
    state_file_path: str=None,
    troops_file_path: str=None,
    state_save_dir: str='.',
    placement_mode: bool = False,
):
    assert not (state_file_path and troops_file_path),\
        'Do not provide troops file when state file given'

    if seed_value is not None:
        seed(seed_value)

    config = Config()
    config.load_yaml('config.yaml')

    # Runtime config
    config['_runtime'] = {}
    config['_runtime']['state_save_dir'] = state_save_dir
    config['_runtime']['placement_mode'] = placement_mode
    config['_runtime']['map_dir_path'] = map_dir_path

    level = logging.getLevelName(config.resolve('global.logging_level', 'ERROR'))
    logger = get_default_logger(level=level)

    map_file_path = get_map_file_path_from_dir(map_dir_path)

    simulation = TileStrategySimulation(config, map_file_path=map_file_path)
    subjects = TileStrategySubjects(simulation=simulation)
    simulation.subjects = subjects

    if state_file_path:
        state_loader_builder = StateConstructorBuilder(config, simulation)
        state_loader = state_loader_builder.get_state_loader()
        state = state_loader.get_state(state_file_path)
        subjects.extend(state.subjects)

    elif troops_file_path:
        troop_loader_builder = TroopConstructorBuilder(config, simulation)
        troop_loader = troop_loader_builder.get_troop_loader()
        placement = Placement(config, simulation)

        troops = troop_loader.get_troop(troops_file_path)
        subjects.extend(troops.subjects)
        placement.place()

    core = Core(
        config=config,
        simulation=simulation,
        cycle_manager=CycleManager(
            config=config,
            simulation=simulation,
        ),
        terminal_manager=TerminalManager(
            config=config,
            terminals=[CocosTerminal(
                config,
                asynchronous=False,
                map_dir_path=map_dir_path,
            )]
        ),
        cycles_per_seconds=1 / config.resolve('core.cycle_duration'),
    )
    core.run()
Exemplo n.º 5
0
 def predicate(
     config: Config,
     simulation: Simulation,
 ):
     return bool(config.resolve(parameter_to_resolve, False))
Exemplo n.º 6
0
    def __init__(
        self,
        config: Config,
        terminal: Terminal,
        physics: Physics,
        read_queue_interval: float = 1 / 60.0,
        map_dir_path: str = None,
    ):
        super().__init__(
            config,
            terminal,
            physics=physics,
            read_queue_interval=read_queue_interval,
            map_dir_path=map_dir_path,
        )
        self.sound_lib = AudioLibrary(
            config.resolve('global.include_path.sounds'))
        self.graphic_path_manager = PathManager(
            self.config.resolve('global.include_path.graphics', ))
        self.debug_gui = self.config.resolve('global.debug_gui', False)

        self.terminal.register_event_handler(
            move.SubjectFinishTileMoveEvent,
            self.set_subject_position,
        )
        self.terminal.register_event_handler(
            move.SubjectFinishMoveEvent,
            self.set_subject_position,
        )

        self.terminal.register_event_handler(
            move.SubjectStartTileMoveEvent,
            self.start_move_subject,
        )

        self.terminal.register_event_handler(
            move.SubjectStartRotationEvent,
            self.start_rotate_subject,
        )

        self.terminal.register_event_handler(
            move.SubjectFinishRotationEvent,
            self.rotate_subject,
        )

        self.terminal.register_event_handler(
            NewVisibleOpponent,
            self.new_visible_opponent,
        )

        self.terminal.register_event_handler(
            NoLongerVisibleOpponent,
            self.no_longer_visible_opponent,
        )

        self.terminal.register_event_handler(
            FireEvent,
            self.fire_happen,
        )

        self.terminal.register_event_handler(
            DieEvent,
            self.subject_die,
        )

        self.dead_soldier_image = pyglet.resource.image(
            self.graphic_path_manager.path('actors/man_d1.png', ))

        # subject/actor mapping
        self.subject_mapper_factory.register_mapper(
            ManSubject,
            SubjectMapper(self.config, ManActor),
        )
        self.subject_mapper_factory.register_mapper(
            TankSubject,
            SubjectMapper(self.config, HeavyVehicleActor),
        )
Exemplo n.º 7
0
def get_logger(name: str, config: Config) -> SynergineLogger:
    global_logging_level = config.resolve('global.logging_level', 'ERROR')
    logger_level_str = config.resolve('global.logger.{}.level',
                                      global_logging_level)
    logger_level = logging.getLevelName(logger_level_str)
    return get_default_logger('synergine-{}'.format(name), logger_level)