示例#1
0
    def __load_msgdhr__(self, f):
        with open(f, "r") as fd:
            for line in fd:
                if self.token_snapshot in line or self.token_packet in line:
                    line = line.replace("#define", "")
                    line = line.replace("# define", "")
                    line = line.replace(" ", "\t")
                    line = line.split('\t')
                    newelement = ""
                    for elem in line:
                        if len(elem) > 0 and elem != "":
                            newelement = elem
                            break
                    if self.token_packet in newelement:
                        self.packets.append(newelement)
                    elif self.token_snapshot in newelement:
                        self.snapshots.append(newelement)
                    else:
                        gLogger.error("Unknow:", newelement)

        gLogger.write(
            gProject.path_filter + "infos_packettype.txt", self.packets,
            "{infos} {f}".format(infos="writing list PACKETTYPE in:",
                                 f=gProject.path_filter +
                                 "infos_snapshottype.txt"))
        gLogger.write(
            gProject.path_filter + "infos_snapshottype.txt", self.snapshots,
            "{infos} {f}".format(infos="writing list SNASHOPTYPE in:",
                                 f=gProject.path_filter +
                                 "infos_snapshottype.txt"))
示例#2
0
    def __load_setting__(self, q, fd):
        sep = fd.readline().replace("\t", "").replace("\n", "")
        if len(sep) != 1 or sep != "{":
            message = "error: [{char}]".format(char=sep)
            gLogger.info(message)
            return None

        while True:
            line = fd.readline().replace("\n", "").replace("\t", "").replace(
                " ", "").replace("\"", "")
            if len(line) <= 0:
                continue
            elif "}" in line:
                break
            else:
                line = line.replace("(", ",").replace(")", "").replace(";", "")
                arr = line.split(",")
                if len(arr) <= 1:
                    gLogger.error("syntaxe line error:", q.Id, line)
                    return None
                fct = arr[0]
                q.Setting[fct] = list()
                i = 1
                while i < len(arr):
                    q.Setting[fct].append(arr[i])
                    i = i + 1

        return True
示例#3
0
    def __write_config_xml__(self):
        gLogger.set_section("propQuest")
        gLogger.info("writing quest XML")

        root = ET.Element("quests")

        for it in self.Quests:
            quest = self.Quests[it]
            section_quest = ET.SubElement(root, "quest")
            section_questions = ET.SubElement(section_quest, "questions")
            section_conditions = ET.SubElement(section_quest, "conditions")
            section_states = ET.SubElement(section_quest, "states")

            section_quest.set("dwID", quest.Id.replace("\"", ""))
            section_quest.set("szTitle", quest.Title)

            for action in quest.Dialog:
                sub_section = ET.SubElement(section_questions, "dialog")
                sub_section.set("action", action)
                sub_section.set("text", quest.Dialog[action])

            for fct in quest.Setting:
                setting = quest.Setting[fct]
                section_condition = ET.SubElement(section_conditions,
                                                  "condition")
                section_condition.set("function", fct)
                if fct == "SetBeginCondPreviousQuest":
                    section_condition.set("nBeginCondPreviousQuestType",
                                          setting[0])
                for i in range(0, len(setting)):
                    if fct in ParamCondition:
                        section_condition.set(ParamCondition[fct][i],
                                              setting[i])
                    elif fct == "SetBeginCondJob":
                        section_condition.set(setting[i], "1")
                    elif fct == "SetBeginCondPreviousQuest":
                        if i == 0:
                            section_condition.set(
                                "nBeginCondPreviousQuestType", setting[0])
                        else:
                            section_condition.set(setting[i], "1")
                    else:
                        gLogger.error("condition unknow", it, fct)

            for value in quest.State:
                state = quest.State[value]
                section = ET.SubElement(section_states, "state")
                section.set("type", value)
                for fct in state:
                    param = state[fct]
                    section.set(fct, param)

        tree = ET.ElementTree(root)
        tree.write(self.out_filename_xml,
                   pretty_print=True,
                   xml_declaration=True)
        gLogger.reset_section()
