smeargle: Add flag for outputting tilemaps in little-endian format.

current
Kiyoshi Aman 2018-10-23 13:05:51 -05:00
parent f5c726eb0b
commit 34c94318a5
3 changed files with 23 additions and 5 deletions

View File

@ -39,7 +39,8 @@ in each object or array.
"tile_offset": 256, // Optional: Constant to add to tile index (first tile: 0x0000 + 256 = 0x0100) "tile_offset": 256, // Optional: Constant to add to tile index (first tile: 0x0000 + 256 = 0x0100)
"raw_fn": "ex_raw.png", // Optional: Output filename for raw graphic tile data. "raw_fn": "ex_raw.png", // Optional: Output filename for raw graphic tile data.
"deduped_fn": "ex_comp.png", // Optional: Output filename for deduped tile data. "deduped_fn": "ex_comp.png", // Optional: Output filename for deduped tile data.
"tilemap_fn": "example.tbl" // Optional: Output filename for tilemap text. "tilemap_fn": "example.tbl", // Optional: Output filename for tilemap text.
"little_endian": false // Optional: Output tilemap in little-endian format.
} }
} }
} }

View File

@ -38,7 +38,8 @@ class Game:
'leading_zeroes': False, 'leading_zeroes': False,
'raw_fn': None, 'raw_fn': None,
'deduped_fn': None, 'deduped_fn': None,
'tilemap_fn': None 'tilemap_fn': None,
'little_endian': False,
} }
for script, data in self._data['scripts'].items(): for script, data in self._data['scripts'].items():

View File

@ -33,7 +33,8 @@ class Script:
'leading_zeroes': get_or_default(kwargs, 'leading_zeroes', False), 'leading_zeroes': get_or_default(kwargs, 'leading_zeroes', False),
'raw_fn': get_or_default(kwargs, 'raw_fn', None), 'raw_fn': get_or_default(kwargs, 'raw_fn', None),
'deduped_fn': get_or_default(kwargs, 'deduped_fn', None), 'deduped_fn': get_or_default(kwargs, 'deduped_fn', None),
'tilemap_fn': get_or_default(kwargs, 'tilemap_fn', None) 'tilemap_fn': get_or_default(kwargs, 'tilemap_fn', None),
'little_endian': get_or_default(kwargs, 'little_endian', False),
} }
mint = self._cfg['min_tiles'] mint = self._cfg['min_tiles']
maxt = self._cfg['max_tiles'] maxt = self._cfg['max_tiles']
@ -155,6 +156,10 @@ class Script:
upper_val = int(floor(index / 256)) upper_val = int(floor(index / 256))
lower_val = int(index % 256) lower_val = int(index % 256)
if upper_val > 0 or self.leading_zeroes is True: if upper_val > 0 or self.leading_zeroes is True:
if self._cfg['little_endian']:
temp = upper_val
upper_val = lower_val
lower_val = temp
map_idx[data] = "<${:02x}><${:02x}>".format(upper_val, lower_val) map_idx[data] = "<${:02x}><${:02x}>".format(upper_val, lower_val)
else: else:
map_idx[data] = "<${:02x}>".format(lower_val) map_idx[data] = "<${:02x}>".format(lower_val)
@ -163,12 +168,23 @@ class Script:
upper_val = int(floor(index / 256)) upper_val = int(floor(index / 256))
lower_val = int(index % 256) lower_val = int(index % 256)
if upper_val > 0 or self.leading_zeroes is True: if upper_val > 0 or self.leading_zeroes is True:
if self._cfg['little_endian']:
temp = upper_val
upper_val = lower_val
lower_val = temp
map_idx[data] = "{:02x}{:02x}".format(upper_val, lower_val) map_idx[data] = "{:02x}{:02x}".format(upper_val, lower_val)
else: else:
map_idx[data] = "{:02x}".format(lower_val) map_idx[data] = "{:02x}".format(lower_val)
else: else:
if self.leading_zeroes: index = unique + self.tile_offset
map_idx[data] = '0x{:04x}'.format(unique + self.tile_offset) upper_val = int(floor(index / 256))
lower_val = int(index % 256)
if upper_val > 0 or self.leading_zeroes is True:
if self._cfg['little_endian']:
temp = upper_val
upper_val = lower_val
lower_val = temp
map_idx[data] = '0x{:02x}{:02x}'.format(upper_val, lower_val)
else: else:
map_idx[data] = '0x{:02x}'.format(unique + self.tile_offset) map_idx[data] = '0x{:02x}'.format(unique + self.tile_offset)
unique += 1 unique += 1