@canvasengine/tiled 2.0.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/Gid.d.ts +13 -0
- package/dist/classes/Layer.d.ts +26 -0
- package/dist/classes/Map.d.ts +232 -0
- package/dist/classes/Object.d.ts +8 -0
- package/dist/classes/Properties.d.ts +11 -0
- package/dist/classes/Tile.d.ts +19 -0
- package/dist/classes/Tileset.d.ts +13 -0
- package/dist/generate/tileset.d.ts +11 -0
- package/dist/generate/wangtile.d.ts +21 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +6205 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/open-file.d.ts +24 -0
- package/dist/parser/parser.d.ts +27 -0
- package/dist/types/Layer.d.ts +116 -0
- package/dist/types/Map.d.ts +72 -0
- package/dist/types/Objects.d.ts +57 -0
- package/dist/types/Text.d.ts +47 -0
- package/dist/types/Tile.d.ts +17 -0
- package/dist/types/Tileset.d.ts +92 -0
- package/dist/types/Types.d.ts +147 -0
- package/dist/types/WorldMaps.d.ts +12 -0
- package/dist/utils.d.ts +10 -0
- package/package.json +31 -0
- package/readme.md +1 -0
- package/src/classes/Gid.ts +46 -0
- package/src/classes/Layer.ts +135 -0
- package/src/classes/Map.ts +443 -0
- package/src/classes/Object.ts +16 -0
- package/src/classes/Properties.ts +30 -0
- package/src/classes/Tile.ts +22 -0
- package/src/classes/Tileset.ts +34 -0
- package/src/generate/tileset.ts +35 -0
- package/src/generate/wangtile.ts +166 -0
- package/src/index.ts +16 -0
- package/src/parser/open-file.ts +155 -0
- package/src/parser/parser.ts +309 -0
- package/src/types/Layer.ts +127 -0
- package/src/types/Map.ts +83 -0
- package/src/types/Objects.ts +64 -0
- package/src/types/Text.ts +47 -0
- package/src/types/Tile.ts +19 -0
- package/src/types/Tileset.ts +99 -0
- package/src/types/Types.ts +157 -0
- package/src/types/WorldMaps.ts +13 -0
- package/src/utils.ts +22 -0
- package/tests/class.spec.ts +88 -0
- package/tests/data.ts +5440 -0
- package/tests/parser.spec.ts +112 -0
- package/tests/tile-properties.spec.ts +99 -0
- package/tests/tiledmap-multi-layers.spec.ts +99 -0
- package/tests/tiledmap.spec.ts +223 -0
- package/tsconfig.json +28 -0
- package/vite.config.ts +21 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TiledMap } from '../types/Map';
|
|
2
|
+
type ParseOptions = {
|
|
3
|
+
getOnlyBasename?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare class TiledParserFile {
|
|
6
|
+
private file;
|
|
7
|
+
private basePath;
|
|
8
|
+
constructor(file: string, { basePath, staticDir, relativePath }?: {
|
|
9
|
+
basePath?: string | undefined;
|
|
10
|
+
staticDir?: string | undefined;
|
|
11
|
+
relativePath?: string | undefined;
|
|
12
|
+
});
|
|
13
|
+
static isBrowser(): boolean;
|
|
14
|
+
static typeOfFile(file: string): {
|
|
15
|
+
isXml: boolean;
|
|
16
|
+
isObject: boolean;
|
|
17
|
+
isHttp: boolean;
|
|
18
|
+
isPath: boolean;
|
|
19
|
+
};
|
|
20
|
+
private _parseFile;
|
|
21
|
+
parseFile(cb: Function, options?: ParseOptions): void;
|
|
22
|
+
parseFilePromise(options?: ParseOptions): Promise<TiledMap>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TiledMap } from '../types/Map';
|
|
2
|
+
import { TiledTileset } from '../types/Tileset';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
export declare class TiledParser {
|
|
5
|
+
private xml;
|
|
6
|
+
private filePath;
|
|
7
|
+
private basePath;
|
|
8
|
+
private layers;
|
|
9
|
+
constructor(xml: string, filePath?: string, basePath?: string);
|
|
10
|
+
static propToNumber: (obj: any, props: string[]) => any;
|
|
11
|
+
static propToBool: (obj: any, props: string[]) => any;
|
|
12
|
+
static toArray<T>(prop: any): T[];
|
|
13
|
+
getImagePath(image: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Check if the object is a tileset source reference
|
|
16
|
+
* Tileset sources should not have their paths transformed with getImagePath
|
|
17
|
+
*/
|
|
18
|
+
private isTilesetSource;
|
|
19
|
+
transform: (obj: any) => any;
|
|
20
|
+
static unpackTileBytes(buffer: Buffer, size: number): number[] | never;
|
|
21
|
+
static decode(obj: {
|
|
22
|
+
encoding: string;
|
|
23
|
+
data: string;
|
|
24
|
+
}, size: number): string | number[];
|
|
25
|
+
parseMap(): TiledMap;
|
|
26
|
+
parseTileset(): TiledTileset;
|
|
27
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { TiledObject } from './Objects';
|
|
2
|
+
import { TiledChunk, TiledCompression, TiledEncoding, TiledImage } from './Types';
|
|
3
|
+
export declare enum TiledLayerType {
|
|
4
|
+
Tile = "tilelayer",
|
|
5
|
+
ObjectGroup = "objectgroup",
|
|
6
|
+
Image = "imagelayer",
|
|
7
|
+
Group = "group"
|
|
8
|
+
}
|
|
9
|
+
export interface TiledLayer {
|
|
10
|
+
/**
|
|
11
|
+
* Incremental ID - unique across all layers
|
|
12
|
+
*/
|
|
13
|
+
id: number;
|
|
14
|
+
/**
|
|
15
|
+
* Image used by this layer. imagelayer only.
|
|
16
|
+
*/
|
|
17
|
+
image: TiledImage;
|
|
18
|
+
/**
|
|
19
|
+
* Array of unsigned int (GIDs) or base64-encoded data. tilelayer only.
|
|
20
|
+
*/
|
|
21
|
+
data: number[] | string;
|
|
22
|
+
/**
|
|
23
|
+
* Array of chunks (optional). tilelayer only.
|
|
24
|
+
*/
|
|
25
|
+
chunks: TiledChunk[];
|
|
26
|
+
/**
|
|
27
|
+
* Column count. Same as map width for fixed-size maps.
|
|
28
|
+
*/
|
|
29
|
+
width: number;
|
|
30
|
+
/**
|
|
31
|
+
* Row count. Same as map height for fixed-size maps.
|
|
32
|
+
*/
|
|
33
|
+
height: number;
|
|
34
|
+
/**
|
|
35
|
+
* Name assigned to this layer
|
|
36
|
+
*/
|
|
37
|
+
name: string;
|
|
38
|
+
/**
|
|
39
|
+
* From [0, 1]
|
|
40
|
+
*/
|
|
41
|
+
opacity: number;
|
|
42
|
+
properties: {
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* csv (default) or base64. tilelayer only.
|
|
47
|
+
*/
|
|
48
|
+
encoding: TiledEncoding;
|
|
49
|
+
/**
|
|
50
|
+
* zlib, gzip, zstd (since Tiled 1.3) or empty (default). tilelayer only.
|
|
51
|
+
*/
|
|
52
|
+
compression?: TiledCompression;
|
|
53
|
+
/**
|
|
54
|
+
* Type of layer (tilelayer, objectgroup)
|
|
55
|
+
*/
|
|
56
|
+
type: TiledLayerType;
|
|
57
|
+
/**
|
|
58
|
+
* @since 1.9
|
|
59
|
+
*/
|
|
60
|
+
class: string;
|
|
61
|
+
/**
|
|
62
|
+
* Whether layer is shown or hidden in editor
|
|
63
|
+
*/
|
|
64
|
+
visible: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Horizontal layer offset in tiles. Always 0.
|
|
67
|
+
*/
|
|
68
|
+
x: number;
|
|
69
|
+
/**
|
|
70
|
+
* Vertical layer offset in tiles. Always 0.
|
|
71
|
+
*/
|
|
72
|
+
y: number;
|
|
73
|
+
/**
|
|
74
|
+
* Layer order in the original Tiled source
|
|
75
|
+
*/
|
|
76
|
+
order: number;
|
|
77
|
+
/**
|
|
78
|
+
* Horizontal layer offset in pixels (default: 0)
|
|
79
|
+
*/
|
|
80
|
+
offsetx: number;
|
|
81
|
+
/**
|
|
82
|
+
* Vertical layer offset in pixels (default: 0)
|
|
83
|
+
*/
|
|
84
|
+
offsety: number;
|
|
85
|
+
/**
|
|
86
|
+
* X coordinate where layer content starts (for infinite maps)
|
|
87
|
+
*/
|
|
88
|
+
startx: number;
|
|
89
|
+
/**
|
|
90
|
+
* Y coordinate where layer content starts (for infinite maps)
|
|
91
|
+
*/
|
|
92
|
+
starty: number;
|
|
93
|
+
/**
|
|
94
|
+
* Hex-formatted color (#RRGGBB or #AARRGGBB) that is multiplied with any graphics drawn by this layer or any child layers (optional).
|
|
95
|
+
*/
|
|
96
|
+
tintcolor: string;
|
|
97
|
+
/**
|
|
98
|
+
* Hex-formatted color (#RRGGBB) (optional). imagelayer only.
|
|
99
|
+
*/
|
|
100
|
+
transparentcolor: string;
|
|
101
|
+
/**
|
|
102
|
+
* topdown (default) or index. objectgroup only.
|
|
103
|
+
*/
|
|
104
|
+
draworder: 'topdown' | 'index' | 'objectgroup';
|
|
105
|
+
/**
|
|
106
|
+
* Array of objects. objectgroup only.
|
|
107
|
+
*/
|
|
108
|
+
objects: TiledObject[];
|
|
109
|
+
layers: TiledLayer[];
|
|
110
|
+
parallaxx: number;
|
|
111
|
+
parallaxy: number;
|
|
112
|
+
repeatx: number;
|
|
113
|
+
repeaty: number;
|
|
114
|
+
locked: boolean;
|
|
115
|
+
color: string;
|
|
116
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { TiledLayer } from './Layer';
|
|
2
|
+
import { TiledTileset } from './Tileset';
|
|
3
|
+
export interface TiledMap {
|
|
4
|
+
type: 'map';
|
|
5
|
+
version: number;
|
|
6
|
+
width: number;
|
|
7
|
+
/**
|
|
8
|
+
* Number of tile rows
|
|
9
|
+
*/
|
|
10
|
+
height: number;
|
|
11
|
+
/**
|
|
12
|
+
* Length of the side of a hex tile in pixels (hexagonal maps only)
|
|
13
|
+
*/
|
|
14
|
+
hexsidelength: number;
|
|
15
|
+
/**
|
|
16
|
+
* Map grid height
|
|
17
|
+
*/
|
|
18
|
+
tileheight: number;
|
|
19
|
+
/**
|
|
20
|
+
* Map grid width
|
|
21
|
+
*/
|
|
22
|
+
tilewidth: number;
|
|
23
|
+
/**
|
|
24
|
+
* Hex-formatted color (#RRGGBB or #AARRGGBB) (optional)
|
|
25
|
+
*/
|
|
26
|
+
backgroundcolor: string;
|
|
27
|
+
/**
|
|
28
|
+
* The compression level to use for tile layer data (defaults to -1, which means to use the algorithm default)
|
|
29
|
+
*/
|
|
30
|
+
compressionlevel: number;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the map has infinite dimensions
|
|
33
|
+
*/
|
|
34
|
+
infinite: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Auto-increments for each layer
|
|
37
|
+
*/
|
|
38
|
+
nextlayerid: number;
|
|
39
|
+
/**
|
|
40
|
+
* Auto-increments for each placed object
|
|
41
|
+
*/
|
|
42
|
+
nextobjectid: number;
|
|
43
|
+
/**
|
|
44
|
+
* Map orientation (orthogonal, isometric, staggered or hexagonal)
|
|
45
|
+
*/
|
|
46
|
+
orientation: 'orthogonal' | 'isometric' | 'staggered' | 'hexagonal';
|
|
47
|
+
layers: TiledLayer[];
|
|
48
|
+
properties: {
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
};
|
|
51
|
+
tilesets: TiledTileset[];
|
|
52
|
+
/**
|
|
53
|
+
* Render order: right-down (the default), right-up, left-down or left-up (currently only supported for orthogonal maps)
|
|
54
|
+
*/
|
|
55
|
+
renderorder: 'right-down' | 'right-up' | 'left-down' | 'left-up';
|
|
56
|
+
/**
|
|
57
|
+
* x or y (staggered / hexagonal maps only)
|
|
58
|
+
*/
|
|
59
|
+
staggeraxis: 'x' | 'y';
|
|
60
|
+
/**
|
|
61
|
+
* odd or even (staggered / hexagonal maps only)
|
|
62
|
+
*/
|
|
63
|
+
staggerindex: 'odd' | 'even';
|
|
64
|
+
/**
|
|
65
|
+
* The Tiled version used to save the file
|
|
66
|
+
*/
|
|
67
|
+
tiledversion: string;
|
|
68
|
+
/**
|
|
69
|
+
* @since 1.9
|
|
70
|
+
*/
|
|
71
|
+
class: string;
|
|
72
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TiledText } from './Text';
|
|
2
|
+
import { TiledPoint } from './Types';
|
|
3
|
+
export interface TiledObject {
|
|
4
|
+
id: number;
|
|
5
|
+
/**
|
|
6
|
+
* Tile object id
|
|
7
|
+
*/
|
|
8
|
+
gid: number;
|
|
9
|
+
/**
|
|
10
|
+
* Used to mark an object as a point
|
|
11
|
+
*/
|
|
12
|
+
point: boolean;
|
|
13
|
+
height: number;
|
|
14
|
+
name: string;
|
|
15
|
+
properties: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Angle in degrees clockwise
|
|
20
|
+
*/
|
|
21
|
+
rotation: number;
|
|
22
|
+
type: string;
|
|
23
|
+
/**
|
|
24
|
+
* @since 1.9
|
|
25
|
+
*/
|
|
26
|
+
class: string;
|
|
27
|
+
visible: boolean;
|
|
28
|
+
width: number;
|
|
29
|
+
/**
|
|
30
|
+
* X coordinate in pixels
|
|
31
|
+
*/
|
|
32
|
+
x: number;
|
|
33
|
+
/**
|
|
34
|
+
* Y coordinate in pixels
|
|
35
|
+
*/
|
|
36
|
+
y: number;
|
|
37
|
+
/**
|
|
38
|
+
* Reference to a template file, in case object is a template instance
|
|
39
|
+
*/
|
|
40
|
+
template: string;
|
|
41
|
+
/**
|
|
42
|
+
* Only used for text objects
|
|
43
|
+
*/
|
|
44
|
+
text: TiledText;
|
|
45
|
+
/**
|
|
46
|
+
* Whether or not object is an ellipse
|
|
47
|
+
*/
|
|
48
|
+
ellipse: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Polygon points
|
|
51
|
+
*/
|
|
52
|
+
polygon: TiledPoint[];
|
|
53
|
+
/**
|
|
54
|
+
* Polyline points
|
|
55
|
+
*/
|
|
56
|
+
polyline: TiledPoint[];
|
|
57
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface TiledText {
|
|
2
|
+
text: string;
|
|
3
|
+
/**
|
|
4
|
+
* Whether to use a bold font (default: false)
|
|
5
|
+
*/
|
|
6
|
+
bold: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Hex-formatted color (#RRGGBB or #AARRGGBB) (default: #000000)
|
|
9
|
+
*/
|
|
10
|
+
color: string;
|
|
11
|
+
/**
|
|
12
|
+
* Font family (default: sans-serif)
|
|
13
|
+
*/
|
|
14
|
+
fontfamily: string;
|
|
15
|
+
/**
|
|
16
|
+
* Horizontal alignment (center, right, justify or left (default))
|
|
17
|
+
*/
|
|
18
|
+
halign: 'center' | 'right' | 'justify' | 'left';
|
|
19
|
+
/**
|
|
20
|
+
* Whether to use an italic font (default: false)
|
|
21
|
+
*/
|
|
22
|
+
italic: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to use kerning when placing characters (default: true)
|
|
25
|
+
*/
|
|
26
|
+
kerning: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Pixel size of font (default: 16)
|
|
29
|
+
*/
|
|
30
|
+
pixelsize: number;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to strike out the text (default: false)
|
|
33
|
+
*/
|
|
34
|
+
strikeout: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to underline the text (default: false)
|
|
37
|
+
*/
|
|
38
|
+
underline: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Vertical alignment (center, bottom or top (default))
|
|
41
|
+
*/
|
|
42
|
+
valign: 'center' | 'bottom' | 'top';
|
|
43
|
+
/**
|
|
44
|
+
* Whether the text is wrapped within the object bounds (default: false)
|
|
45
|
+
*/
|
|
46
|
+
wrap: boolean;
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TiledObject } from './Objects';
|
|
2
|
+
import { TiledFrame } from './Types';
|
|
3
|
+
export interface TilesetTile {
|
|
4
|
+
gid: number;
|
|
5
|
+
id: number;
|
|
6
|
+
type: string;
|
|
7
|
+
image: string;
|
|
8
|
+
imageheight: number;
|
|
9
|
+
imagewidth: number;
|
|
10
|
+
animations: TiledFrame[];
|
|
11
|
+
properties: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
terrain: number[];
|
|
15
|
+
objects: TiledObject[];
|
|
16
|
+
probability: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { TilesetTile } from './Tile';
|
|
2
|
+
import { TiledGrid, TiledMapTerrain, TiledTileOffset, TiledWangSet } from './Types';
|
|
3
|
+
export interface TiledTileset {
|
|
4
|
+
type: 'tileset';
|
|
5
|
+
/**
|
|
6
|
+
* The JSON format version
|
|
7
|
+
*/
|
|
8
|
+
version: number;
|
|
9
|
+
/**
|
|
10
|
+
* GID corresponding to the first tile in the set
|
|
11
|
+
*/
|
|
12
|
+
firstgid: number;
|
|
13
|
+
/**
|
|
14
|
+
* Image used for tiles in this set
|
|
15
|
+
*/
|
|
16
|
+
image: {
|
|
17
|
+
source: string;
|
|
18
|
+
height: number;
|
|
19
|
+
width: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Height of source image in pixels
|
|
23
|
+
*/
|
|
24
|
+
imageheight: number;
|
|
25
|
+
/**
|
|
26
|
+
* Width of source image in pixels
|
|
27
|
+
*/
|
|
28
|
+
imagewidth: number;
|
|
29
|
+
/**
|
|
30
|
+
* (optional)
|
|
31
|
+
*/
|
|
32
|
+
grid: TiledGrid;
|
|
33
|
+
/**
|
|
34
|
+
* Buffer between image edge and first tile (pixels)
|
|
35
|
+
*/
|
|
36
|
+
margin: number;
|
|
37
|
+
/**
|
|
38
|
+
* Alignment to use for tile objects (unspecified (default), topleft, top, topright, left, center, right, bottomleft, bottom or bottomright) (since 1.4)
|
|
39
|
+
*/
|
|
40
|
+
objectalignment: 'unspecified' | 'topleft' | 'top' | 'topright' | 'left' | 'center' | 'right' | 'bottomleft' | 'bottom' | 'bottomright';
|
|
41
|
+
/**
|
|
42
|
+
* Refers to external tileset file (should be JSON)
|
|
43
|
+
*/
|
|
44
|
+
source: string;
|
|
45
|
+
/**
|
|
46
|
+
* Spacing between adjacent tiles in image (pixels)
|
|
47
|
+
*/
|
|
48
|
+
spacing: number;
|
|
49
|
+
columns: number;
|
|
50
|
+
rows: number;
|
|
51
|
+
/**
|
|
52
|
+
* Maximum height of tiles in this set
|
|
53
|
+
*/
|
|
54
|
+
tileheight: number;
|
|
55
|
+
tilewidth: number;
|
|
56
|
+
/**
|
|
57
|
+
* Array of Tiles (optional)
|
|
58
|
+
*/
|
|
59
|
+
tiles: TilesetTile[];
|
|
60
|
+
name: string;
|
|
61
|
+
properties: {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The number of tiles in this tileset
|
|
66
|
+
*/
|
|
67
|
+
tilecount: number;
|
|
68
|
+
/**
|
|
69
|
+
* Optional
|
|
70
|
+
*/
|
|
71
|
+
tileoffset: TiledTileOffset;
|
|
72
|
+
/**
|
|
73
|
+
* The Tiled version used to save the file
|
|
74
|
+
*/
|
|
75
|
+
tiledversion: string;
|
|
76
|
+
/**
|
|
77
|
+
* Hex-formatted color (#RRGGBB or #AARRGGBB) (optional)
|
|
78
|
+
*/
|
|
79
|
+
backgroundcolor: string;
|
|
80
|
+
/**
|
|
81
|
+
* Hex-formatted color (#RRGGBB) (optional)
|
|
82
|
+
*/
|
|
83
|
+
transparentcolor: string;
|
|
84
|
+
/**
|
|
85
|
+
* Array of Terrains (optional)
|
|
86
|
+
*/
|
|
87
|
+
terrains: TiledMapTerrain[];
|
|
88
|
+
/**
|
|
89
|
+
* Array of Wang sets (since 1.1.5)
|
|
90
|
+
*/
|
|
91
|
+
wangsets: TiledWangSet[];
|
|
92
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export interface TiledProperty<T = unknown> {
|
|
2
|
+
/**
|
|
3
|
+
* Name of the property
|
|
4
|
+
*/
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* Type of the property (string (default), int, float, bool, color or file (since 0.16, with color and file added in 0.17))
|
|
8
|
+
*/
|
|
9
|
+
type: 'string' | 'int' | 'float' | 'bool' | 'color' | 'file';
|
|
10
|
+
/**
|
|
11
|
+
* Value of the property
|
|
12
|
+
*/
|
|
13
|
+
value: T;
|
|
14
|
+
}
|
|
15
|
+
export type TiledEncoding = 'csv' | 'base64';
|
|
16
|
+
export type TiledCompression = 'zlib' | 'gzip' | 'zstd';
|
|
17
|
+
export interface TiledChunk {
|
|
18
|
+
/**
|
|
19
|
+
* Array of unsigned int (GIDs) or base64-encoded data
|
|
20
|
+
*/
|
|
21
|
+
data: number[] | string;
|
|
22
|
+
/**
|
|
23
|
+
* Height in tiles
|
|
24
|
+
*/
|
|
25
|
+
height: number;
|
|
26
|
+
/**
|
|
27
|
+
* Width in tiles
|
|
28
|
+
*/
|
|
29
|
+
width: number;
|
|
30
|
+
/**
|
|
31
|
+
* X coordinate in tiles
|
|
32
|
+
*/
|
|
33
|
+
x: number;
|
|
34
|
+
/**
|
|
35
|
+
* Y coordinate in tiles
|
|
36
|
+
*/
|
|
37
|
+
y: number;
|
|
38
|
+
}
|
|
39
|
+
export interface TiledTileOffset {
|
|
40
|
+
/**
|
|
41
|
+
* Horizontal offset in pixels
|
|
42
|
+
*/
|
|
43
|
+
x: number;
|
|
44
|
+
/**
|
|
45
|
+
* Vertical offset in pixels (positive is down)
|
|
46
|
+
*/
|
|
47
|
+
y: number;
|
|
48
|
+
}
|
|
49
|
+
export interface TiledWangSet {
|
|
50
|
+
/**
|
|
51
|
+
* Array of Wang colors
|
|
52
|
+
*/
|
|
53
|
+
cornercolors: TiledWangColor[];
|
|
54
|
+
/**
|
|
55
|
+
* Array of Wang colors
|
|
56
|
+
*/
|
|
57
|
+
edgecolors: TiledWangColor[];
|
|
58
|
+
name: string;
|
|
59
|
+
properties: TiledProperty[];
|
|
60
|
+
/**
|
|
61
|
+
* Local ID of tile representing the Wang set
|
|
62
|
+
*/
|
|
63
|
+
tile: number;
|
|
64
|
+
wangtiles: TiledWangTile[];
|
|
65
|
+
}
|
|
66
|
+
export interface TiledWangTile {
|
|
67
|
+
/**
|
|
68
|
+
* Array of Wang color indexes (uchar[8]
|
|
69
|
+
*/
|
|
70
|
+
wangid: number[];
|
|
71
|
+
/**
|
|
72
|
+
* Tile is flipped diagonally (default: false)
|
|
73
|
+
*/
|
|
74
|
+
dflip: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Tile is flipped horizontally (default: false)
|
|
77
|
+
*/
|
|
78
|
+
hflip: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Local ID of tile
|
|
81
|
+
*/
|
|
82
|
+
tileid: number;
|
|
83
|
+
/**
|
|
84
|
+
* Tile is flipped vertically (default: false)
|
|
85
|
+
*/
|
|
86
|
+
vflip: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface TiledWangColor {
|
|
89
|
+
/**
|
|
90
|
+
* Hex-formatted color (#RRGGBB or #AARRGGBB)
|
|
91
|
+
*/
|
|
92
|
+
color: string;
|
|
93
|
+
/**
|
|
94
|
+
* Name of the Wang color
|
|
95
|
+
*/
|
|
96
|
+
name: string;
|
|
97
|
+
/**
|
|
98
|
+
* Probability used when randomizing
|
|
99
|
+
*/
|
|
100
|
+
probability: number;
|
|
101
|
+
/**
|
|
102
|
+
* Local ID of tile representing the Wang color
|
|
103
|
+
*/
|
|
104
|
+
tile: number;
|
|
105
|
+
}
|
|
106
|
+
export interface TiledGrid {
|
|
107
|
+
/**
|
|
108
|
+
* orthogonal (default) or isometric
|
|
109
|
+
*/
|
|
110
|
+
orientation: 'orthogonal' | 'isometric';
|
|
111
|
+
/**
|
|
112
|
+
* Cell width of tile grid
|
|
113
|
+
*/
|
|
114
|
+
width: number;
|
|
115
|
+
/**
|
|
116
|
+
* Cell height of tile grid
|
|
117
|
+
*/
|
|
118
|
+
height: number;
|
|
119
|
+
}
|
|
120
|
+
export interface TiledFrame {
|
|
121
|
+
/**
|
|
122
|
+
* Frame duration in milliseconds
|
|
123
|
+
*/
|
|
124
|
+
duration: number;
|
|
125
|
+
/**
|
|
126
|
+
* Local tile ID representing this frame
|
|
127
|
+
*/
|
|
128
|
+
tileid: number;
|
|
129
|
+
}
|
|
130
|
+
export interface TiledMapTerrain {
|
|
131
|
+
name: string;
|
|
132
|
+
/**
|
|
133
|
+
* Local ID of tile representing terrain
|
|
134
|
+
*/
|
|
135
|
+
tile: number;
|
|
136
|
+
properties: TiledProperty[];
|
|
137
|
+
}
|
|
138
|
+
export interface TiledPoint {
|
|
139
|
+
x: number;
|
|
140
|
+
y: number;
|
|
141
|
+
}
|
|
142
|
+
export interface TiledImage {
|
|
143
|
+
source: string;
|
|
144
|
+
width: number;
|
|
145
|
+
height: number;
|
|
146
|
+
trans?: string;
|
|
147
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function isTiledFormat(val: any): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Join path segments with forward slashes
|
|
4
|
+
* @param {...string} segments - Path segments to join
|
|
5
|
+
* @returns {string} Joined path
|
|
6
|
+
* @example
|
|
7
|
+
* joinPath('base', 'static', 'file.json') // returns 'base/static/file.json'
|
|
8
|
+
*/
|
|
9
|
+
export declare function joinPath(...segments: string[]): string;
|
|
10
|
+
export declare function getBaseName(path: string): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@canvasengine/tiled",
|
|
3
|
+
"version": "2.0.0-beta.25",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/node": "^18.15.10",
|
|
15
|
+
"typescript": "^5.0.2",
|
|
16
|
+
"vite": "^6.2.5",
|
|
17
|
+
"vite-plugin-dts": "^4.5.3",
|
|
18
|
+
"vitest": "^3.1.1"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"buffer": "^6.0.3",
|
|
22
|
+
"xml-js": "^1.6.11",
|
|
23
|
+
"xmlbuilder": "^15.1.1"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "vite build",
|
|
28
|
+
"dev": "vite build --watch",
|
|
29
|
+
"test": "vitest"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Time was saved on writing the types. Thanks to https://github.com/excaliburjs/excalibur-tiled/blob/main/src
|