Пример #1
0
    def delete_command(self, command):
        """
            Remove command from Console

            :param command: Command
        """
        try:
            del self.commands[command]
        except KeyError:
            logger.warning("Command '" + command + "' doesn't exist")
Пример #2
0
    def remove_widget(self, widget):
        """
            Remove an widget from UISystem

            :param widget: Widget to remove
        """
        if self.has_widget(widget):
            self.widgets.remove(widget)
        else:
            logger.warning("Widget is not in UISystem")
Пример #3
0
    def add_command(self, command, function):
        """
            Add command to Console

            :param command: Command
            :param function: Function triggered when command is call
        """
        if command in self.commands.keys():
            logger.warning("Command overrided : " + command)
        self.commands[command] = function
Пример #4
0
    def text(self, text):
        """
            Set text of Label

            :param text: Text
        """
        self.__text = text

        if "\n" in text:
            logger.warning("Label doesn't support multiline. Use MultilineLabel")
Пример #5
0
    def remove_entity(self, entity):
        """
            Remove an entity from EntitySystem

            :param entity: Entity to remove
        """
        if self.has_entity(entity):
            self.entities.remove(entity)
        else:
            logger.warning("Entity is not in EntitySystem")
Пример #6
0
    def set_callback(self, callback, function):
        """
            Set callback of Window

            :param callback: Callback to set
            :param function: Function which is triggered by the callback
        """
        if callback in self.callbacks.keys():
            self.callbacks[callback] = function
        else:
            logger.warning("The callback '{}' doesn't exist.", callback)
Пример #7
0
    def remove_component(self, tcomponent):
        """
            Remove component with its type

            :param tcomponent: Type of Component

            .. warning:: This can be dangerous
        """
        logger.info("Remove component can be dangerous.")
        if self.has_component(tcomponent):
            self.components.remove(self.get_component(tcomponent))
        else:
            logger.warning("Entity doesn't have " + str(tcomponent))
Пример #8
0
    def get_component(self, tcomponent):
        """
            Get component from entity with its type

            :param tcomponent: Type of Component
            :return: Component or None

            .. note:: Return None if entity hasn't this type of component
        """
        if self.has_component(tcomponent):
            return tuple(i for i in self.components
                         if isinstance(i, tcomponent))[0]
        logger.warning("Entity doesn't have " + str(tcomponent))
Пример #9
0
    def create(self, dic):
        """
            Create config from dict

            :param dic: Dictionary of config
        """
        if self.created:
            logger.warning("Config File already exist but recreated")
        else:
            logger.info("Config File created")
        with open(self.file, "w") as f:
            f.write(json.dumps(dic, indent=4))
        self.dic = dic
Пример #10
0
    def add_widget(self, widget):
        """
            Add an widget in UISystem

            :param widget: Widget to be added
        """
        if self.has_widget(widget):
            logger.warning("Widget already in UISystem")
        else:
            if len(self.widgets):
                widget.identity = self.widgets[-1].identity + 1
            else:
                widget.identity = 0
            widget.system = self
            self.widgets.append(widget)
Пример #11
0
    def add_entity(self, entity):
        """
            Add an entity in EntitySystem

            :param entity: Entity to be added
        """
        if self.has_entity(entity):
            logger.warning("Entity already in EntitySystem")
        else:
            if len(self.entities):
                entity.identity = self.entities[-1].identity + 1
            else:
                entity.identity = 0
            entity.system = self
            self.entities.append(entity)
Пример #12
0
    def file(self, file):
        """
            Set lang file

            :param file: Path of lang file
        """
        self.dic = {}
        self.__file = file
        if os.path.exists(file):
            with open(file) as f:
                for i in f.readlines():
                    if len(i.split(": ")) == 2:
                        self.dic[i.split(": ")[0]] = i.split(": ")[1].replace("\n", "")
                    else:
                        logger.warning("Unknown format of Lang. You must use 'key: value'")
        else:
            logger.error("Lang file doesn't exist")
Пример #13
0
    def execute_command(self, command):
        """
            Execute command of Console

            :param command: Console to execute

            .. note:: You may not use this method. Console make it for you.
        """
        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:
            logger.warning("Unknown command : " + command)
Пример #14
0
    def add_component(self, component):
        """
            Add component to entity

            :param component: Component to be added
            :return: Component added
        """
        if isinstance(component, tuple(type(c) for c in self.components)):
            logger.warning("Entity already have a " +
                           str(component.__class__.__name__))
        else:
            for i in component.required_components:
                if i not in set(type(c) for c in self.components):
                    logger.warning(
                        str(component.__class__.__name__) + " require " +
                        str(i.__name__))
                    return
            for i in component.incompatible_components:
                if i in set(type(c) for c in self.components):
                    logger.warning(
                        str(component.__class__.__name__) +
                        " is incompatible with " + str(i.__name__))
                    return
            component.entity = self
            self.components.add(component)
            return component