-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrite_ship.py
More file actions
64 lines (53 loc) · 2.03 KB
/
write_ship.py
File metadata and controls
64 lines (53 loc) · 2.03 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
''' tool to write json data to a png file '''
import json
from PIL import Image
from cosmoteer_save_tools import Ship
# load generated json
GEN_JSON = "out.json"
with open(GEN_JSON, "r", encoding="utf-8") as f:
json_data = json.load(f)
# Convert lists to tuples in the JSON data
# thing to tuple
tuple_data = ["RoofBaseColor", "RoofDecalColor1", "RoofDecalColor2", "RoofDecalColor3"]
for key, value in json_data.items():
if key in tuple_data:
if isinstance(value, list):
json_data[key] = tuple(value)
if "Roles" in json_data:
for role in json_data["Roles"]:
if "Color" in role and isinstance(role["Color"], list):
role["Color"] = tuple(role["Color"])
if "WeaponShipRelativeTargets" in json_data:
for WeaponShipRelativeTargets in json_data["WeaponShipRelativeTargets"]:
if "Value" in WeaponShipRelativeTargets and isinstance(
WeaponShipRelativeTargets["Value"], list
):
WeaponShipRelativeTargets["Value"] = tuple(WeaponShipRelativeTargets["Value"])
# Now, json_data contains tuples instead of lists
# print(json_data)
ORG_IMG = "ionv2.ship.png" # Replace with the path to your image
my_ship1 = Ship(ORG_IMG) # read image
my_ship1.data = json_data # replace the data
new_image = my_ship1.write(Image.open("test99.png")) # write image
new_image.save("outtest.ship.png") # save image
my_ship2 = Ship("outtest.ship.png") # read image
print(my_ship1.data == my_ship2.data)
# print all of the differences
for key in my_ship1.data.keys():
if my_ship1.data[key] != my_ship2.data[key]:
print("ship 1")
print(key)
print(my_ship1.data[key])
print("===================================")
print("ship 2")
print(my_ship2.data[key])
print()
for key in my_ship1.data.keys():
if my_ship1.data[key] != json_data[key]:
print("ship 1")
print(key)
print(my_ship1.data[key])
print("===================================")
print("json data")
print(json_data[key])
print()