Skip to content

Commit

Permalink
add the tool into repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ToortelCactus committed Nov 29, 2024
1 parent c931ba4 commit de1e590
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/pythonis
Submodule pythonis added at 4d1bab
107 changes: 107 additions & 0 deletions tools/update_history_buildings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from pythonis.parser import parse_dir, to_file
from pythonis.tree import Node
from pythonis.tree import Tree

import os


#helper functions
def thisRegion(node: Node) -> str:
return '"' + node.parent.parent.getVal().split(':')[1] + '"'

def thisCountry(node: Node) -> str:
return '"c:' + node.parent.getVal().split(':')[1] + '"'

def thisTag(node: Node) -> str:
return node.parent.getVal().split(':')[1]


capitals = dict()

# walkers functions
def fetchCapitalStates(node: Node):
if node.raw == "capital":
capitals[node.parent.raw] = node.children[0].getVal()

def updateBuilding(node: Node):
if node.raw == "create_building":
child: Node = node.getChild("level")

if child is not None:
levels = child.children[0].getNum()

child.reset("add_ownership")
child.singleChild = False

# TODO: if something, decide / distribute

# workers only for now
b = child.addChild("building")
b.singleChild = False
b.addChild("type").addChild('"' + node.getChild("building").getSingleChildVal() + '"')
b.addChild("country").addChild(thisCountry(node))
b.addChild("levels").addChild(str(levels))
b.addChild("region").addChild(thisRegion(node))

return #DEBUG

# state owned
c = child.addChild("country")
c.singleChild = False
c.addChild("country").addChild(thisCountry(node))
c.addChild("levels").addChild(str(levels))

# workers
b = child.addChild("building")
b.singleChild = False
b.addChild("type").addChild('"' + node.getChild("building").getSingleChildVal() + '"')
b.addChild("country").addChild(thisCountry(node))
b.addChild("levels").addChild(str(levels))
b.addChild("region").addChild(thisRegion(node))

# private in capital "building_financial_district"
b = child.addChild("building")
b.singleChild = False
b.addChild("type").addChild('"building_financial_district"')
b.addChild("country").addChild(thisCountry(node))
b.addChild("levels").addChild(str(levels))
b.addChild("region").addChild('"' + capitals[thisTag(node)] + '"')

# local manor
b = child.addChild("building")
b.singleChild = False
b.addChild("type").addChild('"building_manor_house"')
b.addChild("country").addChild(thisCountry(node))
b.addChild("levels").addChild(str(levels))
b.addChild("region").addChild(thisRegion(node))

def removeOwnershipPMs(node: Node):
if node.raw == "activate_production_methods":
for child in node.children:
if "privately_own" in child.raw or \
"nt_guilds" in child.raw or \
"publicly_own" in child.raw or \
"government_ru" in child.raw or \
"worker_coop" in child.raw:
node.children.remove(child)
return

# get capitals loaded
if os.name == "nt":
country_trees = parse_dir("..\\common\\country_definitions\\")
else:
country_trees = parse_dir("../common/country_definitions/")
for tree in country_trees.values():
tree.walkTree(fetchCapitalStates)

# update the buildings
if os.name == "nt":
trees = parse_dir("..\\common\\history\\buildings\\")
else:
trees = parse_dir("../common/history/buildings/")
for tree in trees.values():
tree.walkTree(updateBuilding)

for file, tree in trees.items():
to_file(file.split("\\")[-1], tree)

0 comments on commit de1e590

Please sign in to comment.