Ejemplo n.º 1
0
    def exec_look_at(self):
        """
        This non-constant method executes the "look at" command: First, it finds out which entity
        is meant, which can be the place we are at, another entity at our place or even ourselves!
        If it couldn't find the requested entity, it the user so. Then, it receives the description
        of the targeted entity and displays it.
        """
        target_name = self.get_argument_as_string()
        place = self.parent().parent()
        keyword_place = Core.get_res_man().get_string("core.gameplayParser.lookAt.keyword.place")
        key_inventory = "core.gameplayParser.lookAt.keyword.inventory"
        keyword_inventory = Core.get_res_man().get_string(key_inventory)

        if len(target_name) == 0:
            self.window.show_text(place.generate_description())
        elif target_name == keyword_place or target_name == place.objectName():
            self.window.show_text(place.generate_description())
        elif target_name == keyword_inventory:
            self.window.show_text(self.parent().generate_inventory_list(empty_note=True) + ".")
        else:
            target = place.findChild(Core.Entity, target_name)
            if target is None:
                self.window.show_text("${core.gameplayParser.invalidTargetMessage}")
            else:
                self.window.show_text(target.generate_description())
Ejemplo n.º 2
0
    def exec_combine(self):
        """
        This non-constant method executes the "combine" command: First, it searches for the
        argument separator in our argument, then it extracts the two arguments from the list and
        connects them into two strings. The next step is that it tries the find the entities with
        the given names and to lookup the class of combination result. When this is all done, it
        creates the product and deletes the old entities, in this order. If anything went wrong in
        this process, it tells the user that he/she messed up and ends without changing anything.
        """
        # Get the whole argument text.
        argument = self.get_argument()

        # Find the combination argument separator, usually 'with'.
        separator = Core.get_res_man().get_string("core.gameplayParser.combine.argumentSeparator")
        separator_position = -1
        for i in range(0, len(argument)):
            if argument[i] == separator:
                separator_position = i
                break

        arg_a = None
        arg_b = None
        arg_a_name = str()
        arg_b_name = str()
        if separator_position == -1:
            # If there is no separator and therefore only one argument, patch the argument together.
            for word in argument[0:-1]:
                arg_a_name += word + " "
            arg_a_name += argument[-1]
        else:
            # If there are two arguments, patch both names together.
            for word in argument[0:separator_position-1]:
                arg_a_name += word + " "
            arg_a_name += argument[separator_position-1]

            for word in argument[separator_position+1: len(argument)-1]:
                arg_b_name += word + " "
            arg_b_name += argument[len(argument)-1]

            # Find entity B
            arg_b = self.parent().parent().findChild(Core.Entity, arg_b_name)
            if arg_b is None:
                text = "${core.gameplayParser.invalidTargetMessage}"
                self.window.show_text(text)
                return

        # Find entity A, which is always needed.
        arg_a = self.parent().parent().findChild(Core.Entity, arg_a_name)
        if arg_a is None:
            text = "${core.gameplayParser.invalidTargetMessage}"
            self.window.show_text(text)
            return

        # Call entity A's "on_used" method.
        if not arg_a.on_used(self.parent(), arg_b):
            text = "${core.gameplayParser.genericError}"
            self.window.show_text(text)
            return
Ejemplo n.º 3
0
 def add_option_button(self, text):
     """
     This non-constant method adds an option button with the given text to the command row and
     returns it. The text may contain unresolved resource string keys as they will be resolved
     inside this method.
     """
     text = Core.get_res_man().decode_string(text)
     button = QPushButton(text, self.command_row)
     child_number = len(self.command_row.children())
     button.setObjectName("option_button_" + str(child_number))
     self.command_row.layout().addWidget(button)
     self.scroll_text_area_down()
     return button
