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

Commit 3d9e422

Browse files
authored
Edit rail support (ish), some bugfixes.
1 parent 8822d6b commit 3d9e422

1 file changed

Lines changed: 178 additions & 32 deletions

File tree

Rails.py

Lines changed: 178 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
#from tkinter import ttk
99

1010
# Set up points
11-
X = [1.0, 3.0, 2.0]
12-
Y = [1.0, 7.0, 15.0]
13-
Z = [1.0, 5.0, 4.0]
11+
#X = [1.0, 3.0, 2.0]
12+
#Y = [1.0, 7.0, 15.0]
13+
#Z = [1.0, 5.0, 4.0]
14+
15+
16+
17+
X = [1.0]
18+
Y = [1.0]
19+
Z = [1.0]
1420

1521
# Set up HashID
1622
HashID = "Auto"
@@ -46,17 +52,40 @@
4652
paramDict = [{
4753
"IsAdjustPosAndDirToPoint": "false",
4854
"WaitASKeyName": "Search",
49-
"WaitFrame": "60.0"
55+
"WaitFrame": "60.0",
56+
"Rotate": "90.0"
5057
},
5158
{
5259
"IsAdjustPosAndDirToPoint": "false",
5360
"WaitASKeyName": "Search",
54-
"WaitFrame": "60.0"
61+
"WaitFrame": "60.0",
62+
"Rotate": "90.0"
5563
},
5664
{
5765
"IsAdjustPosAndDirToPoint": "false",
5866
"WaitASKeyName": "Search",
59-
"WaitFrame": "60.0"
67+
"WaitFrame": "60.0",
68+
"Rotate": "90.0"
69+
}]
70+
71+
72+
paramDictForTkinter = [{
73+
"IsAdjustPosAndDirToPoint": "false",
74+
"WaitASKeyName": "Search",
75+
"WaitFrame": "60.0",
76+
"Rotate": "90.0"
77+
},
78+
{
79+
"IsAdjustPosAndDirToPoint": "false",
80+
"WaitASKeyName": "Search",
81+
"WaitFrame": "60.0",
82+
"Rotate": "90.0"
83+
},
84+
{
85+
"IsAdjustPosAndDirToPoint": "false",
86+
"WaitASKeyName": "Search",
87+
"WaitFrame": "60.0",
88+
"Rotate": "90.0"
6089
}]
6190

6291

@@ -72,9 +101,17 @@ def WriteToFile(InputText):
72101

73102
#Define InsertRail - This takes the unedited static file text and injects the rail into it.
74103
#It then calls WriteToFile.
75-
def InsertRail(Input, RailString):
104+
def InsertRail(Input, RailString, hashId):
76105
if (Input.find("Rails: []") == -1):
77-
OutputText = Input + "\n" + RailString
106+
railStart = Input.find(f"- HashID: !u {hashId}")
107+
railEnd = Input.find(f"Guide", railStart)
108+
while (Input[railEnd+1] == "P"):
109+
railEnd = Input.find(f"Guide", railEnd)
110+
if (railStart == -1):
111+
OutputText = Input + "\n" + RailString
112+
else:
113+
Input = Input[0:railStart] + Input[railEnd:-1]
114+
Input = Input[:railStart] + RailString + Input[railStart:]
78115
else:
79116
OutputText = Input + "Rails:" + "\n" + RailString
80117

