Add the gestion of tmx extension
This commit is contained in:
parent
2d62d5d8b2
commit
8ab815ffef
|
@ -1,14 +1,22 @@
|
|||
#! /usr/bin/env python3
|
||||
from sys import argv
|
||||
import xmltodict
|
||||
|
||||
|
||||
def convert_to_string(csv_filename):
|
||||
output_filename = csv_filename.split('.')[0]
|
||||
def convert_to_string(filename):
|
||||
output_filename, extension = filename.split('.')
|
||||
char_list = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "
|
||||
|
||||
with open(csv_filename, "r") as file:
|
||||
data = [[int(char_id) for char_id in line.split(",")] for line in file.read().splitlines()]
|
||||
with open(filename, "r") as file:
|
||||
data = file.read()
|
||||
|
||||
if extension == "tmx":
|
||||
data = xmltodict.parse(data)["map"]["layer"]["data"]["#text"].splitlines()
|
||||
data = [[int(char_id) - 1 for char_id in line.split(",") if char_id] for line in data]
|
||||
elif extension == "csv":
|
||||
data = data.splitlines()
|
||||
data = [[int(char_id) for char_id in line.split(",") if char_id] for line in data]
|
||||
|
||||
output = r""
|
||||
for line in data:
|
||||
for char_id in line:
|
||||
|
@ -16,6 +24,6 @@ def convert_to_string(csv_filename):
|
|||
output += "\n"
|
||||
|
||||
with open(f"{output_filename}.py", "w") as file:
|
||||
file.write(f"{output_filename}_map = r\"\"\"\n{output}\n\"\"\"")
|
||||
file.write(f"{output_filename} = (r\"\"\"\n{output[:-2]}\"\"\",\n)")
|
||||
|
||||
convert_to_string(*argv[1:])
|
Loading…
Reference in New Issue