-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatting.py
More file actions
140 lines (116 loc) · 3.94 KB
/
Copy pathformatting.py
File metadata and controls
140 lines (116 loc) · 3.94 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from zon_object_types import *
import os
def is_float(value):
try:
float(value)
return True
except ValueError:
return False
def InterperetFormattingLine(Line):
# each zonThing is formatted like this
# .nameOfThing = typeOfThing,
currentState = "Tabs"
nameBuffer = ""
varBuffer = ""
isZon = False
for Character in Line:
if (Character != "}") or (Character != "{"): # zon detector
isZon = True
if currentState == "Tabs":
if Character != " ":
currentState = "ReadName"
if currentState == "ReadName":
if Character == " ":
currentState = "InbetweenVarRead"
else:
if (Character == "."): continue
nameBuffer = nameBuffer + Character
elif currentState == "InbetweenVarRead":
if (Character != " ") and (Character != "="):
currentState = "ReadVar"
if currentState == "ReadVar":
if Character == ",":
currentState = "EndValue"
break
else:
varBuffer = varBuffer + Character
# end of text processing
if nameBuffer == "},":
nameBuffer = ""
varBuffer = "},"
return nameBuffer, varBuffer, isZon
def readFormatZon(lineList, startingLine, parentZon):
lineNumber = startingLine
while lineNumber < len(lineList):
line = lineList[lineNumber]
varName, varType, isZon = InterperetFormattingLine(line)
if varType == ".{":
newZonObj = zonObject()
newZonObj.name = varName
lineNumber = readZonObject(lineList, lineNumber + 1, newZonObj)
parentZon.children.append(newZonObj)
else:
createChildBasedOnInfo(varName, varType, parentZon)
lineNumber += 1
def createChildBasedOnInfo(varName, varType, parentZon): # determines how to interperet the given format text
if (varType == ".tags") or (varType == "0xffffffff"):
newZonObj = zonArray()
newZonObj.name = varName
newZonObj.children = [varType]
parentZon.children.append(newZonObj)
elif (varType.isdecimal()) or (is_float(varType)) or (varType == "image.png") or (varType == ".tag") or (varType == "true") or (varType == "false") or (varType == "0x000000") or (varType == "cubyz:no_rotation"):
newZonObj = zonValue()
newZonObj.name = varName
newZonObj.value = varType
parentZon.children.append(newZonObj)
elif (varType == "modifiers"):
newZonObj = formatGroupZonMulti()
newZonObj.name = varName
newZonObj.formatGroup = createFormatGroup("formatting/modifier")
parentZon.children.append(newZonObj)
elif (varType == "item"):
newZonObj = zonObject()
newZonObj.name = varName
newZonObj.children = readFormatFile("formatting/base_types/item.txt").children
parentZon.children.append(newZonObj)
elif (varType == "},"):
return
elif (varType == "recipies"):
newZonObj = recipieZon()
parentZon.children.append(newZonObj)
else:
print("Formatter Read Error: could not interperet the varType: " + str(varType))
def readZonObject(lineList, startingLine, parentZon):
lineNumber = startingLine
while lineNumber < len(lineList):
line = lineList[lineNumber]
varName, varType, isZon = InterperetFormattingLine(line)
if varType == "{":
newZonObj = zonObject()
newZonObj.name = varName
lineNumber = readZonObject(lineList, startingLine, newZonObj)
parentZon.children.append(newZonObj)
else:
createChildBasedOnInfo(varName, varType, parentZon)
lineNumber += 1
if varName == "},":
break
return lineNumber #this is so it continues after its done building a zonoObject
def readFormatFile(filePath): # returns the format file in a code readable way
documentLines = []
CurrentZonObject = baseZonObject()
CurrentZonObject.children = [] # i really dont understand why we have to clear this
with open(filePath, "r") as file:
while True:
line = file.readline()
if not line:
break
documentLines.append(line.strip())
readFormatZon(documentLines, 0, CurrentZonObject)
return CurrentZonObject
def createFormatGroup(filePath):
specificFormatList = []
for name in os.listdir(filePath):
specificFormatList.append(filePath + "/" + name)
return specificFormatList
print("imported formatting.py")