Relative
This commit is contained in:
42
tools/assetstool/processtileset.py
Normal file
42
tools/assetstool/processtileset.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import sys, os
|
||||
import xml.etree.ElementTree as ET
|
||||
from assethelpers import getAssetRelativePath
|
||||
|
||||
def processTileset(assetPath):
|
||||
# Process the tileset file
|
||||
print(f"Processing tileset: {assetPath}")
|
||||
|
||||
# Load the tileset XML
|
||||
tree = ET.parse(assetPath)
|
||||
root = tree.getroot()
|
||||
|
||||
# Needs tilewidth, tileheight, tilecount and columns attributes
|
||||
if not all(attr in root.attrib for attr in ['tilewidth', 'tileheight', 'tilecount', 'columns']):
|
||||
print(f"Error: Tileset {assetPath} is missing required attributes.")
|
||||
return
|
||||
|
||||
tilewidth = int(root.attrib.get('tilewidth', 0))
|
||||
tileheight = int(root.attrib.get('tileheight', 0))
|
||||
tilecount = int(root.attrib.get('tilecount', 0))
|
||||
columns = int(root.attrib.get('columns', 0))
|
||||
|
||||
if tilewidth <= 0 or tileheight <= 0 or tilecount <= 0 or columns <= 0:
|
||||
print(f"Error: Tileset {assetPath} has invalid attribute values.")
|
||||
return
|
||||
|
||||
# Exactly one image element is required
|
||||
images = root.findall('image')
|
||||
if len(images) != 1:
|
||||
print(f"Error: Tileset {assetPath} must have exactly one image element.")
|
||||
return
|
||||
|
||||
image = images[0]
|
||||
if 'source' not in image.attrib:
|
||||
print(f"Error: Tileset {assetPath} is missing image source.")
|
||||
return
|
||||
|
||||
imageSource = image.attrib['source']
|
||||
|
||||
# Build
|
||||
relative = getAssetRelativePath(assetPath)
|
||||
print(f"Relative path: {relative}")
|
Reference in New Issue
Block a user