@safe-engine/cocos 2.5.3 → 2.5.4
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/app.d.ts.map +1 -1
- package/dist/app.js +12 -7
- package/dist/fasttiled/TiledMapComp.d.ts +12 -0
- package/dist/fasttiled/TiledMapComp.d.ts.map +1 -0
- package/dist/fasttiled/TiledMapComp.js +18 -0
- package/dist/fasttiled/TiledMapContainer.d.ts +31 -0
- package/dist/fasttiled/TiledMapContainer.d.ts.map +1 -0
- package/dist/fasttiled/TiledMapContainer.js +25 -0
- package/dist/fasttiled/index.d.ts +3 -0
- package/dist/fasttiled/index.d.ts.map +1 -0
- package/dist/fasttiled/index.js +6 -0
- package/dist/fasttiled/tield.d.ts +7 -0
- package/dist/fasttiled/tield.d.ts.map +1 -0
- package/dist/fasttiled/tield.js +88 -0
- package/package.json +1 -1
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAKA,wBAAgB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,QAQ7C;AACD,UAAU,UAAU;IAClB,SAAS,EAAE,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CACtB;AACD,wBAAsB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;;;CAAA,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,iBA2CnG;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAKA,wBAAgB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,QAQ7C;AACD,UAAU,UAAU;IAClB,SAAS,EAAE,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CACtB;AACD,wBAAsB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;;;CAAA,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,iBA2CnG;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,oBA0CnE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAIxD;AAED,eAAO,MAAM,WAAW,uBAAiB,CAAA"}
|
package/dist/app.js
CHANGED
|
@@ -54,13 +54,18 @@ export function loadAll(assets, cb) {
|
|
|
54
54
|
const allAssets = [];
|
|
55
55
|
Object.values(assets).forEach((value) => {
|
|
56
56
|
if (value.skeleton) {
|
|
57
|
-
allAssets.push(value.skeleton);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
allAssets.push(value.skeleton, value.atlas);
|
|
58
|
+
if (value.texture) {
|
|
59
|
+
if (Array.isArray(value.texture)) {
|
|
60
|
+
allAssets.push(...value.texture);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
allAssets.push(value.texture);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
allAssets.push(value.atlas.replace('.atlas', '.png'));
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
else if (value.endsWith('.ttf')) {
|
|
66
71
|
allAssets.push({
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseComponentProps, ComponentX } from '..';
|
|
2
|
+
import { TiledMapContainer } from './TiledMapContainer';
|
|
3
|
+
interface TiledMapCompProps extends BaseComponentProps<TiledMapComp> {
|
|
4
|
+
mapFile: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class TiledMapComp extends ComponentX<TiledMapCompProps, TiledMapContainer> {
|
|
7
|
+
getLayer(layerName: string): import("./TiledMapContainer").TiledMapLayer;
|
|
8
|
+
getObjectGroup(layerName: string): any;
|
|
9
|
+
render(): this;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=TiledMapComp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TiledMapComp.d.ts","sourceRoot":"","sources":["../../src/fasttiled/TiledMapComp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAuB,MAAM,IAAI,CAAA;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,UAAU,iBAAkB,SAAQ,kBAAkB,CAAC,YAAY,CAAC;IAClE,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,YAAa,SAAQ,UAAU,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAChF,QAAQ,CAAC,SAAS,EAAE,MAAM;IAG1B,cAAc,CAAC,SAAS,EAAE,MAAM;IAIhC,MAAM;CAQP"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentX, GameWorld, NodeComp } from '..';
|
|
2
|
+
import { loadIsometricMap } from './tield';
|
|
3
|
+
export class TiledMapComp extends ComponentX {
|
|
4
|
+
getLayer(layerName) {
|
|
5
|
+
return this.node.instance.getLayer(layerName);
|
|
6
|
+
}
|
|
7
|
+
getObjectGroup(layerName) {
|
|
8
|
+
return this.node.instance.getObjectGroup(layerName);
|
|
9
|
+
}
|
|
10
|
+
render() {
|
|
11
|
+
const tiledMap = loadIsometricMap(this.props.mapFile);
|
|
12
|
+
const world = GameWorld.Instance;
|
|
13
|
+
const entity = world.entities.create();
|
|
14
|
+
this.node = entity.assign(new NodeComp(tiledMap, entity));
|
|
15
|
+
const comp = entity.assign(this);
|
|
16
|
+
return comp;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Vec2 } from '../polyfills';
|
|
2
|
+
export declare class TiledMapContainer extends cc.Node {
|
|
3
|
+
layers: Map<string, TiledMapLayer>;
|
|
4
|
+
objectGroups: Map<string, any>;
|
|
5
|
+
getLayer(layerName: string): TiledMapLayer;
|
|
6
|
+
getObjectGroup(layerName: string): any;
|
|
7
|
+
}
|
|
8
|
+
export declare class TiledMapLayer extends cc.Node {
|
|
9
|
+
mapData: any;
|
|
10
|
+
getPositionAt(tx: number, ty: number): {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
equals(other: /*elided*/ any): boolean;
|
|
14
|
+
add(value: cc.Point | Vec2): /*elided*/ any;
|
|
15
|
+
addSelf(value: cc.Point | Vec2): /*elided*/ any;
|
|
16
|
+
sub(value: cc.Point | Vec2): /*elided*/ any;
|
|
17
|
+
mul(multiply: number): /*elided*/ any;
|
|
18
|
+
mulSelf(multiply: number): /*elided*/ any;
|
|
19
|
+
mag(): number;
|
|
20
|
+
normalizeSelf(): /*elided*/ any;
|
|
21
|
+
normalize(): /*elided*/ any;
|
|
22
|
+
cross(other: Vec2): number;
|
|
23
|
+
signAngle(other: Vec2): number;
|
|
24
|
+
lengthSqr(): number;
|
|
25
|
+
dot(other: Vec2): number;
|
|
26
|
+
angle(other: Vec2): number;
|
|
27
|
+
distance(other: /*elided*/ any): number;
|
|
28
|
+
};
|
|
29
|
+
getTileAt(tx: number, ty: number): cc.Node;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=TiledMapContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TiledMapContainer.d.ts","sourceRoot":"","sources":["../../src/fasttiled/TiledMapContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGnC,qBAAa,iBAAkB,SAAQ,EAAE,CAAC,IAAI;IAC5C,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAY;IAC9C,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAY;IAE1C,QAAQ,CAAC,SAAS,EAAE,MAAM;IAI1B,cAAc,CAAC,SAAS,EAAE,MAAM;CAGjC;AAED,qBAAa,aAAc,SAAQ,EAAE,CAAC,IAAI;IACxC,OAAO,EAAE,GAAG,CAAA;IACZ,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;IAOpC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAIjC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Vec2 } from '../polyfills';
|
|
2
|
+
import { tileToPixel } from './tield';
|
|
3
|
+
export class TiledMapContainer extends cc.Node {
|
|
4
|
+
layers = new Map();
|
|
5
|
+
objectGroups = new Map();
|
|
6
|
+
getLayer(layerName) {
|
|
7
|
+
return this.layers.get(layerName);
|
|
8
|
+
}
|
|
9
|
+
getObjectGroup(layerName) {
|
|
10
|
+
return this.objectGroups.get(layerName);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class TiledMapLayer extends cc.Node {
|
|
14
|
+
mapData;
|
|
15
|
+
getPositionAt(tx, ty) {
|
|
16
|
+
// Use zero-based tile coordinates (no +1) and convert local tile position to world space
|
|
17
|
+
const pos = tileToPixel(this.mapData, tx, ty);
|
|
18
|
+
const worldPoint = this.convertToWorldSpaceAR(cc.p(pos.x, pos.y));
|
|
19
|
+
return Vec2(worldPoint);
|
|
20
|
+
}
|
|
21
|
+
getTileAt(tx, ty) {
|
|
22
|
+
const idx = 0 | (tx + ty * this.mapData.width);
|
|
23
|
+
return this.children[idx];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fasttiled/index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAA;AAE9B,wBAAgB,aAAa,SAE5B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TiledMapContainer } from './TiledMapContainer';
|
|
2
|
+
export declare function tileToPixel(map: any, tx: any, ty: any): {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function loadIsometricMap(mapUrl: string): TiledMapContainer;
|
|
7
|
+
//# sourceMappingURL=tield.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tield.d.ts","sourceRoot":"","sources":["../../src/fasttiled/tield.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAiB,MAAM,qBAAqB,CAAA;AAEtE,wBAAgB,WAAW,CAAC,GAAG,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA;;;EAiDtC;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,qBAyC9C"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { TiledMapContainer, TiledMapLayer } from './TiledMapContainer';
|
|
2
|
+
export function tileToPixel(map, tx, ty) {
|
|
3
|
+
const tw = map.tilewidth;
|
|
4
|
+
const th = map.tileheight;
|
|
5
|
+
const { orientation, staggeraxis, staggerindex } = map;
|
|
6
|
+
// Cocos coordinate system: origin at bottom-left and sprites are centered by default
|
|
7
|
+
// Convert Tiled (top-left origin) coordinates to Cocos (bottom-left, centered)
|
|
8
|
+
switch (orientation) {
|
|
9
|
+
case 'orthogonal': {
|
|
10
|
+
const x = tx * tw + tw / 2;
|
|
11
|
+
const y = (map.height - ty - 1) * th + th / 2;
|
|
12
|
+
return { x, y };
|
|
13
|
+
}
|
|
14
|
+
case 'isometric': {
|
|
15
|
+
// Standard isometric screen coordinates (top-left origin)
|
|
16
|
+
const x0 = (tx - ty) * (tw / 2);
|
|
17
|
+
const y0 = (tx + ty) * (th / 2);
|
|
18
|
+
// full map size in pixels for isometric
|
|
19
|
+
const mapW = (map.width + map.height) * (tw / 2);
|
|
20
|
+
const mapH = (map.width + map.height) * (th / 2);
|
|
21
|
+
const x = x0 + mapW / 2; // center horizontally
|
|
22
|
+
const y = mapH - y0 - th / 2; // flip Y and center vertically
|
|
23
|
+
return { x, y };
|
|
24
|
+
}
|
|
25
|
+
case 'staggered': {
|
|
26
|
+
if (staggeraxis === 'x') {
|
|
27
|
+
const odd = staggerindex === 'odd';
|
|
28
|
+
const offset = tx % 2 === (odd ? 1 : 0) ? th / 2 : 0;
|
|
29
|
+
const x0 = tx * (tw / 2);
|
|
30
|
+
const y0 = ty * th + offset;
|
|
31
|
+
const x = x0 + tw / 2;
|
|
32
|
+
const y = map.height * th - y0 - th / 2;
|
|
33
|
+
return { x, y };
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const odd = staggerindex === 'odd';
|
|
37
|
+
const offset = ty % 2 === (odd ? 1 : 0) ? tw / 2 : 0;
|
|
38
|
+
const x0 = tx * tw + offset;
|
|
39
|
+
const y0 = ty * (th / 2);
|
|
40
|
+
const x = x0 + tw / 2;
|
|
41
|
+
const y = map.height * th - y0 - th / 2;
|
|
42
|
+
return { x, y };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
default:
|
|
46
|
+
throw new Error(`Unknown map type: ${orientation}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function loadIsometricMap(mapUrl) {
|
|
50
|
+
const mapData = cc.loader.getRes(mapUrl);
|
|
51
|
+
const tileset = mapData.tilesets[0];
|
|
52
|
+
const baseDir = mapUrl.split('/').slice(0, -1).join('/');
|
|
53
|
+
const tilesetImageUrl = `${baseDir}/${tileset.image}`;
|
|
54
|
+
const tilesetTexture = cc.loader.getRes(tilesetImageUrl);
|
|
55
|
+
const tileW = tileset.tilewidth;
|
|
56
|
+
const tileH = tileset.tileheight;
|
|
57
|
+
const cols = tileset.columns;
|
|
58
|
+
const firstGid = tileset.firstgid;
|
|
59
|
+
const tilemap = new TiledMapContainer();
|
|
60
|
+
// tilemap.mapData = mapData
|
|
61
|
+
for (const layer of mapData.layers) {
|
|
62
|
+
if (layer.type !== 'tilelayer')
|
|
63
|
+
continue;
|
|
64
|
+
const tileLayer = new TiledMapLayer();
|
|
65
|
+
tileLayer.mapData = mapData;
|
|
66
|
+
tilemap.layers.set(layer.name, tileLayer);
|
|
67
|
+
tilemap.addChild(tileLayer);
|
|
68
|
+
const data = layer.data;
|
|
69
|
+
for (let i = 0; i < data.length; i++) {
|
|
70
|
+
const gid = data[i];
|
|
71
|
+
if (gid === 0)
|
|
72
|
+
continue;
|
|
73
|
+
const tileId = gid - firstGid;
|
|
74
|
+
const frameX = (tileId % cols) * tileW;
|
|
75
|
+
const frameY = Math.floor(tileId / cols) * tileH;
|
|
76
|
+
const tx = i % mapData.width;
|
|
77
|
+
const ty = Math.floor(i / mapData.width);
|
|
78
|
+
const { x, y } = tileToPixel(mapData, tx, ty);
|
|
79
|
+
const frame = new cc.SpriteFrame(tilesetTexture, cc.rect(frameX, frameY, tileW, tileH));
|
|
80
|
+
const sprite = new cc.Sprite(frame);
|
|
81
|
+
sprite.x = x;
|
|
82
|
+
sprite.y = y - cc.winSize.height;
|
|
83
|
+
// console.log('x,y', x, y)
|
|
84
|
+
tileLayer.addChild(sprite);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return tilemap;
|
|
88
|
+
}
|