-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathriscos2tiled
More file actions
executable file
·57 lines (48 loc) · 1.59 KB
/
riscos2tiled
File metadata and controls
executable file
·57 lines (48 loc) · 1.59 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
#!/usr/bin/env python3
#
# © Reuben Thomas <rrt@sc3d.org> 2024
# Released under the GPL version 3, or (at your option) any later version.
# /// script
# requires-python = ">=3.9"
# dependencies = ["tmxlib"]
# ///
import argparse
import math
import tmxlib as tmx
# Command-line arguments
parser = argparse.ArgumentParser(
description="Convert plain text WinColl levels to Tiled .tmx format.",
)
parser.add_argument("-V", "--version", action="version",
version="%(prog)s 0.2 (07 Dec 2024) by Reuben Thomas <rrt@sc3d.org>")
parser.add_argument("wincoll_file", metavar="WINCOLL-LEVEL", help="plain text WinColl level file")
parser.add_argument("tiled_file", metavar="TILED-MAP", help="Tiled map output file")
args = parser.parse_args()
# Read the input and convert tile encoding
def convert(row: list[str]) -> list[int]:
char_to_num = {
" ": 10,
"#": 11,
"$": 12,
"*": 13,
"+": 14,
".": 15,
"@": 16,
"K": 17,
"W": 18,
}
return list(map(lambda c: char_to_num[c], row))
wincoll_data = []
with open(args.wincoll_file, encoding="utf-8") as fh:
for line in fh.readlines():
wincoll_data += convert(list(line.strip("\n")))
# Construct the output map and save it
tilesize = 16
mapsize = int(math.sqrt(len(wincoll_data)))
tilemap = tmx.Map((mapsize, mapsize), (tilesize, tilesize))
tilemap.tilesets = [
tmx.ImageTileset("WinColl", (tilesize, tilesize), 1, source="WinColl.tsx")]
tilemap.layers = [
tmx.layer.TileLayer(tilemap, "Tile Layer 1", data=wincoll_data),
]
tilemap.save(args.tiled_file)