Skip to content

Commit 5c34855

Browse files
authored
Merge pull request #48 from nerochiaro/use_modules
Use modules
2 parents a8a8067 + f725267 commit 5c34855

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

export_to_godot_tilemap.js renamed to export_to_godot_tilemap.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getResPath, stringifyKeyValue, stringifyNode, splitCommaSeparated, getTilesetColumns } from './utils.mjs';
2+
13
/*global tiled, TextFile */
24
class GodotTilemapExporter {
35

export_to_godot_tileset.js renamed to export_to_godot_tileset.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getResPath, getTilesetColumns } from './utils.mjs';
2+
13
/*global tiled, TextFile */
24
class GodotTilesetExporter {
35

utils.js renamed to utils.mjs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*! (c) 2018, Andrea Giammarchi, (ISC) */
22
var Flatted=function(a,l){return{parse:function(n,t){var e=JSON.parse(n,i).map(f),r=e[0],u=t||s,c="object"==typeof r&&r?function u(c,f,n,i){return Object.keys(n).reduce(function(n,t){var e=n[t];if(e instanceof a){var r=c[e];"object"!=typeof r||f.has(r)?n[t]=i.call(n,t,r):(f.add(r),n[t]=i.call(n,t,u(c,f,r,i)))}else n[t]=i.call(n,t,e);return n},n)}(e,new Set,r,u):r;return u.call({"":c},"",c)},stringify:function(n,e,t){function r(n,t){if(u)return u=!u,t;var e=a.call(this,n,t);switch(typeof e){case"object":if(null===e)return e;case l:return c.get(e)||p(c,f,e)}return e}for(var u,c=new Map,f=[],i=[],a=e&&typeof e==typeof f?function(n,t){if(""===n||-1<e.indexOf(n))return t}:e||s,o=+p(c,f,a.call({"":n},"",n));o<f.length;o++)u=!0,i[o]=JSON.stringify(f[o],r,t);return"["+i.join(",")+"]"}};function s(n,t){return t}function p(n,t,e){var r=a(t.push(e)-1);return n.set(e,r),r}function f(n){return n instanceof a?a(n):n}function i(n,t){return typeof t==l?new a(t):t}}(String,"string");
33

4-
var log = console.log.bind(console);
4+
const log = console.log.bind(console);
55

6-
function logf(data) {
6+
export function logf(data) {
77
console.log(Flatted.stringify(data));
88
}
9-
function logk(data) {
9+
10+
export function logk(data) {
1011
console.log(Object.keys(data));
1112
}
1213

@@ -24,7 +25,7 @@ function logk(data) {
2425
* @param {string} outputPath full path and name of destination file. Ex: 'C:/project/maps/level1/tileset.tres'
2526
* @returns {string} full relative path to file to be included in a 'res://' path. Ex: 'maps/level1/tileset.tres'
2627
*/
27-
function getResPath(projectRoot, relativePath, outputPath) {
28+
export function getResPath(projectRoot, relativePath, outputPath) {
2829
let fullResPath = ''
2930
if (relativePath) {
3031
// Replace all backslashes with forward slashes
@@ -78,7 +79,7 @@ function getResPath(projectRoot, relativePath, outputPath) {
7879
* tile spacing (padding between individual tiles).
7980
* @returns {number}
8081
*/
81-
function getTilesetColumns(tileset) {
82+
export function getTilesetColumns(tileset) {
8283
// noinspection JSUnresolvedVariable
8384
const imageWidth = tileset.imageWidth + tileset.tileSpacing - tileset.margin
8485
const tileWidth = tileset.tileWidth + tileset.tileSpacing
@@ -91,7 +92,7 @@ function getTilesetColumns(tileset) {
9192
/**
9293
* @param {string} str comma separated items
9394
*/
94-
function splitCommaSeparated(str) {
95+
export function splitCommaSeparated(str) {
9596
if (!str) {
9697
return undefined;
9798
}
@@ -114,21 +115,21 @@ function splitCommaSeparated(str) {
114115
}
115116
* ```
116117
*/
117-
function stringifyNode(nodeProperties, contentProperties = {}, metaProperties = {}) {
118+
export function stringifyNode(nodeProperties, contentProperties = {}, metaProperties = {}) {
118119
let str = '\n';
119120
str += '[node';
120121
for (const [key, value] of Object.entries(nodeProperties)) {
121122
if (value !== undefined) {
122-
str += ' ' + this.stringifyKeyValue(key, value, false, true, false);
123+
str += ' ' + stringifyKeyValue(key, value, false, true, false);
123124
}
124125
}
125126
str += ']\n';
126127
for (const [key, value] of Object.entries(contentProperties)) {
127128
if (value !== undefined) {
128-
str += this.stringifyKeyValue(key, value, false, false, true) + '\n';
129+
str += stringifyKeyValue(key, value, false, false, true) + '\n';
129130
}
130131
}
131-
mProps = Object.entries(metaProperties)
132+
const mProps = Object.entries(metaProperties);
132133
if(mProps.length > 0) {
133134
str += '__meta__ = {\n';
134135
var count = 0;
@@ -140,7 +141,7 @@ function stringifyNode(nodeProperties, contentProperties = {}, metaProperties =
140141
if(typeof value === 'number' || typeof value === 'boolean') {
141142
quoteValue = false;
142143
}
143-
str += this.stringifyKeyValue(key, value, true, quoteValue, true, ":");
144+
str += stringifyKeyValue(key, value, true, quoteValue, true, ":");
144145
}
145146
str += '\n}\n';
146147
}
@@ -155,7 +156,7 @@ function stringifyNode(nodeProperties, contentProperties = {}, metaProperties =
155156
* @param {bool} quote
156157
* @param {bool} spaces
157158
*/
158-
function stringifyKeyValue(key, value, quoteKey, quoteValue, spaces, separator = "=") {
159+
export function stringifyKeyValue(key, value, quoteKey, quoteValue, spaces, separator = "=") {
159160
// flatten arrays
160161
if (Array.isArray(value)) {
161162
value = '[\n"' + value.join('","') + '",\n]';

0 commit comments

Comments
 (0)