@rpgjs/tiledmap 5.0.0-alpha.13 → 5.0.0-alpha.15
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/server/index3.js +2 -282
- package/package.json +5 -5
package/dist/server/index3.js
CHANGED
|
@@ -5,9 +5,6 @@ var TiledLayerType = /* @__PURE__ */ ((TiledLayerType2) => {
|
|
|
5
5
|
TiledLayerType2["Group"] = "group";
|
|
6
6
|
return TiledLayerType2;
|
|
7
7
|
})(TiledLayerType || {});
|
|
8
|
-
function joinPath(...segments) {
|
|
9
|
-
return segments.filter((segment) => segment && segment.length > 0).join("/").replace(/\/+/g, "/");
|
|
10
|
-
}
|
|
11
8
|
function getAugmentedNamespace(n) {
|
|
12
9
|
if (Object.prototype.hasOwnProperty.call(n, "__esModule")) return n;
|
|
13
10
|
var f = n.default;
|
|
@@ -4376,284 +4373,8 @@ function requireLib() {
|
|
|
4376
4373
|
};
|
|
4377
4374
|
return lib;
|
|
4378
4375
|
}
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
const _TiledParser = class _TiledParser {
|
|
4382
|
-
constructor(xml, filePath = "", basePath = "") {
|
|
4383
|
-
this.xml = xml;
|
|
4384
|
-
this.filePath = filePath;
|
|
4385
|
-
this.basePath = basePath;
|
|
4386
|
-
this.layers = /* @__PURE__ */ new Map();
|
|
4387
|
-
this.transform = (obj) => {
|
|
4388
|
-
var _a, _b;
|
|
4389
|
-
if (!obj) return;
|
|
4390
|
-
const attr = obj.attributes || obj._attributes;
|
|
4391
|
-
if (!attr) return obj;
|
|
4392
|
-
let newObj = {
|
|
4393
|
-
...obj,
|
|
4394
|
-
...attr,
|
|
4395
|
-
..._TiledParser.propToNumber(attr, [
|
|
4396
|
-
"version",
|
|
4397
|
-
"width",
|
|
4398
|
-
"height",
|
|
4399
|
-
"tilewidth",
|
|
4400
|
-
"tileheight",
|
|
4401
|
-
"nextlayerid",
|
|
4402
|
-
"nextobjectid",
|
|
4403
|
-
"hexsidelength",
|
|
4404
|
-
"opacity",
|
|
4405
|
-
"x",
|
|
4406
|
-
"y",
|
|
4407
|
-
"offsetx",
|
|
4408
|
-
"offsety",
|
|
4409
|
-
"startx",
|
|
4410
|
-
"starty",
|
|
4411
|
-
"id",
|
|
4412
|
-
"firstgid",
|
|
4413
|
-
"imageheight",
|
|
4414
|
-
"imagewidth",
|
|
4415
|
-
"margin",
|
|
4416
|
-
"columns",
|
|
4417
|
-
"rows",
|
|
4418
|
-
"tilecount",
|
|
4419
|
-
"rotation",
|
|
4420
|
-
"gid",
|
|
4421
|
-
"tileid",
|
|
4422
|
-
"duration",
|
|
4423
|
-
"parallaxx",
|
|
4424
|
-
"parallaxy",
|
|
4425
|
-
"repeatx",
|
|
4426
|
-
"repeaty",
|
|
4427
|
-
"pixelsize"
|
|
4428
|
-
]),
|
|
4429
|
-
..._TiledParser.propToBool(attr, [
|
|
4430
|
-
"visible",
|
|
4431
|
-
"infinite",
|
|
4432
|
-
"locked",
|
|
4433
|
-
"bold",
|
|
4434
|
-
"italic",
|
|
4435
|
-
"kerning",
|
|
4436
|
-
"strikeout",
|
|
4437
|
-
"underline",
|
|
4438
|
-
"wrap"
|
|
4439
|
-
])
|
|
4440
|
-
};
|
|
4441
|
-
if (newObj.properties) {
|
|
4442
|
-
const properties = _TiledParser.toArray(newObj.properties.property);
|
|
4443
|
-
const propObj = {};
|
|
4444
|
-
for (let prop of properties) {
|
|
4445
|
-
const attr2 = prop._attributes;
|
|
4446
|
-
if (!attr2) continue;
|
|
4447
|
-
let val;
|
|
4448
|
-
switch (attr2.type) {
|
|
4449
|
-
case "file":
|
|
4450
|
-
val = this.getImagePath(attr2.value);
|
|
4451
|
-
break;
|
|
4452
|
-
case "object":
|
|
4453
|
-
case "float":
|
|
4454
|
-
case "int":
|
|
4455
|
-
val = +attr2.value;
|
|
4456
|
-
break;
|
|
4457
|
-
case "bool":
|
|
4458
|
-
val = attr2.value == "true" ? true : false;
|
|
4459
|
-
break;
|
|
4460
|
-
case "class":
|
|
4461
|
-
val = {
|
|
4462
|
-
...((_a = this.transform(prop)) == null ? void 0 : _a.properties) ?? {},
|
|
4463
|
-
_classname: attr2.propertytype
|
|
4464
|
-
};
|
|
4465
|
-
break;
|
|
4466
|
-
default:
|
|
4467
|
-
val = attr2.value;
|
|
4468
|
-
}
|
|
4469
|
-
propObj[attr2.name] = val;
|
|
4470
|
-
}
|
|
4471
|
-
newObj.properties = propObj;
|
|
4472
|
-
}
|
|
4473
|
-
if (newObj.polygon) {
|
|
4474
|
-
newObj.polygon = this.transform(newObj.polygon);
|
|
4475
|
-
}
|
|
4476
|
-
if (newObj.polyline) {
|
|
4477
|
-
newObj.polyline = this.transform(newObj.polyline);
|
|
4478
|
-
}
|
|
4479
|
-
if (newObj.points) {
|
|
4480
|
-
newObj = newObj.points.split(" ").map((point) => {
|
|
4481
|
-
const pos = point.split(",");
|
|
4482
|
-
return { x: +pos[0], y: +pos[1] };
|
|
4483
|
-
});
|
|
4484
|
-
}
|
|
4485
|
-
if (newObj.point) {
|
|
4486
|
-
newObj.point = true;
|
|
4487
|
-
}
|
|
4488
|
-
if (newObj.ellipse) {
|
|
4489
|
-
newObj.ellipse = true;
|
|
4490
|
-
}
|
|
4491
|
-
if (newObj.text) {
|
|
4492
|
-
newObj.text = {
|
|
4493
|
-
text: newObj.text._text,
|
|
4494
|
-
...this.transform(newObj.text)
|
|
4495
|
-
};
|
|
4496
|
-
delete newObj.text._text;
|
|
4497
|
-
}
|
|
4498
|
-
if (newObj.image) {
|
|
4499
|
-
newObj.image = this.transform(newObj.image);
|
|
4500
|
-
}
|
|
4501
|
-
if (newObj.source) {
|
|
4502
|
-
if (!this.isTilesetSource(newObj)) {
|
|
4503
|
-
newObj.source = this.getImagePath(newObj.source);
|
|
4504
|
-
}
|
|
4505
|
-
}
|
|
4506
|
-
const objectgroup = newObj.object || ((_b = newObj.objectgroup) == null ? void 0 : _b.object);
|
|
4507
|
-
if (objectgroup) {
|
|
4508
|
-
newObj.objects = _TiledParser.toArray(objectgroup).map((object) => {
|
|
4509
|
-
return this.transform(object);
|
|
4510
|
-
});
|
|
4511
|
-
}
|
|
4512
|
-
delete newObj._attributes;
|
|
4513
|
-
delete newObj.attributes;
|
|
4514
|
-
delete newObj.object;
|
|
4515
|
-
delete newObj.objectgroup;
|
|
4516
|
-
return newObj;
|
|
4517
|
-
};
|
|
4518
|
-
}
|
|
4519
|
-
static toArray(prop) {
|
|
4520
|
-
if (!prop) return [];
|
|
4521
|
-
if (!Array.isArray(prop)) return [prop];
|
|
4522
|
-
return prop;
|
|
4523
|
-
}
|
|
4524
|
-
getImagePath(image) {
|
|
4525
|
-
if (this.filePath.startsWith("http")) return new URL(image, this.filePath).href;
|
|
4526
|
-
return joinPath(this.basePath, image);
|
|
4527
|
-
}
|
|
4528
|
-
/**
|
|
4529
|
-
* Check if the object is a tileset source reference
|
|
4530
|
-
* Tileset sources should not have their paths transformed with getImagePath
|
|
4531
|
-
*/
|
|
4532
|
-
isTilesetSource(obj) {
|
|
4533
|
-
return obj.firstgid !== void 0 || obj.tilewidth !== void 0 || obj.tileheight !== void 0 || obj.tilecount !== void 0 || obj.columns !== void 0;
|
|
4534
|
-
}
|
|
4535
|
-
static unpackTileBytes(buffer2, size) {
|
|
4536
|
-
const expectedCount = size * 4;
|
|
4537
|
-
if (buffer2.length !== expectedCount) {
|
|
4538
|
-
throw new Error("Expected " + expectedCount + " bytes of tile data; received " + buffer2.length);
|
|
4539
|
-
}
|
|
4540
|
-
let tileIndex = 0;
|
|
4541
|
-
const array = [];
|
|
4542
|
-
for (let i = 0; i < expectedCount; i += 4) {
|
|
4543
|
-
array[tileIndex] = buffer2.readUInt32LE(i);
|
|
4544
|
-
tileIndex++;
|
|
4545
|
-
}
|
|
4546
|
-
return array;
|
|
4547
|
-
}
|
|
4548
|
-
static decode(obj, size) {
|
|
4549
|
-
const { encoding, data } = obj;
|
|
4550
|
-
if (encoding == "base64") {
|
|
4551
|
-
return _TiledParser.unpackTileBytes(bufferExports.Buffer.from(data.trim(), "base64"), size);
|
|
4552
|
-
} else if (encoding == "csv") {
|
|
4553
|
-
return data.trim().split(",").map((x) => +x);
|
|
4554
|
-
}
|
|
4555
|
-
return data;
|
|
4556
|
-
}
|
|
4557
|
-
parseMap() {
|
|
4558
|
-
const json = libExports.xml2js(this.xml, { compact: true });
|
|
4559
|
-
const jsonNoCompact = libExports.xml2js(this.xml);
|
|
4560
|
-
const tileset = json.map.tileset;
|
|
4561
|
-
json.map.group;
|
|
4562
|
-
const recursiveObjectGroup = (obj) => {
|
|
4563
|
-
const { objectgroup, group: group2, layer, imagelayer } = obj;
|
|
4564
|
-
const setLayer = (type) => {
|
|
4565
|
-
if (!type) return;
|
|
4566
|
-
_TiledParser.toArray(type).forEach((val) => {
|
|
4567
|
-
if (this.layers.has(+val._attributes.id)) {
|
|
4568
|
-
throw new Error(`Tiled Parser Error: Layer with id ${val._attributes.id} already exists`);
|
|
4569
|
-
}
|
|
4570
|
-
this.layers.set(+val._attributes.id, val);
|
|
4571
|
-
});
|
|
4572
|
-
};
|
|
4573
|
-
setLayer(objectgroup);
|
|
4574
|
-
setLayer(layer);
|
|
4575
|
-
setLayer(group2);
|
|
4576
|
-
setLayer(imagelayer);
|
|
4577
|
-
if (group2) {
|
|
4578
|
-
recursiveObjectGroup(group2);
|
|
4579
|
-
}
|
|
4580
|
-
};
|
|
4581
|
-
recursiveObjectGroup(json.map);
|
|
4582
|
-
const recursiveLayer = (elements, array = []) => {
|
|
4583
|
-
var _a;
|
|
4584
|
-
if (!elements) return array;
|
|
4585
|
-
for (let element of elements) {
|
|
4586
|
-
const { name } = element;
|
|
4587
|
-
if (!["layer", "group", "imagelayer", "objectgroup"].includes(name)) continue;
|
|
4588
|
-
const data = (_a = element.elements) == null ? void 0 : _a.find((el) => el.name == "data");
|
|
4589
|
-
element.layer = this.layers.get(+element.attributes.id);
|
|
4590
|
-
const obj = {
|
|
4591
|
-
...this.transform(data) ?? {},
|
|
4592
|
-
...this.transform(element),
|
|
4593
|
-
...this.transform(element.layer),
|
|
4594
|
-
layers: recursiveLayer(element.elements),
|
|
4595
|
-
data: data ? data.elements[0].text : void 0,
|
|
4596
|
-
type: name == "layer" ? "tilelayer" : name
|
|
4597
|
-
};
|
|
4598
|
-
delete obj.elements;
|
|
4599
|
-
delete obj.layer;
|
|
4600
|
-
if (obj.data) obj.data = _TiledParser.decode(obj, obj.width * obj.height);
|
|
4601
|
-
array.push(obj);
|
|
4602
|
-
}
|
|
4603
|
-
return array;
|
|
4604
|
-
};
|
|
4605
|
-
const layers = recursiveLayer(jsonNoCompact.elements[0].elements);
|
|
4606
|
-
const tilesets = _TiledParser.toArray(tileset).map((tileset2) => {
|
|
4607
|
-
const obj = this.transform(tileset2);
|
|
4608
|
-
return obj;
|
|
4609
|
-
});
|
|
4610
|
-
const ret = {
|
|
4611
|
-
...this.transform(json.map),
|
|
4612
|
-
layers,
|
|
4613
|
-
tilesets
|
|
4614
|
-
};
|
|
4615
|
-
delete ret.layer;
|
|
4616
|
-
delete ret.tileset;
|
|
4617
|
-
delete ret.group;
|
|
4618
|
-
delete ret.imagelayer;
|
|
4619
|
-
return ret;
|
|
4620
|
-
}
|
|
4621
|
-
parseTileset() {
|
|
4622
|
-
const json = libExports.xml2js(this.xml, { compact: true });
|
|
4623
|
-
const { tileset } = json;
|
|
4624
|
-
const ret = {
|
|
4625
|
-
...this.transform(tileset),
|
|
4626
|
-
image: this.transform(tileset.image),
|
|
4627
|
-
tiles: _TiledParser.toArray(tileset.tile).map((tile) => {
|
|
4628
|
-
const ret2 = this.transform(tile);
|
|
4629
|
-
if (tile.animation) {
|
|
4630
|
-
ret2.animations = _TiledParser.toArray(tile.animation.frame).map(this.transform);
|
|
4631
|
-
}
|
|
4632
|
-
delete ret2.animation;
|
|
4633
|
-
return ret2;
|
|
4634
|
-
})
|
|
4635
|
-
};
|
|
4636
|
-
delete ret.tile;
|
|
4637
|
-
return ret;
|
|
4638
|
-
}
|
|
4639
|
-
};
|
|
4640
|
-
_TiledParser.propToNumber = (obj, props) => {
|
|
4641
|
-
for (let key of props) {
|
|
4642
|
-
if (obj[key] !== void 0) {
|
|
4643
|
-
obj[key] = +obj[key];
|
|
4644
|
-
}
|
|
4645
|
-
}
|
|
4646
|
-
return obj;
|
|
4647
|
-
};
|
|
4648
|
-
_TiledParser.propToBool = (obj, props) => {
|
|
4649
|
-
for (let key of props) {
|
|
4650
|
-
if (obj[key] !== void 0) {
|
|
4651
|
-
obj[key] = obj[key] == "true" || obj[key] == "1";
|
|
4652
|
-
}
|
|
4653
|
-
}
|
|
4654
|
-
return obj;
|
|
4655
|
-
};
|
|
4656
|
-
let TiledParser = _TiledParser;
|
|
4376
|
+
requireLib();
|
|
4377
|
+
requireBuffer();
|
|
4657
4378
|
class TiledProperties {
|
|
4658
4379
|
constructor(data) {
|
|
4659
4380
|
this.properties = {};
|
|
@@ -5226,7 +4947,6 @@ export {
|
|
|
5226
4947
|
Tile,
|
|
5227
4948
|
TiledLayerType,
|
|
5228
4949
|
TiledObjectClass,
|
|
5229
|
-
TiledParser,
|
|
5230
4950
|
TiledProperties,
|
|
5231
4951
|
Tileset
|
|
5232
4952
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/tiledmap",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.15",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"description": "RPGJS is a framework for creating RPG/MMORPG games",
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@canvasengine/presets": "2.0.0-beta.25",
|
|
26
|
-
"@rpgjs/client": "5.0.0-alpha.
|
|
27
|
-
"@rpgjs/common": "5.0.0-alpha.
|
|
28
|
-
"@rpgjs/server": "5.0.0-alpha.
|
|
29
|
-
"@rpgjs/vite": "5.0.0-alpha.
|
|
26
|
+
"@rpgjs/client": "5.0.0-alpha.15",
|
|
27
|
+
"@rpgjs/common": "5.0.0-alpha.15",
|
|
28
|
+
"@rpgjs/server": "5.0.0-alpha.15",
|
|
29
|
+
"@rpgjs/vite": "5.0.0-alpha.15",
|
|
30
30
|
"canvasengine": "2.0.0-beta.25"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|