forked from brachna/SpineConverter2.1.27
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfastConverter.py
66 lines (52 loc) · 2.37 KB
/
fastConverter.py
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
import sys, os
from spBinaryReader import spBinaryReader
from spJsonReader import spJsonReader
from spBinaryWriter import spBinaryWriter
from spJsonWriter import spJsonWriter
from settings import SpineConverterSettings
from dragonBonesFixer import DragonBonesFixer
import json
import re
import traceback
settings = SpineConverterSettings()
args = sys.argv[1:]
dragonBonesFixer = DragonBonesFixer(settings)
if len(args) == 0:
args = [settings.getFilePath()]
if args[0] == "" or not os.path.isfile(args[0]):
print("File path empty or file doesn't exist\n"+
"Edit \"filepath\" line in settings.json to choose a file\n"+
"To copy file path:\n"+
"Windows: right click on file while holding shift, press \"Copy as File\"\n"+
"Mac: while in right click menu hold down Option key, press \"Copy X as Pathname\"")
input("Press enter to close")
args = []
for arg in args:
try:
fileName = arg
if (fileName.endswith(".skel")):
print("Converting " + fileName.split("\\")[-1] + " into .json.")
binaryReader = spBinaryReader()
jsonWriter = spJsonWriter()
skeletonData = binaryReader.readSkeletonDataFile(fileName)
if (settings.isDumpSkelData()):
text = json.dumps(skeletonData, sort_keys=False, indent=2, separators=(",", ": "))
file = open('skelData.json', 'w')
file.write(text)
file.close()
skeletonData = dragonBonesFixer.fixSkeletonDataFromSkel(skeletonData, fileName)
jsonWriter.writeSkeletonDataFile(skeletonData, fileName.replace(".skel", ".json"))
dragonBonesFixer.fixSpineConverterJson(fileName.replace(".skel", ".json"))
elif (fileName.endswith(".json")):
print("Converting " + fileName.split("\\")[-1] + " into .skel.")
jsonReader = spJsonReader()
binaryWriter = spBinaryWriter()
fileName = dragonBonesFixer.fixDragonBonesJson(fileName)
skeletonData = jsonReader.readSkeletonDataFile(fileName)
binaryWriter.writeSkeletonDataFile(skeletonData, fileName.replace(".json", ".skel"))
else:
print("Invalid file type.")
input("Press enter to close")
except Exception:
traceback.print_exc()
input("Press enter to close")