Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit 73ebae7

Browse files
authored
Added automatic HashId support!
1 parent 8c78f26 commit 73ebae7

1 file changed

Lines changed: 68 additions & 24 deletions

File tree

Rails.py

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import clipboard
33
import math
44
import oead
5+
import zlib
6+
import os
57
#from tkinter import *
68
#from tkinter import ttk
79

810
# Set up points
9-
X = [1, 3, 2]
10-
Y = [1, 7, 15]
11-
Z = [1, 5, 4]
11+
X = [1.0, 3.0, 2.0]
12+
Y = [1.0, 7.0, 15.0]
13+
Z = [1.0, 5.0, 4.0]
1214

1315
# Set up HashID
1416
HashID = "0x0"
@@ -27,8 +29,9 @@
2729
# Set up CurrentPoint. This keeps track of what point you're editing in the GUI.
2830
CurrentPoint = 0
2931

30-
#Set up FilePath
32+
#Set up paths
3133
FilePath = ""
34+
FolderPath = ""
3235

3336

3437
#Set up window position
@@ -46,51 +49,90 @@ def InsertRail(Input, RailString):
4649
else:
4750
OutputText = Input + "Rails:" + "\n" + RailString
4851

49-
print(OutputText)
52+
#print(OutputText)
5053
#clipboard.copy(OutputText)
51-
print(RailString)
54+
#print(RailString)
5255
WriteToFile(OutputText)
53-
def ReadFromFile(RailString):
56+
def ReadFromFile(RailString, Continue, CurrentPath):
5457
#FilePath = top.PathEntry.get()
55-
with open(FilePath, 'rb') as InputFile:
58+
with open(CurrentPath, 'rb') as InputFile:
5659
ReadInputFile = InputFile.read()
5760
DeYaz0 = oead.yaz0.decompress(ReadInputFile)
5861
DeBYML = oead.byml.from_binary(DeYaz0)
5962
Output = oead.byml.to_text(DeBYML)
60-
61-
InsertRail(Output, RailString)
62-
with open("backup/backup.smubin", 'wb') as BackupFile:
63-
BackupFile.write(ReadInputFile)
63+
if (Continue == True):
64+
InsertRail(Output, RailString)
65+
with open("backup/backup.smubin", 'wb') as BackupFile:
66+
BackupFile.write(ReadInputFile)
67+
elif (Continue == False):
68+
return Output
6469

6570

6671
def CoreCalculation():
6772
#Grab all the needed variables
6873
global X
6974
global Y
7075
global Z
71-
global HashId
76+
global HashID
7277
global IsClosed
7378
global RailType
7479
global Translate
7580
global NextDistanceIndex
7681
global NextDistanceArray
7782
global CurrentPoint
7883
global FilePath
84+
global FolderPath
7985

86+
#Read DefaultPath and save it as FilePath
8087
with open("DefaultPath.txt", "r") as Path:
81-
FilePath = Path.read()
82-
83-
X[CurrentPoint] = int(top.XEntry.get())
84-
Y[CurrentPoint] = int(top.YEntry.get())
85-
Z[CurrentPoint] = int(top.ZEntry.get())
88+
FolderPath = Path.read()
89+
#Find new HashID
90+
HighestHashID = 0
91+
for i in os.listdir(FolderPath):
92+
if os.path.isfile(os.path.join(FolderPath,i)) and 'Dynamic' in i:
93+
FilePath = FolderPath + "//" + i
94+
LineList = ReadFromFile(None, False, FilePath).splitlines()
95+
HashIDReadCurrentLine = 0;
96+
for line in LineList:
97+
print("Line: " + line)
98+
if ("- HashId" in line):
99+
splitLine = line.split()
100+
CurrentHashID = int(splitLine[3], 0)
101+
if (CurrentHashID > HighestHashID):
102+
HighestHashID = CurrentHashID
103+
HashIDReadCurrentLine += 1;
104+
105+
for i in os.listdir(FolderPath):
106+
if os.path.isfile(os.path.join(FolderPath,i)) and 'Static' in i:
107+
FilePath = FolderPath + "//" + i
108+
LineList = ReadFromFile(None, False, FilePath).splitlines()
109+
HashIDReadCurrentLine = 0;
110+
for line in LineList:
111+
print("Line: " + line)
112+
if ("- HashId" in line):
113+
splitLine = line.split()
114+
CurrentHashID = int(splitLine[3], 0)
115+
if (CurrentHashID > HighestHashID):
116+
HighestHashID = CurrentHashID
117+
HashIDReadCurrentLine += 1;
118+
119+
print("HighestHashID: " + str(HighestHashID))
120+
HashID = str(HighestHashID + 1)
121+
print(HashID)
122+
123+
124+
X[CurrentPoint] = float(top.XEntry.get())
125+
Y[CurrentPoint] = float(top.YEntry.get())
126+
Z[CurrentPoint] = float(top.ZEntry.get())
86127

87128
NextDistanceIndexCounter = 0
88129
MidpointCounter = -1
89130
XSum = 0
90131
YSum = 0
91132
ZSum = 0
92133
# Set HashId
93-
HashID = top.HashIDEntry.get()
134+
if (top.HashIDEntry.get() != "Auto"):
135+
HashID = top.HashIDEntry.get()
94136
#Set IsClosed
95137
IsClosed = top.IsClosedDropdown.get()
96138
#Set RailType
@@ -129,7 +171,7 @@ def CoreCalculation():
129171
FinalString = (InitString + BodyString + EndString)
130172
clipboard.copy(FinalString)
131173
print(FinalString)
132-
ReadFromFile(FinalString)
174+
ReadFromFile(FinalString, True, FilePath)
133175

134176

135177

@@ -202,7 +244,8 @@ def NextPoint():
202244
print(Z)
203245
if (CurrentPoint < len(X)-1):
204246
CurrentPoint = CurrentPoint + 1
205-
HashID = top.HashIDEntry.get()
247+
if (top.HashIDEntry.get() != "Auto"):
248+
HashID = top.HashIDEntry.get()
206249
WindowX = root.winfo_x()
207250
WindowY = root.winfo_y()
208251
top = Toplevel1 (root)
@@ -229,7 +272,8 @@ def PrevPoint():
229272
print(Z)
230273
if (CurrentPoint > 0):
231274
CurrentPoint = CurrentPoint - 1
232-
HashID = top.HashIDEntry.get()
275+
if (top.HashIDEntry.get() != "Auto"):
276+
HashID = top.HashIDEntry.get()
233277
WindowX = root.winfo_x()
234278
WindowY = root.winfo_y()
235279
top = Toplevel1 (root)
@@ -347,7 +391,7 @@ def __init__(self, top=None):
347391
self.Button3.configure(highlightcolor="black")
348392
self.Button3.configure(pady="0")
349393
self.Button3.configure(relief="flat")
350-
self.Button3.configure(text='''Select File \n (to Modify)''')
394+
self.Button3.configure(text='''Select Folder \n (to Modify)''')
351395

352396
self.Button4 = tk.Button(top)
353397
self.Button4.place(relx=0.7750, rely=--0.7, height=135, width=135)
@@ -425,7 +469,7 @@ def __init__(self, top=None):
425469
self.HashIDEntry.configure(takefocus="")
426470
self.HashIDEntry.configure(cursor="xterm")
427471

428-
self.HashIDEntry.insert(0, HashID)
472+
self.HashIDEntry.insert(0, "Auto")
429473

430474

431475

0 commit comments

Comments
 (0)