def saveFile(self, fileName: str) -> None:
        '''Saves XML files'''
        campaign = self.campaigns[self.__selectedCampaignIndex]
        self.__xmlWriter.campaignWriter(campaign, fileName)

        if len(self.__newTradeRoutes) > 0:
            self.__xmlWriter.tradeRouteWriter(self.__newTradeRoutes)

        if len(self.__updatedPlanetCoords) > 0 :
            xmlReader = XMLReader()
            gameObjectFile = XMLStructure.dataFolder + "/XML/GameObjectFiles.XML"
            planetRoots = xmlReader.findPlanetFilesAndRoots(gameObjectFile)
            self.__xmlWriter.planetCoordinatesWriter(XMLStructure.dataFolder + "/XML/", planetRoots, self.__updatedPlanetCoords)
Esempio n. 2
0
    def planetVariantWriter(self, path, planetVariants):
        '''Write newly created planet variants to file'''
        for planet in planetVariants:
            filePath = path + planet.containingFile

            root = XMLReader().parseFile(filePath)
            if root is None:
                root = et.Element("Planets")

            planetRoot = et.SubElement(root, "Planet", Name=planet.name)
            self.subElementText(planetRoot, "Variant_Of_Existing_Type",
                                planet.variantOf)
            pos_text = str(planet.x) + ", " + str(planet.y) + ", 10.0"
            self.subElementText(planetRoot, "Galactic_Position", pos_text)
            self.writer(et.ElementTree(root), filePath)
Esempio n. 3
0
 def planetCoordinatesWriter(self, path, planetFilesRoots, newPlanetData):
     '''Save updated planet coordinates'''
     for file, root in planetFilesRoots.items():
         for element in root.iter("Planet"):
             name = str(element.get("Name"))
             try:
                 newData = newPlanetData[name]
                 for child in element.iter("Galactic_Position"):
                     outputList = XMLReader().commaSepListParser(child.text)
                     pos_text = str(newData[0]) + ", " + str(
                         newData[1]) + ", " + str(outputList[2])
                     child.text = pos_text
                     break
             except (KeyError):
                 pass
         root.write(path + file, xml_declaration="1.0", pretty_print=True)
Esempio n. 4
0
 def __init__(self):
     self.repository: GameObjectRepository = GameObjectRepository()
     self.__folder: str = ""
     self.__xml: XMLReader = XMLReader()