Ejemplo n.º 4
0
 def show_text(self, text, emplace_res_strings=True, add_html_tags=True):
     """
     Thi non-constant method prints the given text in the text area as it's own paragraph.
     If emplace_res_strings is True (default), it will also decode resource string keys in
     it and if add_html_tags is True (default), it will add tags to the text that indicate that
     it should be handled as an HTML snippet.
     """
     self.text_area.setTextColor(QColor(0, 0, 0))
     if emplace_res_strings:
         text = Core.get_res_man().decode_string(text)
     if add_html_tags:
         text = '<html><body>' + text + '</body></html>'
     self.text_area.append(text)
     self.text_area.show()
     self.scroll_text_area_down()
Ejemplo n.º 5
0
    def filter_ignored_words(self):
        """
        This non-constant method gets all ignored words from the resources manager and removes
        every appearence from our split_text.
        """
        parsers_root = Core.get_res_man().get_element("core.gameplayParser")
        ignored_words = []
        for word in parsers_root.findall("ignoreWord"):
            ignored_words.append(word.text)

        index = 0
        while index < len(self.split_text):
            if self.split_text[index] in ignored_words:
                del self.split_text[index]
            else:
                index += 1
Ejemplo n.º 6
0
    def __init__(self, parent=None):
        Core.Entity.__init__(self, parent)

        self.setObjectName(Core.get_res_man().get_string("core.player.name"))
        self.description = "${core.player.description}"
        self.hidden = True
        self.gender = "f"
        self.show_article = False

        self.window = ClientWindow()
        self.window.show()

        self.gameplay_parser = GameplayParser(self)

        self.window.return_pressed.connect(self.gameplay_parser.command_entered)

        self.set_state("first run", 1)
Ejemplo n.º 7
0
    def __init__(self):
        QMainWindow.__init__(self)

        self.command_stack = []

        self.setObjectName("client_window")
        self.setWindowModality(Qt.NonModal)
        self.resize(800, 600)
        self.setDocumentMode(False)
        self.raw_title = Core.get_res_man().get_string("core.windowTitle")
        self.setWindowTitle(self.raw_title)

        central_widget = QWidget(self)
        central_widget.setObjectName("central_widget")
        self.setCentralWidget(central_widget)

        vertical_layout = QVBoxLayout(central_widget)
        vertical_layout.setObjectName("vertical_layout")
        central_widget.setLayout(vertical_layout)

        self.text_area = QTextEdit(central_widget)
        self.text_area.setReadOnly(True)
        self.text_area.setObjectName("text_area")
        vertical_layout.addWidget(self.text_area)

        self.command_row = QWidget(central_widget)
        self.command_row.setObjectName("command_row")
        vertical_layout.addWidget(self.command_row)

        command_row_layout = QHBoxLayout(self.command_row)
        command_row_layout.setObjectName("command_row_layout")
        command_row_layout.setContentsMargins(0, 0, 0, 0)
        command_row_layout.setSpacing(0)
        self.command_row.setLayout(command_row_layout)

        self.add_command_line()

        menu_bar = QMenuBar(self)
        menu_bar.setObjectName("menubar")
        self.setMenuBar(menu_bar)
Ejemplo n.º 8
0
    def identify_command(self):
        """
        This non-constant method identifies and executes the previously read command.
        """
        string_collection = Core.get_res_man().get_element("core.gameplayParser")

        if len(self.split_text) == 0:
            pass
        elif self.compare_commands_with_text(string_collection.find("lookAt").findall("command")):
            self.exec_look_at()
        elif self.compare_commands_with_text(string_collection.find("walkTo").findall("command")):
            self.exec_walk_to()
        elif self.compare_commands_with_text(string_collection.find("pickUp").findall("command")):
            self.exec_pick_up()
        elif self.compare_commands_with_text(string_collection.find("drop").findall("command")):
            self.exec_drop()
        elif self.compare_commands_with_text(string_collection.find("combine").findall("command")):
            self.exec_combine()
        elif self.compare_commands_with_text(string_collection.find("talk").findall("command")):
            self.exec_talk()
        else:
            self.exec_invalid_command()