forked from PTSnoop/HoI4-to-Stellaris-Converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converter.py
101 lines (79 loc) · 3.58 KB
/
Converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python3
import os,sys,shutil
import naive_parser
import makeNameList
import flagconvert
import localisation
import universe
import events
import readConfig
import logToFile
class Converter:
def __init__(self, savefileName, hoi4path):
self.hoi4path = hoi4path
self.converterDir = os.path.dirname(os.path.realpath(__file__))
self.converterDir = self.converterDir.replace("\\","/") + "/"
print("Running from: "+self.converterDir)
print("Parsing save file...")
self.savefile = naive_parser.ParseSaveFile(savefileName)
print("Reading save data...")
self.parser = naive_parser.Parser(self.savefile, self.hoi4path)
print("Save file parsed.")
self.topNations = self.parser.getTopNations()
def ConvertEverything(self):
self.makeFolders()
self.getUniverse()
self.convertFlags()
self.convertNameLists()
self.convertLocalisation()
self.convertEvents()
def CopyMod(self, targetdir):
name = "outputMod"
shutil.rmtree(targetdir+name, True)
print("Copying '"+self.converterDir+name +"' to '"+targetdir+name+"'...")
shutil.copytree( self.converterDir+name, targetdir+name)
print("Copying '"+self.converterDir+name+".mod' to '",targetdir+name+".mod'...")
shutil.copyfile( self.converterDir+name+".mod", targetdir+name+".mod")
def makeFolders(self):
print("Laying out folder structure...")
shutil.rmtree(self.converterDir+"outputMod", True)
shutil.copytree(self.converterDir+"outputMod_base", self.converterDir+"outputMod")
def getUniverse(self):
print("Creating the universe...")
self.universe = universe.Universe(self.savefile,self.hoi4path)
print("Establishing history...")
self.universe.Load()
def convertFlags(self):
hoi4flagpath = self.hoi4path + "gfx/flags/"
for topNation in self.topNations:
print("Creating flag for "+topNation.tag+"...")
sourceFlagTga = hoi4flagpath + topNation.tag + "_" + topNation.government + ".tga"
destFlagFolder = "outputMod/flags/convertedflags/"
flagconvert.CompileFlag(sourceFlagTga,destFlagFolder)
def convertNameLists(self):
for topNation in self.topNations:
print("Creating name list for "+topNation.tag+"...")
destNameListFolder = "outputMod/common/name_lists/"
makeNameList.MakeNameList(topNation.tag, self.hoi4path, destNameListFolder)
def convertLocalisation(self):
print("Converting localisation...")
self.localiser = localisation.Localisation(self.savefile, self.hoi4path, self.parser, self.universe)
print("Writing localisation...")
self.localiser.writeLocalisation()
self.localiser.writeSyncedLocalisation()
def convertEvents(self):
print("Creating events...")
self.events = events.Events(self.savefile, self.hoi4path, self.parser, self.universe)
self.events.makeEvents()
if __name__ == "__main__":
print("BEGINNING CONVERSION")
#hoi4path = "D:/Steam/steamapps/common/Hearts of Iron IV/mod/Vannilla_Uruguay_End/"
config = readConfig.Config()
converter = Converter(config.savefile, config.hoi4path)
converter.ConvertEverything()
converter.CopyMod(config.targetdir)
print("ALL DONE!")
#hoi4path = "D:/Paradox Interactive/Hearts of Iron IV/mod/Vanilla_Uruguay_End/"
#savefileName = "Uruguay_1940_01_05_01.hoi4"
#converter = Converter(savefileName, hoi4path)
#converter.ConvertEverything()