You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.3 KiB
JavaScript
82 lines
2.3 KiB
JavaScript
const fs = require('fs');
|
|
const child_process = require('node:child_process');
|
|
|
|
const base_dir = process.argv[2] + '/Screens/Online/ChatRoom/'
|
|
const js = fs.readFileSync(base_dir + 'ChatRoomMapView.js').
|
|
toString().replace(/^"use strict";/, '').
|
|
replaceAll(/const /g, 'var ');
|
|
eval(js);
|
|
|
|
const init_ts = (name) =>
|
|
{
|
|
return {
|
|
name,
|
|
tiles: [],
|
|
tilewidth: 100,
|
|
tileheight: 100,
|
|
};
|
|
};
|
|
|
|
const wall_object = { objects: [{
|
|
x: 0, y: 0, width: 100, height: 100,
|
|
}]};
|
|
|
|
const add_ts = (ts, base_in, id, type, style, ts_name) =>
|
|
{
|
|
const fn = `${base_in}/${type}/${style}.png`;
|
|
const out_name = `${type}_${style}.png`;
|
|
console.log(out_name);
|
|
fs.mkdirSync(`${__dirname}/../${ts_name}`, {recursive: true});
|
|
const out = `${__dirname}/../${ts_name}/${out_name}`;
|
|
child_process.execFileSync('convert', [fn, '-resize', '100x', out]);
|
|
|
|
// map types to something more sane/usable for us
|
|
if (type === 'Floor' || type == 'FloorExterior' || type === 'FloorDecoration' ||
|
|
type === 'FloorDecorationThemed' || type === 'FloorItem' ||
|
|
type === 'FloorObstacle')
|
|
type = 'floor';
|
|
else if (type === 'Wall' || type === 'WallDecoration')
|
|
type = 'wall';
|
|
else if (type === 'WallPath')
|
|
type = 'door';
|
|
else if (type === 'Water' || type === 'FloorDecorationParty' ||
|
|
type == 'FloorDecorationCamping')
|
|
type = 'misc'; // don't care
|
|
else
|
|
throw new Error(`TODO ${type}`);
|
|
|
|
let tile = {
|
|
id: id,
|
|
image: `${ts_name}/${out_name}`,
|
|
properties: [{name: 'type', type: 'string', value: type}],
|
|
};
|
|
if (ts.name === 'Tiles' && type === 'wall') tile.objectgroup = wall_object;
|
|
ts.tiles.push(tile);
|
|
};
|
|
|
|
const save_ts = (ts, fn) =>
|
|
{
|
|
ts.tilecount = ts.tiles.length;
|
|
fs.writeFileSync(fn, JSON.stringify(ts, null, 2));
|
|
}
|
|
|
|
const tile_ts = init_ts('Tiles');
|
|
for (let {ID, Type, Style} of ChatRoomMapViewTileList)
|
|
add_ts(tile_ts, `${base_dir}/MapTile`, ID, Type, Style, 'tileset_tile');
|
|
save_ts(tile_ts, `${__dirname}/../tileset_tile.tsj`);
|
|
|
|
const object_ts = init_ts('Objects');
|
|
const blanks = [];
|
|
for (let {ID, Type, Style} of ChatRoomMapViewObjectList)
|
|
{
|
|
if (Style === 'Blank')
|
|
{
|
|
blanks.push(ID);
|
|
continue;
|
|
}
|
|
add_ts(object_ts, `${base_dir}/MapObject`, ID, Type, Style, 'tileset_object');
|
|
}
|
|
save_ts(object_ts, `${__dirname}/../tileset_object.tsj`);
|
|
|
|
console.log(blanks);
|