示例#4
0
    def __write_config_json__(self):
        gLogger.set_section("propquest")
        gLogger.info("writing quest JSON")

        data = dict()

        for name_quest in self.Quests:
            quest = self.Quests[name_quest]
            data[name_quest] = {
                "id": quest.Id.replace("\"", ""),
                "title": quest.Title,
                "dialog": [],
                "condition": {},
                "type": {}
            }

            for action in quest.Dialog:
                data[name_quest]["dialog"].append({
                    "action": action,
                    "text": quest.Dialog[action]
                })

            for name_function in quest.Setting:
                setting = quest.Setting[name_function]
                condition = dict()
                if name_function == 'SetBeginCondPreviousQuest':
                    condition["nBeginCondPreviousQuestType"] = setting[0]
                for i in range(0, len(setting)):
                    if name_function in ParamCondition:
                        condition[ParamCondition[name_function]
                                  [i]] = setting[i]
                    elif name_function == "SetBeginCondJob":
                        condition[setting[i]] = 1
                    elif name_function == "SetBeginCondPreviousQuest":
                        if i == 0:
                            condition["nBeginCondPreviousQuestType"] = setting[
                                0]
                        else:
                            condition["nBeginCondPreviousQuestType"] = 1
                    else:
                        gLogger.error("condition unknow", name_quest,
                                      name_function)
                data[name_quest]["condition"][name_function] = condition

            for value in quest.State:
                for state in quest.State[value]:
                    data[name_quest]["type"][
                        QAction[value]] = quest.State[value][state]

        with open(self.out_filename_json, 'w') as fd:
            json.dump(data, fd, indent=4)

        gLogger.reset_section()
示例#5
0
 def __write_sub_section__(self, arr, xml_section, title, list_type):
     for index in arr:
         section = ET.SubElement(xml_section, title)
         object = arr[index]
         if object["dwModelType"] not in list_type:
             gLogger.error(title, "have wrong model type:", index,
                           object["dwModelType"])
             return None
         for i in range(0, len(ModelParams)):
             key = ModelParams[i]
             value = object[key]
             section.set(key, value)
     return True
示例#6
0
    def load(self, f):
        gLogger.set_section("propquest")
        self.in_filename = f
        gLogger.info("loading:", self.in_filename)
        new_quest = True
        with open(self.in_filename, "r") as fd:
            q = None
            for line in fd:
                line = line.replace("\n", "")
                line = line.replace(" ", "\t")
                if "\\" in line or line == "" or line == "\t":
                    continue
                s = False
                for it in line:
                    if it != "\t":
                        s = True
                        break
                if s is False:
                    continue

                if new_quest is True:
                    q = Quest()
                    new_quest = False
                    line = line.replace("\t", "")
                    q.Id = line
                    fd.readline()
                    continue

                if "SetTitle" in line:
                    if self.__load_set_title__(q, fd) is None:
                        return None
                elif "setting" in line or "Setting" in line:
                    if self.__load_setting__(q, fd) is None:
                        return None
                elif "SetDialog" in line:
                    if self.__load_dialog__(q, fd) is None:
                        return None
                elif "state" in line:
                    if self.__load_state__(q, fd, line) is None:
                        return None
                else:
                    self.Quests[q.Id] = q
                    line = line.replace("\t", "")
                    if len(line) != 1 or line != "}":
                        gLogger.error("line != }", line)
                        return None
                    new_quest = True

        gLogger.reset_section()
        return True
示例#7
0
 def __load_lnd__(self, fn, world, define):
     gLogger.info("loading:", fn)
     x = int(0)
     y = int(0)
     with open(fn, "rb") as fd:
         version = bytes_to_unsigned_int(fd.read(4))
         if version <= 0:
             gLogger.error("version:", version, "is unknow")
         if version >= 1:
             y = bytes_to_unsigned_int(fd.read(4))
             x = bytes_to_unsigned_int(fd.read(4))
         self.__load_lnd_terrain__(fd, world, y, x)
         self.__load_lnd_water__(fd, world, y, x)
         if version >= 2:
             world.land_attributes = fd.read(WATER_AREA)  # land attributes
         self.__load_lnd_layer__(fd, world, y, x)
         self.__load_lnd_obj__(fd, world, y, x)
示例#8
0
 def __load_world_inc__(self, define_world):
     index = str()
     with open(self.file_listing_world, "r") as fd:
         for line in fd:
             line = line.replace("\n", "")
             arr = splitter(line)
             arr = self.__clean_arr__(arr)
             if len(arr) == 2 and "SetTitle" not in arr[1]:
                 world = World()
                 world.MPU = MPU
                 world.id = str(arr[0])
                 if world.id not in define_world:
                     gLogger.error("World undeclared: [{id_world}]".format(
                         id_world=world.id))
                     continue
                 world.directory = str(arr[1]).replace("\"", "")
                 self.worlds[world.id] = world
             elif len(arr) == 2 and "SetTitle" in arr[1]:
                 index = arr[0]
             elif len(arr) == 1 and "IDS_WORLD_INC" in arr[0]:
                 if index in self.worlds:
                     self.worlds[index].title = arr[0]
                 else:
                     gLogger.error("SetTitle on world undeclared:", index)