Beispiel #1
0
    def LoadServers(self, file_name):
        anim_models_alias = "AnimatedModelsServer"
        # static_models_alias = "StaticModelsServer",
        # light_alias = "LightsServer"
        # sprite_alias = "SpritesServer"
        # particles_alias = "ParticlesServer"
        # sounds_alias = "SoundsServer"
        # music_alias = "MusicServer"
        # projectors_alias = "ProjectorsServer"
        # decals_alias = "DecalsServer"
        self.servers = {}  # 9 servers total
        animated_models_server = self.ServerContainer(
            AnimatedModelsServer(), anim_models_alias,
            theWndStation.GetStringByStringId(anim_models_alias, "0"))
        self.servers[anim_models_alias] = animated_models_server
        animated_models_server.server.AddAllItems(
            os.path.join(WORKING_DIRECTORY, "data/models/animmodels.xml"))
        logger.info(f"Loading Servers: {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.info(f"Loading server :{server_container.name}")
                    server_container.server.ReadFromXmlNode(
                        xml_file_node, server_node)

                else:
                    logger.info(
                        f"Skipping loading unsupported server: {server_node.tag}"
                    )
        else:
            logger.error("Load servers: cannot find Servers")
Beispiel #2
0
 def _LoadVehiclePartTypeToResourceXmlFile(self, some_other_int, fileName):
     vehiclePartTypesXmlNode = xml_to_objfy(fileName)
     if vehiclePartTypesXmlNode.tag == "VehiclePartTypes":
         if len(vehiclePartTypesXmlNode.getchildren()) > 0:
             check_mono_xml_node(vehiclePartTypesXmlNode, "VehiclePart")
             for vehicle_part in vehiclePartTypesXmlNode["VehiclePart"]:
                 vehiclePartName = read_from_xml_node(
                     vehicle_part, "PartName")
                 resourceName = read_from_xml_node(vehicle_part,
                                                   "ResourceName")
                 if self.GetResourceId(resourceName) == -1:
                     logger.warning(
                         f"ResourceManager: warning - invalid resource name '{resourceName}' "
                         f"is matched to vehicle part type '{vehiclePartName}'"
                     )
                 else:
                     if self.vehiclePart2Resource.get(
                             vehiclePartName) is None:
                         self.vehiclePart2Resource[
                             vehiclePartName] = resourceName
                     else:
                         raise NameError(
                             f"ResourceManager: Can't add vehicle part with name {vehiclePartName} "
                             f"to vehiclePart2Resource map. Already exist mapping with this name."
                         )
     else:
         raise FileNotFoundError("Can't load VehiclePartTypes from XML!")
Beispiel #3
0
 def LoadGlobalPropertiesFromXML(self, fileName):
     xmlFile = xml_to_objfy(fileName)
     if xmlFile.tag == "Properties":
         self.theGlobalProperties = GlobalProperties()
         self.theGlobalProperties.LoadFromXML(fileName, xmlFile)
     else:
         raise NameError("GlobalProperties file should contain root Properties tag")
Beispiel #4
0
 def LoadStrings(self, stringsName: str):
     xmlFile = xml_to_objfy(stringsName)
     if xmlFile.tag == "resource":
         check_mono_xml_node(xmlFile, "string")
         for xml_node in child_from_xml_node(xmlFile, "string"):
             id_attr = read_from_xml_node(xml_node, "id")
             value_attr = read_from_xml_node(xml_node, "value")
             self.strings[id_attr] = value_attr
Beispiel #5
0
 def _LoadFromXmlFile(self, some_int, fileName):
     resourceTypesXmlNode = xml_to_objfy(fileName)
     if resourceTypesXmlNode.tag == "ResourceTypes":
         check_mono_xml_node(resourceTypesXmlNode, "Type")
         for resource in resourceTypesXmlNode["Type"]:
             self._ReadResourceFromXml(fileName, resource, 0)
     else:
         raise FileNotFoundError("Can't load ResourceTypes from XML!")
Beispiel #6
0
 def LoadGameObjectsFolderFromXML(self, fileName):
     xmlFileNode = xml_to_objfy(fileName)
     if xmlFileNode.tag != "Prototypes":
         raise AttributeError(
             f"Given file {xmlFileNode.base} should contain <Prototypes> tag!"
         )
     directory = path.dirname(fileName)
     self.LoadFromFolder(fileName, xmlFileNode, directory)
Beispiel #7
0
 def AddItems(self, params, model_id):
     item = self.GetItemByName(model_id, False)
     if item == -1:
         proto = self.ParseProto(params)
         if proto == 1:
             xml_file_node = xml_to_objfy(params)
             if xml_file_node.tag == "AnimatedModels":
                 for model_node in xml_file_node.iterchildren(tag="model"):
                     anim_model = self.AnimatedModel()
                     anim_model.model_id = safe_check_and_set(
                         item.id, model_node, "id")
Beispiel #8
0
    def LoadFromXML(self, fileName):
        xmlFile = xml_to_objfy(fileName)
        if xmlFile.tag == "Affixes":
            check_mono_xml_node(xmlFile, "ForResource")
            for resource_node in xmlFile["ForResource"]:
                resource_name = read_from_xml_node(resource_node, "Name")
                resource_id = self.theResourceManager.GetResourceId(
                    resource_name)
                if resource_id == -1:
                    logger.warning(
                        f"Error loading affixes: invalid resource name: {resource_name}"
                    )
                else:
                    prefixes = child_from_xml_node(resource_node,
                                                   "Prefixes",
                                                   do_not_warn=True)
                    suffixes = child_from_xml_node(resource_node,
                                                   "Suffixes",
                                                   do_not_warn=True)

                    if prefixes is not None:
                        check_mono_xml_node(prefixes, "AffixGroup")
                        for affix_group_node in child_from_xml_node(
                                prefixes, "AffixGroup"):
                            affix_group = AffixGroup(self)
                            affix_group.affixType = 0
                            affix_group.LoadFromXML(xmlFile, affix_group_node)

                            affix_groups_list_size = len(self.affixGroups)
                            affix_group.affixGroupId = affix_groups_list_size
                            affix_group.targetResourceId = resource_id

                            self.affixGroups.append(affix_group)
                    if suffixes is not None:
                        check_mono_xml_node(suffixes, "AffixGroup")
                        for affix_group_node in child_from_xml_node(
                                suffixes, "AffixGroup"):
                            affix_group = AffixGroup(self)
                            affix_group.affixType = 1
                            affix_group.LoadFromXML(xmlFile, affix_group_node)

                            affix_groups_list_size = len(self.affixGroups)
                            affix_group.affixGroupId = affix_groups_list_size
                            affix_group.targetResourceId = resource_id

                            self.affixGroups.append(affix_group)
                    if suffixes is None and prefixes is None:
                        logger.warning(
                            f"Affixes node for resource {resource_name} has no Prefixes and no Suffixes!"
                        )
        else:
            raise NameError("Affixes file should contain root Affixes tag")
Beispiel #9
0
 def AddAllItems(self, filepath):
     '''Replacement to read all models from animmodels.xml'''
     xml_file_node = xml_to_objfy(filepath)
     if xml_file_node.tag == "AnimatedModels":
         for model_node in xml_file_node.iterchildren(tag="model"):
             anim_model = self.AnimatedModel()
             anim_model.model_id = safe_check_and_set(
                 anim_model.model_id, model_node, "id")
             anim_model.file_name = safe_check_and_set(
                 anim_model.file_name, model_node, "file")
             # ToDo: deprecate check on duplication if not needed
             if self.models.get(anim_model.model_id) is not None:
                 logger.warning(
                     f"Duplicate model found in animmodels.xml with id: '{anim_model.model_id}'"
                 )
             self.models[anim_model.model_id] = anim_model
Beispiel #10
0
    def LoadFromXML(self, xmlFile, copy_to_default: bool = True):
        xmlNode = xml_to_objfy(xmlFile)
        if xmlNode.tag != "relationship":
            raise ValueError(
                "Relationship XML should contain root tag 'relationship'!")
        formatType = 0
        self.minID = int(read_from_xml_node(xmlNode, "MinPlayerID"))
        self.maxID = int(read_from_xml_node(xmlNode, "MaxPlayerID"))
        default_tolerance_name = read_from_xml_node(xmlNode,
                                                    "DefaultTolerance")
        self.defaultTolerance = self.GetToleranceByName(default_tolerance_name)

        if self.minID <= self.maxID:
            if self.maxID - self.minID + 1 > 1000:
                self.maxID = self.minID + 1001
                logger.warning(
                    f"Tolerance range can't be more than 1001, for example 1000-2001 range is valid."
                    f"Reseting max value to be {self.maxID}")
            self.pTolerance = {}
            tolerance_range_len = self.maxID - self.minID
            tolerance_id_range = range(0, tolerance_range_len**2)
            for tolerance_id in tolerance_id_range:
                self.pTolerance[tolerance_id] = self.defaultTolerance
            format_type_read = read_from_xml_node(xmlNode,
                                                  "FormatType",
                                                  do_not_warn=True)
            if format_type_read is not None:
                formatType = int(format_type_read)
            if formatType != 0:
                if formatType == 1:
                    raise NotImplementedError(
                        "Can't work with saves yet, do not load from currentmap.xml"
                    )
                    self.LoadFormat(
                        xmlFile, xmlNode,
                        1)  # ??? do we even need this for format_type 1?
                else:
                    raise ValueError(
                        f"Invalid format type {formatType} for relationship")
            else:
                self.LoadFormat(xmlFile, xmlNode, 0)
        if copy_to_default:
            self.pDefaultTolerance = self.pTolerance
        else:
            raise ValueError(
                "Relationship MinPlayerID should be less than MaxPlayerID")
Beispiel #11
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")