[TOOL] Copy Universe Aesthetics (BG, Sun, Planet)

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
User avatar
Jack08
Posts: 2971
Joined: Sun, 25. Dec 05, 11:42

[TOOL] Copy Universe Aesthetics (BG, Sun, Planet)

Post by Jack08 » Fri, 16. Dec 11, 18:11

To Copy all background, sun and planet data from one universe file to another universe file, follow these instructions:
  • Step1: Install Python 2.7 from http://www.python.org (do not use 3.x)
  • Step2: Create a new folder anwhere on your computer and name it anything you like
  • Step3: Create the following file: "CopyAesthetics.py" and copy and paste the script below into this file
  • Step4: Extract and place the Universe XML witch holds the visual data you want to copy in the same folder as the python script and name it "x3_universe_source.xml"
  • Step5: Extract the Universe XML witch you would like to input visual data to and place it in the same fodler as the python script and name it "x3_universe_target.xml"
  • Step6: Execute(Double Click) the script, A "x3_universe_output.xml" file should be created
  • Step7: Rename the "x3_universe_output.xml" file to "x3_universe.xml"
  • Step8: ???
  • Step9: Profffffit!
Provided without warranty.

CopyAesthetics.py:

Code: Select all

#Written by Jack08
SourceXML = open("x3_universe_source.xml", "r")

def ExtractElement(Element, Data):
    Element = Element+"="
    A = Data.split(Element)
    if len(A) > 1:
        A=A[1]
        A=A.split('"')[1]
        return A
    return False


def IsTypeNonF(Type, Data):
    Chk = ExtractElement("t", Data)
    if Chk == False or Chk != str(Type) or ExtractElement("f", Data)!=False:
        return False
    return Chk

def IsType(Type, Data):
    Chk = ExtractElement("t", Data)
    if Chk == False or Chk != str(Type):
        return False
    return Chk

def IsSector(Data):
    return IsType(1, Data)

def IsSun(Data):
    return IsTypeNonF(3, Data)

def IsBackground(Data):
    return IsType(2, Data)

def IsPlanet(Data):
    return IsType(4, Data)

Data = SourceXML.readline()
Sectors = []
cSector = []

while Data != '':
    if(IsSector(Data)):
        if len(cSector):
            Sectors.append(cSector)
        cSector = []
        A=Data
        cSector.append([int(ExtractElement("x", Data)), int(ExtractElement("y", Data))])    
    if(IsBackground(Data) or IsSun(Data) or IsPlanet(Data)):
        cSector.append(Data)
    Data = SourceXML.readline()

SourceXML.close()



XML_OUT = []
Target = open("x3_universe_target.xml", "r")
Data = Target.readline()

Enable = False

while Data != '':
    if(IsSector(Data)):
        XML_OUT.append(Data)
        CoOrd = [int(ExtractElement("x", Data)), int(ExtractElement("y", Data))]
        for Entry in Sectors:
            if CoOrd in Entry:
                for NewData in Entry:
                    if type(NewData) == str:
                        XML_OUT.append(NewData)
                Enable = True
                break
            else:
                Enable = False
        Data = Target.readline()
        continue

    if((IsBackground(Data) or IsSun(Data) or IsPlanet(Data)) and Enable):
        Data = Target.readline()
        continue

    XML_OUT.append(Data)
    Data = Target.readline()
    
Target.close()

Output = open("x3_universe_output.xml", "w")
for Element in XML_OUT:
    Output.write(Element)
Output.close()


Image
"One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible."
―Farengar Secret-Fire

User avatar
Ketraar
Moderator (DevNet)
Moderator (DevNet)
Posts: 8725
Joined: Fri, 21. May 04, 17:15

Post by Ketraar » Fri, 16. Dec 11, 20:32

Mind that in AP some objects are placed by x3universe_war.xml.

Just heads up ;-)

MFG

Ketraar

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”