1
1
/*! (c) 2018, Andrea Giammarchi, (ISC) */
2
2
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" ) ;
3
3
4
- var log = console . log . bind ( console ) ;
4
+ const log = console . log . bind ( console ) ;
5
5
6
- function logf ( data ) {
6
+ export function logf ( data ) {
7
7
console . log ( Flatted . stringify ( data ) ) ;
8
8
}
9
- function logk ( data ) {
9
+
10
+ export function logk ( data ) {
10
11
console . log ( Object . keys ( data ) ) ;
11
12
}
12
13
@@ -24,7 +25,7 @@ function logk(data) {
24
25
* @param {string } outputPath full path and name of destination file. Ex: 'C:/project/maps/level1/tileset.tres'
25
26
* @returns {string } full relative path to file to be included in a 'res://' path. Ex: 'maps/level1/tileset.tres'
26
27
*/
27
- function getResPath ( projectRoot , relativePath , outputPath ) {
28
+ export function getResPath ( projectRoot , relativePath , outputPath ) {
28
29
let fullResPath = ''
29
30
if ( relativePath ) {
30
31
// Replace all backslashes with forward slashes
@@ -78,7 +79,7 @@ function getResPath(projectRoot, relativePath, outputPath) {
78
79
* tile spacing (padding between individual tiles).
79
80
* @returns {number }
80
81
*/
81
- function getTilesetColumns ( tileset ) {
82
+ export function getTilesetColumns ( tileset ) {
82
83
// noinspection JSUnresolvedVariable
83
84
const imageWidth = tileset . imageWidth + tileset . tileSpacing - tileset . margin
84
85
const tileWidth = tileset . tileWidth + tileset . tileSpacing
@@ -91,7 +92,7 @@ function getTilesetColumns(tileset) {
91
92
/**
92
93
* @param {string } str comma separated items
93
94
*/
94
- function splitCommaSeparated ( str ) {
95
+ export function splitCommaSeparated ( str ) {
95
96
if ( ! str ) {
96
97
return undefined ;
97
98
}
@@ -114,21 +115,21 @@ function splitCommaSeparated(str) {
114
115
}
115
116
* ```
116
117
*/
117
- function stringifyNode ( nodeProperties , contentProperties = { } , metaProperties = { } ) {
118
+ export function stringifyNode ( nodeProperties , contentProperties = { } , metaProperties = { } ) {
118
119
let str = '\n' ;
119
120
str += '[node' ;
120
121
for ( const [ key , value ] of Object . entries ( nodeProperties ) ) {
121
122
if ( value !== undefined ) {
122
- str += ' ' + this . stringifyKeyValue ( key , value , false , true , false ) ;
123
+ str += ' ' + stringifyKeyValue ( key , value , false , true , false ) ;
123
124
}
124
125
}
125
126
str += ']\n' ;
126
127
for ( const [ key , value ] of Object . entries ( contentProperties ) ) {
127
128
if ( value !== undefined ) {
128
- str += this . stringifyKeyValue ( key , value , false , false , true ) + '\n' ;
129
+ str += stringifyKeyValue ( key , value , false , false , true ) + '\n' ;
129
130
}
130
131
}
131
- mProps = Object . entries ( metaProperties )
132
+ const mProps = Object . entries ( metaProperties ) ;
132
133
if ( mProps . length > 0 ) {
133
134
str += '__meta__ = {\n' ;
134
135
var count = 0 ;
@@ -140,7 +141,7 @@ function stringifyNode(nodeProperties, contentProperties = {}, metaProperties =
140
141
if ( typeof value === 'number' || typeof value === 'boolean' ) {
141
142
quoteValue = false ;
142
143
}
143
- str += this . stringifyKeyValue ( key , value , true , quoteValue , true , ":" ) ;
144
+ str += stringifyKeyValue ( key , value , true , quoteValue , true , ":" ) ;
144
145
}
145
146
str += '\n}\n' ;
146
147
}
@@ -155,7 +156,7 @@ function stringifyNode(nodeProperties, contentProperties = {}, metaProperties =
155
156
* @param {bool } quote
156
157
* @param {bool } spaces
157
158
*/
158
- function stringifyKeyValue ( key , value , quoteKey , quoteValue , spaces , separator = "=" ) {
159
+ export function stringifyKeyValue ( key , value , quoteKey , quoteValue , spaces , separator = "=" ) {
159
160
// flatten arrays
160
161
if ( Array . isArray ( value ) ) {
161
162
value = '[\n"' + value . join ( '","' ) + '",\n]' ;
0 commit comments