@@ -86,15 +123,15 @@ def InsertRail(Input, RailString):
86123
#Define ReadFromFile. This reads all the data in the file and stores it as a string.
87124
#It then calls InsertRail, only if Continue is passed into it as true.
88125
#This functionality is for when you don't want to continue through, and just want to read the file.
89-
def ReadFromFile(RailString, Continue, CurrentPath):
126+
def ReadFromFile(RailString, Continue, CurrentPath, hashId):
90127
#FilePath = top.PathEntry.get()
91128
with open(CurrentPath, 'rb') as InputFile:
92129
ReadInputFile = InputFile.read()
93130
DeYaz0 = oead.yaz0.decompress(ReadInputFile)
94131
DeBYML = oead.byml.from_binary(DeYaz0)
95132
Output = oead.byml.to_text(DeBYML)
96133
if (Continue == True):
97-
InsertRail(Output, RailString)
134+
InsertRail(Output, RailString, hashId)
98135
with open("backup/backup.smubin", 'wb') as BackupFile:
99136
BackupFile.write(ReadInputFile)
100137
elif (Continue == False):
@@ -134,7 +171,7 @@ def CoreCalculation(Continue):
134171
for i in os.listdir(FolderPath):
135172
if os.path.isfile(os.path.join(FolderPath,i)) and 'Dynamic' in i:
136173
FilePath = FolderPath + "//" + i
137-
LineList = ReadFromFile(None, False, FilePath).splitlines()
174+
LineList = ReadFromFile(None, False, FilePath, None).splitlines()
138175
HashIDReadCurrentLine = 0;
139176
for line in LineList:
140177
#print("Line: " + line)
@@ -148,7 +185,7 @@ def CoreCalculation(Continue):
148185
for i in os.listdir(FolderPath):
149186
if os.path.isfile(os.path.join(FolderPath,i)) and 'Static' in i:
150187
FilePath = FolderPath + "//" + i
151-
LineList = ReadFromFile(None, False, FilePath).splitlines()
188+
LineList = ReadFromFile(None, False, FilePath, None).splitlines()
152189
HashIDReadCurrentLine = 0;
153190
for line in LineList:
154191
#print("Line: " + line)
@@ -211,7 +248,7 @@ def CoreCalculation(Continue):
211248
print("yay")
212249
InitString = ("- HashId: !u " + HashID + "\n" + " IsClosed: " + str(IsClosed) + "\n" + " RailPoints:" + "\n" + f" - '!Parameters': {paramDict[0]}" + "\n" + " NextDistance: " + str(NextDistanceArray[0]) + "\n" + " PrevDistance: " + str(FirstLastDist) + "\n" + " Translate: " + "[" + str(X[0]) + ", " + str(Y[0]) + ", " + str(Z[0]) + "]" + "\n" + " UnitConfigName: GuidePoint")
213250
elif (IsClosed == "false"):
214-
InitString = ("- HashId: !u " + HashID + "\n" + " IsClosed: " + str(IsClosed) + "\n" + " RailPoints:" + "\n" + f" - '!Parameters': {paramDict[0]}" + "\n" + " NextDistance: " + str(NextDistanceArray[0]) + "\n" + " PrevDistance: " + str(NextDistanceArray[0]) + "\n" + " Translate: " + "[" + str(X[0]) + ", " + str(Y[0]) + ", " + str(Z[0]) + "]" + "\n" + " UnitConfigName: GuidePoint")
251+
InitString = ("- HashId: !u " + HashID + "\n" + " IsClosed: " + str(IsClosed) + "\n" + " RailPoints:" + "\n" + f" - '!Parameters': {paramDict[0]}" + "\n" + " NextDistance: " + str(NextDistanceArray[0]) + "\n" + " PrevDistance: " + "0.0" + "\n" + " Translate: " + "[" + str(X[0]) + ", " + str(Y[0]) + ", " + str(Z[0]) + "]" + "\n" + " UnitConfigName: GuidePoint")
215252
else:
216253
messagebox.showerror("You messed up.", "Please specify IsClosed! It can only be true or false.")
217254
print("Please specify IsClosed! It can only be true or false.")
@@ -231,7 +268,7 @@ def CoreCalculation(Continue):
231268
EndString = ("\n" + f" - '!Parameters': {paramDict[-1]}" + "\n" + " NextDistance: " + str(PrevDistance) + "\n" + " PrevDistance: " + str(PrevDistance) + "\n" + " Translate: " + "[" + str(X[-1]) + ", " + str(Y[-1]) + ", " + str(Z[-1]) + "]" + "\n" + " UnitConfigName: GuidePoint" + "\n" + " RailType: " + RailType + "\n" + " Translate: " + str(Translate) + "\n" + " UnitConfigName: Guide")
232269
FinalString = (InitString + BodyString + EndString)
233270
#print(FinalString)
234-
ReadFromFile(FinalString, Continue, FilePath)
271+
ReadFromFile(FinalString, Continue, FilePath, HashID)
235272

