Skip to content

Commit 4770e24

Browse files
committed
feat(aiv): add inverty and skipkeep format options
1 parent 63647f7 commit 4770e24

3 files changed

Lines changed: 31 additions & 13 deletions

File tree

sourcehold/tool/convert/aiv/__init__.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,53 @@ def convert_aiv(args):
1515
inp = args.input
1616
if not pathlib.Path(inp).exists():
1717
raise Exception(f"file does not exist: {inp}")
18-
18+
inp_invert_y = False
1919
inp_format = args.from_format
2020
if not inp_format:
21-
if inp.endswith(".aiv"):
22-
inp_format = 'aiv'
23-
elif inp.endswith(".json"):
24-
inp_format = "json"
21+
if inp.endswith(".aiv"):
22+
inp_format = 'aiv'
23+
elif inp.endswith(".json"):
24+
inp_format = "json"
25+
inp_invert_y = True
26+
else:
27+
inp_format_tokens = inp_format.split(",")
28+
if 'inverty' in inp_format_tokens:
29+
inp_invert_y = True
30+
31+
out_invert_y = False
32+
out_skip_keep = False
2533
out_format = args.to_format
2634
if not out_format:
2735
if inp_format == "aiv":
2836
out_format = "json"
37+
out_invert_y = True
2938
elif inp_format == "json":
3039
out_format = "aiv"
40+
else:
41+
out_format_tokens = out_format.split(",")
42+
if 'inverty' in out_format_tokens:
43+
out_invert_y = True
44+
if 'skipkeep' in out_format_tokens:
45+
out_skip_keep = True
3146
if args.output == None:
3247
if out_format == "json":
3348
args.output = "-"
3449
elif out_format == "aiv":
3550
args.output = f"{pathlib.Path(inp).name}.aiv"
3651
#args.output = f"{pathlib.Path(inp).name}.json"
37-
52+
3853
if args.debug:
39-
print(f"converting '{inp_format}' file '{inp}' to '{out_format}' file '{args.output}'")
40-
if inp_format == 'aiv' and out_format == "json":
41-
conv = to_json(path = inp, include_extra=args.extra, report=args.debug)
54+
print(f"converting '{inp_format}: inverty={inp_invert_y}' file '{inp}' to '{out_format}: inverty={out_invert_y}' file '{args.output}'")
55+
56+
if inp_format.startswith('aiv') and out_format.startswith("json"):
57+
58+
conv = to_json(path = inp, include_extra=args.extra, report=args.debug, invert_y=out_invert_y, skip_keep=out_skip_keep)
4259
if args.output == "-":
4360
print(conv)
4461
else:
4562
pathlib.Path(args.output).write_text(conv)
46-
elif inp_format == "json" and out_format == "aiv":
47-
conv = from_json(path = inp, report=args.debug)
63+
elif inp_format.startswith('json') and out_format.startswith("aiv"):
64+
conv = from_json(path = inp, report=args.debug, invert_y=inp_invert_y)
4865
conv.to_file(args.output)
4966
else:
5067
raise NotImplementedError(f"combination of in-format '{inp_format}' and out-format '{out_format}' not implemented")

sourcehold/tool/convert/aiv/exports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323

24-
def to_json(aiv=None, path: str='', include_extra=False, invert_y=True, report=False):
24+
def to_json(aiv=None, path: str='', include_extra=False, invert_y=True, skip_keep=False, report=False):
2525
if aiv == None and not path:
2626
raise Exception()
2727
if aiv == None:
@@ -91,7 +91,7 @@ def to_json(aiv=None, path: str='', include_extra=False, invert_y=True, report=F
9191
processed[offset] = True
9292
continue
9393

94-
elif construction == 38: #keep2
94+
elif skip_keep and construction == 38: #keep2
9595
processed[offset] = True
9696
continue
9797

sourcehold/tool/convert/aiv/info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ def convertMapperEnumToAIVEnum(k=None, v=None):
659659
"MAPPER_HOVEL" : 4, # 0x36
660660
"MAPPER_OXENBASE" : 2, # 0x37
661661
"MAPPER_QUARRY" : 6, # 0x38
662+
"MAPPER_KEEP2" : 7, # 0x3d
662663
"MAPPER_STABLES" : 6, # 0x41
663664
"MAPPER_WHEATFARM" : 9, # 0x46
664665
"MAPPER_HOPSFARM" : 9, # 0x47

0 commit comments

Comments
 (0)