Skip to content

Commit 913e29e

Browse files
authored
Merge pull request #10 from john-soklaski/master
Convert CCScriptWriter to Python 3
2 parents 660e8cc + ba43712 commit 913e29e

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

CCScriptWriter/CCScriptWriter.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import time
1212

1313
import yaml
14+
from functools import reduce
1415

1516

1617
#############
@@ -211,15 +212,15 @@ def loadDialogue(self, loadCoilSnake=False):
211212
try:
212213
with open(project) as f: pass
213214
except IOError:
214-
print("Failed to open \"{}\". Invalid CoilSnake project. "
215-
"Aborting.".format(project))
215+
print(("Failed to open \"{}\". Invalid CoilSnake project. "
216+
"Aborting.".format(project)))
216217
sys.exit(1)
217218
for fileName in COILSNAKE_FILES:
218219
csFile = open(os.path.join(o, fileName), "r")
219220
yamlData = yaml.load(csFile, Loader=yaml.CSafeLoader)
220221
csFile.close()
221222
if fileName != "map_doors.yml":
222-
for e, v in yamlData.iteritems():
223+
for e, v in yamlData.items():
223224
for p in COILSNAKE_POINTERS:
224225
if p in v:
225226
try:
@@ -231,8 +232,8 @@ def loadDialogue(self, loadCoilSnake=False):
231232
self.pointers.append(int(v[p][12:], 16))
232233
else:
233234
p = "Text Pointer"
234-
for e, v in yamlData.iteritems():
235-
for s, d in v.iteritems():
235+
for e, v in yamlData.items():
236+
for s, d in v.items():
236237
if not d: continue
237238
for k in d:
238239
if p in k:
@@ -255,7 +256,7 @@ def loadDialogue(self, loadCoilSnake=False):
255256

256257
# Add new blocks as needed by the pointers.
257258
print("Checking pointers...")
258-
pointers = filter(None, sorted(set(self.pointers)))
259+
pointers = [_f for _f in sorted(set(self.pointers)) if _f]
259260
self.pointers = []
260261
for address in self.dialogue:
261262
if address in pointers:
@@ -381,9 +382,9 @@ def outputDialogue(self, outputCoilSnake=False):
381382

382383
# Take care of the special pointers (both SNES and ASM type).
383384
m("\n\n// Special Pointers")
384-
for k, p in self.specialPointers.iteritems():
385+
for k, p in self.specialPointers.items():
385386
m("\nROM[{}] = \"{}\"".format(hex(k + 0xc00000), p))
386-
for k, p in self.asmPointers.iteritems():
387+
for k, p in self.asmPointers.items():
387388
if p[1] == 0:
388389
m("\n_asmptr({}, {})".format(hex(k + 0xc00000), p[0]))
389390
elif p[1] == 1:
@@ -403,7 +404,7 @@ def outputToCoilSnakeProject(self):
403404
csFile = open(os.path.join(o, fileName), "r")
404405
yamlData = yaml.load(csFile, Loader=yaml.CSafeLoader)
405406
if fileName != "map_doors.yml":
406-
for e, v in yamlData.iteritems():
407+
for e, v in yamlData.items():
407408
pointers = {}
408409
for p in COILSNAKE_POINTERS:
409410
if p in v:
@@ -415,13 +416,13 @@ def outputToCoilSnakeProject(self):
415416
pointers[p] = int(v[p][12:], 16)
416417
if not pointers:
417418
continue
418-
for k, v in pointers.iteritems():
419+
for k, v in pointers.items():
419420
f = self.dataFiles[v]
420421
yamlData[e][k] = "{}.l_{}".format(f, hex(v))
421422
else:
422423
p = "Text Pointer"
423-
for e, v in yamlData.iteritems():
424-
for s, d in v.iteritems():
424+
for e, v in yamlData.items():
425+
for s, d in v.items():
425426
if not d: continue
426427
for n, k in enumerate(d):
427428
pointers = {}
@@ -434,7 +435,7 @@ def outputToCoilSnakeProject(self):
434435
pointers[p] = int(k[p][12:], 16)
435436
if not pointers:
436437
continue
437-
for a, b in pointers.iteritems():
438+
for a, b in pointers.items():
438439
f = self.dataFiles[b]
439440
yamlData[e][s][n][a] = "{}.l_{}".format(f,
440441
hex(b))
@@ -741,7 +742,7 @@ def main():
741742
main.loadDialogue(args.coilsnake)
742743
main.processDialogue()
743744
main.outputDialogue(args.coilsnake)
744-
print("Complete. Time: {:.2f}s".format(float(time.time() - start)))
745+
print(("Complete. Time: {:.2f}s".format(float(time.time() - start))))
745746
except KeyboardInterrupt:
746747
print("\rProgram execution aborted.")
747748

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name="CCScriptWriter",
7-
version="1.1",
7+
version="1.2",
88
description="Extracts the dialogue from EarthBound and outputs it into a CCScript file.",
99
url="https://github.com/Lyrositor/CCScriptWriter",
1010
packages=find_packages(),

0 commit comments

Comments
 (0)