예제 #1
0
 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")
예제 #2
0
    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()
예제 #3
0
 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")
예제 #4
0
 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
예제 #5
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)
예제 #6
0
    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()
예제 #7
0
 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
예제 #8
0
파일: Label.py 프로젝트: pyengine3/PyEngine
    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()
예제 #9
0
    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
예제 #10
0
 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")
예제 #11
0
 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.")
예제 #12
0
 def add_command(self, name, function):
     if name in self.commands:
         loggers.get_logger("PyEngine").warning("Command overrided : " +
                                                name)
     self.commands[name] = function
예제 #13
0
 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")