-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtiled2riscos
executable file
·60 lines (51 loc) · 1.51 KB
/
tiled2riscos
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
#!/usr/bin/env python3
#
# © Reuben Thomas <[email protected]> 2024
# Released under the GPL version 3, or (at your option) any later version.
# /// script
# requires-python = ">=3.9"
# dependencies = ["pytmx"]
# ///
import argparse
import pytmx
# Command-line arguments
parser = argparse.ArgumentParser(
description="Convert Tiled WinColl levels to RISC OS plain text format.",
)
parser.add_argument(
"-V",
"--version",
action="version",
version="%(prog)s 0.34 (27 Dec 2024) by Reuben Thomas <[email protected]>",
)
parser.add_argument("tiled_file", metavar="TILED-MAP", help="Tiled map output file")
parser.add_argument(
"wincoll_file", metavar="WINCOLL-LEVEL", help="plain text WinColl level file"
)
args = parser.parse_args()
# Read the input and convert tile GIDs to text
tiled_map = pytmx.TiledMap(args.tiled_file)
gid_to_char = {
"wincoll/levels/Gap.png": " ",
"wincoll/levels/Brick.png": "#",
"wincoll/levels/Safe.png": "$",
"wincoll/levels/Diamond.png": "*",
"wincoll/levels/Blob.png": "+",
"wincoll/levels/Earth.png": ".",
"wincoll/levels/Rock.png": "@",
"wincoll/levels/Key.png": "K",
"wincoll/levels/Hero.png": "W",
}
lines = []
text = ""
for tile in tiled_map.layers[0].tiles():
text += gid_to_char[tile[2][0]]
# Convert tile string to lines and save it
output = (
"\n".join(
[text[i : i + tiled_map.width] for i in range(0, len(text), tiled_map.width)],
)
+ "\n"
)
with open(args.wincoll_file, "w", encoding="utf-8") as fh:
fh.write(output)