236273
def ClipboardCopy():
237274
global FinalString
@@ -318,21 +355,50 @@ def NextPoint():
318355

319356
try:
320357
if (optionsWindow.IsAdjustPosAndDirToPoint.get() == "No Entry"):
321-
del paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint']
358+
try:
359+
del paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint']
360+
except:
361+
print("Already no entry, continuing.")
322362
else:
323363
paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint'] = optionsWindow.IsAdjustPosAndDirToPoint.get()
324364

325365
if (optionsWindow.WaitASKeyName.get() == "No Entry"):
326-
del paramDict[CurrentPoint]['WaitASKeyName']
366+
try:
367+
del paramDict[CurrentPoint]['WaitASKeyName']
368+
except:
369+
print("Already no entry, continuing.")
327370
else:
328371
paramDict[CurrentPoint]['WaitASKeyName'] = optionsWindow.WaitASKeyName.get()
329372

330373
if (optionsWindow.WaitFrame.get() == "No Entry"):
331-
del paramDict[CurrentPoint]['WaitFrame']
374+
try:
375+
del paramDict[CurrentPoint]['WaitFrame']
376+
except:
377+
print("Already no entry, continuing.")
332378
else:
333379
paramDict[CurrentPoint]['WaitFrame'] = optionsWindow.WaitFrame.get()
380+
381+
if (optionsWindow.Rotate.get() == "No Entry"):
382+
try:
383+
del paramDict[CurrentPoint]['Rotate']
384+
except:
385+
print("Already no entry, continuing.")
386+
else:
387+
paramDict[CurrentPoint]['Rotate'] = optionsWindow.Rotate.get()
388+
except:
389+
print("Parameters not changed.")
390+
391+
392+
try:
393+
paramDictForTkinter[CurrentPoint]['IsAdjustPosAndDirToPoint'] = optionsWindow.IsAdjustPosAndDirToPoint.get()
394+
395+
paramDictForTkinter[CurrentPoint]['WaitASKeyName'] = optionsWindow.WaitASKeyName.get()
396+
397+
paramDictForTkinter[CurrentPoint]['WaitFrame'] = optionsWindow.WaitFrame.get()
398+
399+
paramDictForTkinter[CurrentPoint]['Rotate'] = optionsWindow.Rotate.get()
334400
except:
335-
print("You haven't set that value yet.")
401+
print("Parameters not changed.")
336402

337403
print(paramDict[CurrentPoint])
338404
#print(X)
@@ -376,26 +442,50 @@ def PrevPoint():
376442

377443
try:
378444
if (optionsWindow.IsAdjustPosAndDirToPoint.get() == "No Entry"):
379-
del paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint']
445+
try:
446+
del paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint']
447+
except:
448+
print("Already no entry, continuing.")
380449
else:
381450
paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint'] = optionsWindow.IsAdjustPosAndDirToPoint.get()
382451

383452
if (optionsWindow.WaitASKeyName.get() == "No Entry"):
384-
del paramDict[CurrentPoint]['WaitASKeyName']
453+
try:
454+
del paramDict[CurrentPoint]['WaitASKeyName']
455+
except:
456+
print("Already no entry, continuing.")
385457
else:
386458
paramDict[CurrentPoint]['WaitASKeyName'] = optionsWindow.WaitASKeyName.get()
387459

