def get_widget(self, identity: int) -> Widget: liste = [i for i in self.widgets if i.identity == identity] if len(liste): return liste[0] loggers.get_logger("PyEngine").warning("Try to get widget with id " + str(identity) + " but it doesn't exist")
def __init__(self, position: Vec2, text: str, color: Color = Colors.WHITE.value, font: Font = Font(), background: Union[None, Color] = None): super(MultilineLabel, self).__init__(position) if not isinstance(font, Font): raise TypeError("Font have not a Font type") if not isinstance(color, Color): raise TypeError("Color have not a Color type") if not isinstance(background, Color) and background is not None: raise TypeError("Background must be a Color") if "\n" not in text: loggers.get_logger("PyEngine").info( "MultilineLabel without Line break is useless. Use Label.") self.__text = text self.labels = [ Label(Vec2(self.position.x, self.position.y + 20 * (k + 1)), v) for k, v in enumerate(text.split("\n")) ] self.__color = color self.__font = font self.__background = background self.update_render()
def get_component(self, component: ctypes) -> cunion: liste = [i for i in self.components if isinstance(i, component)] try: return liste[0] except IndexError: loggers.get_logger("PyEngine").warning("Try to get " + str(component) + " but Entity don't have it")
def sprites(self, sprites: List): if not (isinstance(sprites, list) or isinstance(sprites, tuple)) and len(sprites) == 0: raise ValueError("Sprites must be a List with minimum one sprite") elif len(sprites) == 1: loggers.get_logger("PyEngine").info( "AnimatedImage is useless with only one sprite. Use Image.") self.__sprites = sprites self.sprite = sprites[0] self.current_sprite = 0
def execute_command(self, command): if len(command.split(" ")) > 1: args = command.split(" ")[1:] else: args = [] command = command.split(" ")[0] if command in self.commands: self.commands[command](self, self.window, args) else: loggers.get_logger("PyEngine").warning("Unknown command : " + command)
def text(self, text): if len(self.labels): [self.system.remove_widget(i) for i in self.labels] if "\n" not in text: loggers.get_logger("PyEngine").info( "MultilineLabel without Line break is useless. Use Label.") self.__text = text self.labels = [ Label(Vec2(self.position.x, self.position.y + 20 * (k + 1)), v) for k, v in enumerate(text.split("\n")) ] [self.system.add_widget(i) for i in self.labels] self.update_render()
def __init__(self, position: Vec2, sprites: List, timer: int = 20, size: Vec2 = None): if not isinstance(sprites, (list, tuple)) and len(sprites) == 0: raise ValueError("Sprites must be a List with minimum one sprite") elif len(sprites) == 1: loggers.get_logger("PyEngine").info( "AnimatedImage is useless with only one sprite. Use Image.") super(AnimatedImage, self).__init__(position, sprites[0], size) self.__sprites = sprites self.timer = timer - 1 self.current_sprite = 0 self.play = True
def __init__(self, position: Vec2, text: str, color: Color = Colors.WHITE.value, font: Font = Font(), background: Union[None, Color] = None): super(Label, self).__init__(position) if not isinstance(font, Font): raise TypeError("Font have not a Font type") if not isinstance(color, Color): raise TypeError("Color have not a Color type") if not isinstance(background, Color) and background is not None: raise TypeError("Background must be a Color") if "\n" in text: loggers.get_logger("PyEngine").warning("Line break doesn't work with Label. Use MultilineLabel") text = text.replace("\n", "") self.__color = color self.__font = font self.__background = background self.text = text self.update_render()
def __init__(self, pos, file, scale=1): super(Tilemap, self).__init__() self.folder = "/".join(file.split("/")[:-1]) + "/" self.add_component(PositionComponent(pos)) self.add_component(TextComponent("")) with open(file, "r") as f: datas = json.load(f) if datas["infinite"]: raise ValueError("PyEngine can't use infinite map") if len(datas["tilesets"]) > 1: loggers.get_logger("PyEngine").warning( "Tilemap use only 1 tileset.") if len(datas["layers"]) > 1: loggers.get_logger("PyEngine").warning("Tilemap use only 1 layer.") self.height = datas["height"] self.width = datas["width"] self.tileheight = datas["tileheight"] self.tilewidth = datas["tilewidth"] tileset = ElementTree.parse(self.folder + datas["tilesets"][0]["source"]) idtiles = {} for tile in tileset.getroot(): if tile.tag == 'tile': idtiles[tile.attrib["id"]] = tile[0].attrib["source"] self.tiles = [ self.create_tile(datas, idtiles, pos, x, y) for y in range(self.height) for x in range(self.width) ] self.tiles = [x for x in self.tiles if x is not None] self.scale = scale
def get_system(self, classe: stypes) -> sunion: liste = [i for i in self.systems.values() if type(i) == classe] if len(liste): return liste[0] loggers.get_logger("PyEngine").warning("Try to get " + str(classe) + " but World don't have it")
def remove_component(self, component: ctypes) -> None: for i in [i for i in self.components if isinstance(i, component)]: loggers.get_logger("PyEngine").debug("Deleting " + str(component)) self.components.remove(i) loggers.get_logger("PyEngine").info( "Deleting component can be dangerous.")
def add_command(self, name, function): if name in self.commands: loggers.get_logger("PyEngine").warning("Command overrided : " + name) self.commands[name] = function
def get_entity(self, identity: int) -> Entity: for i in self.entities: if i.identity == identity: return i loggers.get_logger("PyEngine").warning("Try to get entity with id "+str(identity)+" but it doesn't exist")