def LoadFromXMLFile(self, fileName): self.loadingLock += 1 self.LoadGameObjectsFolderFromXML(fileName) self.loadingLock -= 1 for prototype in self.prototypes: logger.debug(f"PostLoad for prototype {prototype.prototypeName}") prototype.PostLoad(self)
def get_selected_item_name_and_class(self): indexes = self.tree_prot_explorer.selectedIndexes() logger.debug(f"Indexes: {indexes}") prot_name = self.tree_prot_explorer.model().data(indexes[0]) prot_class = self.tree_prot_explorer.model().data(indexes[1]) if prot_class is None: return prot_name, None else: return prot_name, prot_class
def ReadNewPrototype(self, xmlFile, xmlNode: objectify.ObjectifiedElement): class_name = read_from_xml_node(xmlNode, "Class") logger.debug(f"Loading {class_name} prototype from {xmlNode.base}") prototype_info = self.theServer.CreatePrototypeInfoByClassName( class_name)(self.theServer) if prototype_info: prototype_info.className.value = class_name parent_prot_name = read_from_xml_node(xmlNode, "ParentPrototype", do_not_warn=True) if parent_prot_name is not None: parent_prot_info = self.InternalGetPrototypeInfo( parent_prot_name) dummy = PrototypeInfo(self.theServer) if parent_prot_info is None: logger.error( f"Parent prototype of {class_name} is not loaded! Expected parent: {parent_prot_name}" ) parent_prot_info = dummy prototype_info.CopyFrom(parent_prot_info) prototypes_length = len(self.prototypes) prototype_info.prototypeId = prototypes_length if prototype_info.LoadFromXML(xmlFile, xmlNode) == STATUS_SUCCESS: if self.prototypeNamesToIds.get( prototype_info.prototypeName.value) is not None: logger.critical( f"Duplicate prototype in game objects: {prototype_info.prototypeName.value}" ) raise AttributeError( "Duplicate prototype, critical error!") else: self.prototypeNamesToIds[ prototype_info.prototypeName. value] = prototype_info.prototypeId self.prototypes.append(prototype_info) self.prototypesMap[ prototype_info.prototypeName.value] = prototype_info if prototype_info.className.value not in self.prototypeClasses: self.prototypeClasses.append( prototype_info.className.value) return 1 else: logger.error( f"Prototype {prototype_info.prototypeName.value} " f"of class {prototype_info.className.value} was not loaded!" ) return 0 else: logger.error("Invalid class name: <{class_name}>!") return 0
def LoadAdditionalServers(self, file_name): xml_file_node = xml_to_objfy(file_name) if xml_file_node is not None: for server_node in xml_file_node.iterchildren(): server_container = self.servers.get(server_node.tag) if server_container is not None: logger.debug( f"Loading additional server :{server_container.name}") server_container.server.ReadFromXmlNode( xml_file_node, server_node, warn_on_duplication=False) else: logger.debug( f"Skipping loading unsupported server: {server_node.tag}" ) else: logger.error("Load servers: cannot find Servers")
def check_mono_xml_node(xml_node: objectify.ObjectifiedElement, expected_child_name: str, ignore_comments: bool = False): children = xml_node.getchildren() if len(children) > 0: for child in children: if child.tag != expected_child_name: if child.tag == "comment" and not ignore_comments: comment = unescape(str(etree.tostring(child))).strip("b'<!-- ").strip(" -->'") path = unquote(xml_node.base).replace(f'file:/{WORKING_DIRECTORY}', '') logger.debug(f"Comment '{comment}' " f"in tag: '{xml_node.tag}'' " f"in file: {path}.") else: logger.warning(f"Unexpected node with a name {child.tag} found " f"in xml node: {xml_node.tag} in {xml_node.base}!") else: logger.error(f"Empty node with a name {xml_node.tag} when expecting to find child " f"nodes with a name {expected_child_name} in {xml_node.base}")
def LoadFromXML(self, xmlFile, xmlNode: objectify.ObjectifiedElement): self.name = read_from_xml_node(xmlNode, "Name") forms_quantity = 1 is_prefix = self.affixGroup.affixType == 0 if is_prefix: forms_quantity = theEngineConfig.loc_forms_quantity if forms_quantity > 0: default_localized_string = self.GetLocalizedName(self.name) logger.debug( f"Default localized string {default_localized_string} found for {self.name}" ) for localization_index in range(forms_quantity): localized_string = self.GetLocalizedName( self.name, str(localization_index)) logger.debug( f"localized string {localized_string} found for {self.name}" ) modifications_str = read_from_xml_node(xmlNode, "modifications") modifications_str = modifications_str.split(";") for mod in modifications_str: modification = ModificationInfo(mod.strip()) self.modifications.append(modification)
def __init__(self, app): super(MainWindow, self).__init__() # setting up application skin and display properties self.app = app styles.dark(self.app.instance()) self.createIcons() logger.debug("setupMainTabWidget") self.setupMainTabWidget() self.setCentralWidget(self.main_tab_widget) self.createActions() self.setupTopMenu() self.setupToolBar() self.setupDockWindows() self.setupStatusBar() self.setWindowTitle('{} v{}'.format(APP_NAME, APP_VERSION))
def parse_model_group_health(relative_path: str): logger.debug(f"Trying to parse ModelGroups from '{relative_path}'") group_health = {} with open(os.path.join(WORKING_DIRECTORY, relative_path), 'rb') as f: str_from_file = f.read() if VehicleGamStruct.GROUP_HEALTH_HEADER.value in str_from_file: main_header = VehicleGamStruct.GROUP_HEALTH_HEADER.value elif VehicleGamStruct.GROUP_HEALTH_HEADER_URAL_CARGO.value in str_from_file: main_header = VehicleGamStruct.GROUP_HEALTH_HEADER_URAL_CARGO.value else: logger.debug(f"Model file '{relative_path}' given doesn't contain known GroupHealth headers!") return None group_health["Main"] = {"id": None, "variants": None} if VehicleGamStruct.BREAKABLE_BSTR.value in str_from_file: main_breakable_raw = str_from_file.split(main_header) breakables_raw = main_breakable_raw[1][main_breakable_raw[1].index(VehicleGamStruct.BREAKABLE_BSTR.value):] current_index = 0 while True: if breakables_raw[current_index:current_index + 3] == b"\x49\x56\x52": # IVR break # finding amount of variants for groups which dictates chunk length variants = breakables_raw[current_index + 28] if variants == 2: chunk_size = 60 elif variants == 3: chunk_size = 72 else: logger.error(f"Tried to parse HealthGroups for model containing group with {variants} variants!" "Only 2 and 3 are supported by toolkit!") breakable_string = breakables_raw[current_index:current_index + chunk_size] if VehicleGamStruct.BREAKABLE_BSTR.value in breakable_string: breakable_name = breakable_string[:11].decode('latin-1').replace('\x00', '') breakable_id = int(breakable_string[11:][21:22].hex(), 16) group_health[breakable_name] = {"id": breakable_id, "variants": variants} current_index += chunk_size # for byte_str in breakables_list: # if VehicleGamStruct.BREAKABLE_BSTR.value in byte_str: # breakable_name = byte_str[:11].decode('latin-1').replace('\x00', '') # breakable_id = int(byte_str[11:][21:22].hex(), 16) # group_health[breakable_name] = breakable_id return group_health else: logger.debug(f"Model file '{relative_path}' doesn't contain any breakable health zones.") return group_health
def log_comment(comment_node: objectify.ObjectifiedElement, parent_node: objectify.ObjectifiedElement): comment = unescape(str(etree.tostring(comment_node))).strip("b'<!-- ").strip(" -->'") path = unquote(parent_node.base).replace(f'file:/{WORKING_DIRECTORY}', '') logger.debug(f"Comment '{comment}' " f"in tag: '{parent_node.tag}'' " f"in file: {path}.")
def undo(self): logger.debug("Undo pressed") pass