bc_tiled_plugin

Tiled plugin to edit Bondage Club maps
git clone https://git.neptards.moe/u3shit/bc_tiled_plugin.git
Log | Files | Refs | README | LICENSE

import.js (2507B)


      1 const fs = require('fs');
      2 const child_process = require('node:child_process');
      3 
      4 const base_dir = process.argv[2] + '/Screens/Online/ChatRoom/'
      5 const js = fs.readFileSync(base_dir + 'ChatRoomMapView.js').
      6       toString().replace(/^"use strict";/, '').
      7       replaceAll(/const /g, 'var ');
      8 eval(js);
      9 
     10 const init_ts = (name) =>
     11 {
     12   return {
     13     name,
     14     tiles: [],
     15     tilewidth: 100,
     16     tileheight: 100,
     17   };
     18 };
     19 
     20 const wall_object = { objects: [{
     21   x: 0, y: 0, width: 100, height: 100,
     22 }]};
     23 
     24 const add_ts = (ts, base_in, id, type, style, ts_name) =>
     25 {
     26   const fn = `${base_in}/${type}/${style}.png`;
     27   const out_name = `${type}_${style}.png`;
     28   console.log(out_name);
     29   fs.mkdirSync(`${__dirname}/../${ts_name}`, {recursive: true});
     30   const out = `${__dirname}/../${ts_name}/${out_name}`;
     31   child_process.execFileSync('convert', [fn, '-resize', '100x', out]);
     32 
     33   // map types to something more sane/usable for us
     34   if (type === 'Floor' || type == 'FloorExterior' || type === 'FloorDecoration' ||
     35       type === 'FloorDecorationThemed' || type == 'FloorDecorationParty' ||
     36       type === 'FloorDecorationCamping' || type == 'FloorDecorationExpanding' ||
     37       type === 'FloorItem' || type === 'FloorObstacle')
     38     type = 'floor';
     39   else if (type === 'Wall' || type === 'WallDecoration')
     40     type = 'wall';
     41   else if (type === 'WallPath')
     42     type = 'door';
     43   else if (type === 'Water' || type === 'FloorDecorationAnimal' ||
     44            type == 'FloorNumber' || type == 'FloorLetter' || type == 'FloorIcon')
     45     type = 'misc'; // don't care
     46   else
     47     throw new Error(`TODO ${type}`);
     48 
     49   let tile = {
     50     id: id,
     51     image: `${ts_name}/${out_name}`,
     52     properties: [{name: 'type', type: 'string', value: type}],
     53   };
     54   if (ts.name === 'Tiles' && type === 'wall') tile.objectgroup = wall_object;
     55   ts.tiles.push(tile);
     56 };
     57 
     58 const save_ts = (ts, fn) =>
     59 {
     60   ts.tilecount = ts.tiles.length;
     61   fs.writeFileSync(fn, JSON.stringify(ts, null, 2));
     62 }
     63 
     64 const tile_ts = init_ts('Tiles');
     65 for (let {ID, Type, Style} of ChatRoomMapViewTileList)
     66   add_ts(tile_ts, `${base_dir}/MapTile`, ID, Type, Style, 'tileset_tile');
     67 save_ts(tile_ts, `${__dirname}/../tileset_tile.tsj`);
     68 
     69 const object_ts = init_ts('Objects');
     70 const blanks = [];
     71 for (let {ID, Type, Style} of ChatRoomMapViewObjectList)
     72 {
     73   if (Style === 'Blank')
     74   {
     75     blanks.push(ID);
     76     continue;
     77   }
     78   add_ts(object_ts, `${base_dir}/MapObject`, ID, Type, Style, 'tileset_object');
     79 }
     80 save_ts(object_ts, `${__dirname}/../tileset_object.tsj`);
     81 
     82 console.log(blanks);