388460
if (optionsWindow.WaitFrame.get() == "No Entry"):
389-
del paramDict[CurrentPoint]['WaitFrame']
461+
try:
462+
del paramDict[CurrentPoint]['WaitFrame']
463+
except:
464+
print("Already no entry, continuing.")
390465
else:
391466
paramDict[CurrentPoint]['WaitFrame'] = optionsWindow.WaitFrame.get()
392467

393468
if (optionsWindow.Rotate.get() == "No Entry"):
394-
del paramDict[CurrentPoint]['Rotate']
469+
try:
470+
del paramDict[CurrentPoint]['Rotate']
471+
except:
472+
print("Already no entry, continuing.")
395473
else:
396474
paramDict[CurrentPoint]['Rotate'] = optionsWindow.Rotate.get()
397475
except:
398-
print("You haven't set that value yet.")
476+
print("Parameters not changed.")
477+
478+
479+
try:
480+
paramDictForTkinter[CurrentPoint]['IsAdjustPosAndDirToPoint'] = optionsWindow.IsAdjustPosAndDirToPoint.get()
481+
482+
paramDictForTkinter[CurrentPoint]['WaitASKeyName'] = optionsWindow.WaitASKeyName.get()
483+
484+
paramDictForTkinter[CurrentPoint]['WaitFrame'] = optionsWindow.WaitFrame.get()
485+
486+
paramDictForTkinter[CurrentPoint]['Rotate'] = optionsWindow.Rotate.get()
487+
except:
488+
print("Parameters not changed.")
399489

400490
print(paramDict[CurrentPoint])
401491
#print(X)
@@ -413,9 +503,10 @@ def AddPoint():
413503
global X
414504
global Y
415505
global Z
416-
X.append(0)
417-
Y.append(0)
418-
Z.append(0)
506+
global CurrentPoint
507+
X.append(X[CurrentPoint-1])
508+
Y.append(Y[CurrentPoint-1])
509+
Z.append(Z[CurrentPoint-1])
419510
paramDict.append({
420511
"IsAdjustPosAndDirToPoint": "false",
421512
"WaitASKeyName": "Search",
@@ -432,7 +523,7 @@ def RemovePoint():
432523
# This isn't needed for some reason.
433524
global root
434525

435-
if len(X) > 2:
526+
if len(X) > 1:
436527
if CurrentPoint >= len(X)-1:
437528
CurrentPoint = len(X)-2
438529
X.pop()
@@ -452,6 +543,59 @@ def EnterPath():
452543
top.PathEntry = filedialog.askdirectory()
453544
#top.PathEntry.place(relx=0.225, rely=--0.65, relheight=0.047, relwidth=0.165)
454545

546+
def on_paramClosing():
547+
global optionsRoot
548+
global CurrentPoint
549+
try:
550+
if (optionsWindow.IsAdjustPosAndDirToPoint.get() == "No Entry"):
551+
try:
552+
del paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint']
553+
except:
554+
print("Already no entry, continuing.")
555+
else:
556+
paramDict[CurrentPoint]['IsAdjustPosAndDirToPoint'] = optionsWindow.IsAdjustPosAndDirToPoint.get()
557+
558+
if (optionsWindow.WaitASKeyName.get() == "No Entry"):
559+
try:
560+
del paramDict[CurrentPoint]['WaitASKeyName']
561+
except:
562+
print("Already no entry, continuing.")
563+
else:
564+
paramDict[CurrentPoint]['WaitASKeyName'] = optionsWindow.WaitASKeyName.get()
565+
566+
if (optionsWindow.WaitFrame.get() == "No Entry"):
567+
try:
568+
del paramDict[CurrentPoint]['WaitFrame']
569+
except:
570+
print("Already no entry, continuing.")
571+
else:
572+
paramDict[CurrentPoint]['WaitFrame'] = optionsWindow.WaitFrame.get()
573+
574+
if (optionsWindow.Rotate.get() == "No Entry"):
575+
try:
576+
del paramDict[CurrentPoint]['Rotate']
577+
except:
578+
print("Already no entry, continuing.")
579+
else:
580+
paramDict[CurrentPoint]['Rotate'] = optionsWindow.Rotate.get()
581+
except:
582+
print("Parameters not changed.")
583+
584+
585+
try:
586+
paramDictForTkinter[CurrentPoint]['IsAdjustPosAndDirToPoint'] = optionsWindow.IsAdjustPosAndDirToPoint.get()
587+
588+
paramDictForTkinter[CurrentPoint]['WaitASKeyName'] = optionsWindow.WaitASKeyName.get()
589+
590+
paramDictForTkinter[CurrentPoint]['WaitFrame'] = optionsWindow.WaitFrame.get()
591+
592+
paramDictForTkinter[CurrentPoint]['Rotate'] = optionsWindow.Rotate.get()
593+
except:
594+
print("Parameters not changed.")
595+
596+
print(paramDict[CurrentPoint])
597+
optionsRoot.destroy()
598+
455599

456600

457601
def openOptionsWindow():
@@ -460,6 +604,7 @@ def openOptionsWindow():
460604
optionsRoot = tk.Tk()
461605
optionsRoot.iconbitmap('Rails.ico')
462606
optionsWindow = paramLevel(optionsRoot)
607+
optionsRoot.protocol("WM_DELETE_WINDOW", on_paramClosing)
463608

464609

465610

@@ -789,7 +934,7 @@ def __init__(self, top=None):
789934
self.IsAdjustPosAndDirToPointValueList = ['true','false', 'No Entry',]
790935
self.IsAdjustPosAndDirToPoint.configure(values=self.IsAdjustPosAndDirToPointValueList)
791936
self.IsAdjustPosAndDirToPoint.configure(takefocus="")
792-
self.IsAdjustPosAndDirToPoint.insert(0, "false")
937+
self.IsAdjustPosAndDirToPoint.insert(0, paramDictForTkinter[CurrentPoint]['IsAdjustPosAndDirToPoint'])
793938

794939

795940
self.WaitASKeyNameLabel = ttk.Label(top)
@@ -808,7 +953,7 @@ def __init__(self, top=None):
808953
self.WaitASKeyNameValueList = ['Search','No Entry',]
809954
self.WaitASKeyName.configure(values=self.WaitASKeyNameValueList)
810955
self.WaitASKeyName.configure(takefocus="")
811-
self.WaitASKeyName.insert(0, "Search")
956+
self.WaitASKeyName.insert(0, paramDictForTkinter[CurrentPoint]['WaitASKeyName'])
812957

813958

814959
self.WaitFrameLabel = ttk.Label(top)
@@ -825,9 +970,9 @@ def __init__(self, top=None):
825970
self.WaitFrame = ttk.Combobox(top)
826971
self.WaitFrame.place(relx=0.25, rely=--0.1, relheight=0.047, relwidth=0.165)
827972
self.WaitFrameValueList = ['60.0','No Entry',]
828-
self.WaitFrame.configure(values=self.WaitASKeyNameValueList)
973+
self.WaitFrame.configure(values=self.WaitFrameValueList)
829974
self.WaitFrame.configure(takefocus="")
830-
self.WaitFrame.insert(0, "60.0")
975+
self.WaitFrame.insert(0, paramDictForTkinter[CurrentPoint]['WaitFrame'])
831976

832977

833978
self.RotateLabel = ttk.Label(top)
@@ -846,7 +991,8 @@ def __init__(self, top=None):
846991
self.RotateValueList = ['90.0','No Entry',]
847992
self.Rotate.configure(values=self.RotateValueList)
848993
self.Rotate.configure(takefocus="")
849-
self.Rotate.insert(0, "90.0")
994+
self.Rotate.insert(0, paramDictForTkinter[CurrentPoint]['Rotate'])
995+
850996

851997
if __name__ == '__main__':
852998
vp_start_gui()

0 commit comments

Comments
 (0)