@safe-engine/cocos 1.5.3 → 1.5.5
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/animation/AnimationComponent.js +53 -75
- package/dist/animation/AnimationSystem.js +15 -23
- package/dist/animation/index.js +6 -9
- package/dist/app.js +37 -64
- package/dist/box2d-wasm/ContactListener.d.ts +12 -0
- package/dist/box2d-wasm/ContactListener.d.ts.map +1 -0
- package/dist/box2d-wasm/ContactListener.js +64 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts +50 -0
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsComponent.js +16 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts +12 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSprite.js +51 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts +15 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -0
- package/dist/box2d-wasm/PhysicsSystem.js +139 -0
- package/dist/box2d-wasm/debugDraw.d.ts +66 -0
- package/dist/box2d-wasm/debugDraw.d.ts.map +1 -0
- package/dist/box2d-wasm/debugDraw.js +210 -0
- package/dist/box2d-wasm/index.d.ts +6 -0
- package/dist/box2d-wasm/index.d.ts.map +1 -0
- package/dist/box2d-wasm/index.js +10 -0
- package/dist/collider/CollideComponent.js +98 -159
- package/dist/collider/CollideSystem.js +63 -79
- package/dist/collider/index.js +7 -11
- package/dist/dragonbones/PixiDragonBonesSprite.js +15 -19
- package/dist/dragonbones/index.js +38 -68
- package/dist/gworld/components/AnimationComponent.d.ts +2 -2
- package/dist/gworld/components/CollideComponent.d.ts +3 -3
- package/dist/gworld/components/EnhancedComponent.js +29 -36
- package/dist/gworld/components/GUIComponent.js +50 -118
- package/dist/gworld/components/NoRenderComponent.js +25 -65
- package/dist/gworld/components/NodeComp.d.ts.map +1 -1
- package/dist/gworld/components/NodeComp.js +237 -317
- package/dist/gworld/components/RenderComponent.js +46 -104
- package/dist/gworld/core/NodePool.js +13 -20
- package/dist/gworld/core/Scene.js +11 -35
- package/dist/gworld/core/decorator.js +12 -42
- package/dist/gworld/index.js +13 -42
- package/dist/gworld/systems/CollideSystem.d.ts +1 -2
- package/dist/gworld/systems/CollideSystem.d.ts.map +1 -1
- package/dist/gworld/systems/CollideSystem.js +2 -12
- package/dist/gworld/systems/GUISystem.js +105 -120
- package/dist/gworld/systems/NoRenderSystem.d.ts.map +1 -1
- package/dist/gworld/systems/NoRenderSystem.js +70 -80
- package/dist/gworld/systems/RenderSystem.js +64 -78
- package/dist/helper/Intersection.js +33 -40
- package/dist/helper/action.js +8 -21
- package/dist/helper/director.js +2 -6
- package/dist/helper/math.js +9 -15
- package/dist/helper/utils.js +28 -37
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -31
- package/dist/polyfills.js +69 -97
- package/dist/richtext/RichTextComp.js +27 -55
- package/dist/richtext/RichTextSystem.js +17 -25
- package/dist/richtext/html-text-parser.js +36 -40
- package/dist/richtext/index.js +5 -8
- package/dist/safex.js +1 -2
- package/dist/spine/CCSkeleton.d.ts.map +1 -1
- package/dist/spine/CCSkeleton.js +25 -61
- package/dist/spine/CCSkeletonAnimation.js +18 -54
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +1 -1
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +1 -1
- package/dist/spine/CCSkeletonCanvasRenderCmd.js +39 -43
- package/dist/spine/CCSkeletonTexture.js +4 -40
- package/dist/spine/CCSkeletonWebGLRenderCmd.js +56 -92
- package/dist/spine/index.js +37 -63
- package/package.json +4 -1
- package/dist/dragonbones/cocos/CocosArmatureDisplay.d.ts +0 -77
- package/dist/dragonbones/cocos/CocosArmatureDisplay.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosArmatureDisplay.js +0 -227
- package/dist/dragonbones/cocos/CocosFactory.d.ts +0 -128
- package/dist/dragonbones/cocos/CocosFactory.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosFactory.js +0 -231
- package/dist/dragonbones/cocos/CocosSlot.d.ts +0 -49
- package/dist/dragonbones/cocos/CocosSlot.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosSlot.js +0 -385
- package/dist/dragonbones/cocos/CocosTextureAtlasData.d.ts +0 -53
- package/dist/dragonbones/cocos/CocosTextureAtlasData.d.ts.map +0 -1
- package/dist/dragonbones/cocos/CocosTextureAtlasData.js +0 -158
- package/dist/dragonbones/dragonBones.d.ts +0 -3
- package/dist/dragonbones/dragonBones.d.ts.map +0 -1
- package/dist/dragonbones/dragonBones.js +0 -4788
- package/dist/helper/NodePool.d.ts +0 -9
- package/dist/helper/NodePool.d.ts.map +0 -1
- package/dist/helper/NodePool.js +0 -29
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AnimationComp = exports.AnimationClip = exports.WrapMode = void 0;
|
|
19
|
-
var EnhancedComponent_1 = require("../gworld/components/EnhancedComponent");
|
|
20
|
-
var RenderComponent_1 = require("../gworld/components/RenderComponent");
|
|
21
|
-
var WrapMode;
|
|
1
|
+
import { EnhancedComponent } from '../gworld/components/EnhancedComponent';
|
|
2
|
+
import { SpriteRender } from '../gworld/components/RenderComponent';
|
|
3
|
+
export var WrapMode;
|
|
22
4
|
(function (WrapMode) {
|
|
23
5
|
WrapMode[WrapMode["Default"] = 0] = "Default";
|
|
24
6
|
WrapMode[WrapMode["Normal"] = 1] = "Normal";
|
|
@@ -27,58 +9,56 @@ var WrapMode;
|
|
|
27
9
|
WrapMode[WrapMode["Reverse"] = 36] = "Reverse";
|
|
28
10
|
WrapMode[WrapMode["LoopReverse"] = 38] = "LoopReverse";
|
|
29
11
|
WrapMode[WrapMode["PingPongReverse"] = 54] = "PingPongReverse";
|
|
30
|
-
})(WrapMode || (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}());
|
|
42
|
-
exports.AnimationClip = AnimationClip;
|
|
12
|
+
})(WrapMode || (WrapMode = {}));
|
|
13
|
+
export class AnimationClip {
|
|
14
|
+
static WrapMode = WrapMode;
|
|
15
|
+
sample = 60;
|
|
16
|
+
speed = 1;
|
|
17
|
+
wrapMode = WrapMode.Normal;
|
|
18
|
+
events = [];
|
|
19
|
+
duration = 0;
|
|
20
|
+
name;
|
|
21
|
+
curveData;
|
|
22
|
+
}
|
|
43
23
|
// cc.AnimationClip = AnimationClip;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
24
|
+
export class AnimationComp extends EnhancedComponent {
|
|
25
|
+
defaultClip;
|
|
26
|
+
clips;
|
|
27
|
+
playOnLoad;
|
|
28
|
+
isPaused = true;
|
|
29
|
+
elapsed = 0;
|
|
30
|
+
currentClip;
|
|
31
|
+
constructor(defaultClip, clips, playOnLoad) {
|
|
32
|
+
super();
|
|
33
|
+
this.defaultClip = defaultClip;
|
|
34
|
+
this.clips = clips;
|
|
35
|
+
this.playOnLoad = playOnLoad;
|
|
54
36
|
}
|
|
55
|
-
|
|
56
|
-
var _this = this;
|
|
37
|
+
start() {
|
|
57
38
|
if (this.playOnLoad) {
|
|
58
|
-
setTimeout(
|
|
59
|
-
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
this.play();
|
|
60
41
|
}, 0);
|
|
61
42
|
}
|
|
62
43
|
// cc.log(this.clips);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
var _this = this;
|
|
44
|
+
}
|
|
45
|
+
update(dt) {
|
|
66
46
|
if (this.isPaused || !this.node.active) {
|
|
67
47
|
return;
|
|
68
48
|
}
|
|
69
|
-
|
|
49
|
+
const { curveData, wrapMode, events, duration, speed } = this.currentClip;
|
|
70
50
|
this.elapsed += dt * speed;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
events.forEach(
|
|
74
|
-
|
|
75
|
-
if (!isCalled &&
|
|
51
|
+
const { spriteFrame, nextFrame } = curveData.comps;
|
|
52
|
+
const nextFrameTime = spriteFrame[nextFrame].frame;
|
|
53
|
+
events.forEach((evt) => {
|
|
54
|
+
const { func, frame, params, isCalled } = evt;
|
|
55
|
+
if (!isCalled && this.elapsed >= frame) {
|
|
76
56
|
evt.isCalled = true;
|
|
77
57
|
// this.node.emit(func, ...params)
|
|
78
58
|
}
|
|
79
59
|
});
|
|
80
60
|
if (this.elapsed >= nextFrameTime) {
|
|
81
|
-
|
|
61
|
+
const imageComp = this.node.getComponent(SpriteRender);
|
|
82
62
|
if (imageComp) {
|
|
83
63
|
imageComp.spriteFrame = spriteFrame[nextFrame].value;
|
|
84
64
|
}
|
|
@@ -89,7 +69,7 @@ var AnimationComp = /** @class */ (function (_super) {
|
|
|
89
69
|
if (wrapMode === WrapMode.Loop) {
|
|
90
70
|
curveData.comps.nextFrame = 0;
|
|
91
71
|
this.elapsed = 0;
|
|
92
|
-
events.forEach(
|
|
72
|
+
events.forEach((evt) => {
|
|
93
73
|
evt.isCalled = false;
|
|
94
74
|
});
|
|
95
75
|
}
|
|
@@ -98,13 +78,13 @@ var AnimationComp = /** @class */ (function (_super) {
|
|
|
98
78
|
}
|
|
99
79
|
}
|
|
100
80
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
81
|
+
}
|
|
82
|
+
getAnimationState(name) {
|
|
103
83
|
return {
|
|
104
84
|
isPlaying: !this.isPaused,
|
|
105
85
|
};
|
|
106
|
-
}
|
|
107
|
-
|
|
86
|
+
}
|
|
87
|
+
play(name) {
|
|
108
88
|
this.elapsed = 0;
|
|
109
89
|
// cc.log('play', name, this.defaultClip.name);
|
|
110
90
|
if (!name) {
|
|
@@ -116,26 +96,24 @@ var AnimationComp = /** @class */ (function (_super) {
|
|
|
116
96
|
else if (this.currentClip && name === this.currentClip.name) {
|
|
117
97
|
return;
|
|
118
98
|
}
|
|
119
|
-
this.currentClip = this.clips.find(
|
|
99
|
+
this.currentClip = this.clips.find((clip) => clip.name === name);
|
|
120
100
|
this.currentClip.curveData.comps.nextFrame = 0;
|
|
121
101
|
// cc.log('name', name, this.currentClip);
|
|
122
|
-
this.currentClip.events.forEach(
|
|
102
|
+
this.currentClip.events.forEach((evt) => {
|
|
123
103
|
evt.isCalled = false;
|
|
124
104
|
});
|
|
125
105
|
this.isPaused = false;
|
|
126
|
-
}
|
|
127
|
-
|
|
106
|
+
}
|
|
107
|
+
pause() {
|
|
128
108
|
this.node.instance.pause();
|
|
129
109
|
this.isPaused = true;
|
|
130
|
-
}
|
|
131
|
-
|
|
110
|
+
}
|
|
111
|
+
resume() {
|
|
132
112
|
this.node.instance.resume();
|
|
133
113
|
this.isPaused = false;
|
|
134
|
-
}
|
|
135
|
-
|
|
114
|
+
}
|
|
115
|
+
stop(name) {
|
|
136
116
|
this.node.instance.unscheduleAllCallbacks();
|
|
137
117
|
this.isPaused = true;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
}(EnhancedComponent_1.EnhancedComponent));
|
|
141
|
-
exports.AnimationComp = AnimationComp;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
AnimationSystem.prototype.configure = function (event_manager) {
|
|
11
|
-
event_manager.subscribe(entityx_ts_1.EventTypes.ComponentAdded, AnimationComponent_1.AnimationComp, function (_a) {
|
|
12
|
-
var entity = _a.entity;
|
|
13
|
-
var animation = entity.getComponent(AnimationComponent_1.AnimationComp);
|
|
14
|
-
animation.node = entity.getComponent(NodeComp_1.NodeComp);
|
|
1
|
+
import { EventTypes } from 'entityx-ts';
|
|
2
|
+
import { NodeComp } from '../gworld/components/NodeComp';
|
|
3
|
+
import { AnimationComp } from './AnimationComponent';
|
|
4
|
+
export class AnimationSystem {
|
|
5
|
+
configure(event_manager) {
|
|
6
|
+
event_manager.subscribe(EventTypes.ComponentAdded, AnimationComp, ({ entity }) => {
|
|
7
|
+
const animation = entity.getComponent(AnimationComp);
|
|
8
|
+
animation.node = entity.getComponent(NodeComp);
|
|
15
9
|
setTimeout(animation.start.bind(animation), 0);
|
|
16
10
|
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
}
|
|
12
|
+
update(entities, events, dt) {
|
|
13
|
+
const animations = entities.entities_with_components(AnimationComp);
|
|
20
14
|
// cc.log(animations);
|
|
21
|
-
animations.forEach(
|
|
22
|
-
|
|
15
|
+
animations.forEach((ett) => {
|
|
16
|
+
const animation = ett.getComponent(AnimationComp);
|
|
23
17
|
if (animation.node && animation.node.active) {
|
|
24
18
|
animation.update(dt);
|
|
25
19
|
}
|
|
26
20
|
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}());
|
|
30
|
-
exports.AnimationSystem = AnimationSystem;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/animation/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
gworld_1.GameWorld.Instance.systems.add(AnimationSystem_1.AnimationSystem);
|
|
8
|
-
gworld_1.GameWorld.Instance.listUpdate.push(AnimationSystem_1.AnimationSystem);
|
|
9
|
-
gworld_1.GameWorld.Instance.systems.configureOnce(AnimationSystem_1.AnimationSystem);
|
|
1
|
+
import { GameWorld } from '../gworld';
|
|
2
|
+
import { AnimationSystem } from './AnimationSystem';
|
|
3
|
+
export function setupAnimation() {
|
|
4
|
+
GameWorld.Instance.systems.add(AnimationSystem);
|
|
5
|
+
GameWorld.Instance.listUpdate.push(AnimationSystem);
|
|
6
|
+
GameWorld.Instance.systems.configureOnce(AnimationSystem);
|
|
10
7
|
}
|
package/dist/app.js
CHANGED
|
@@ -1,64 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.audioEngine = void 0;
|
|
19
|
-
exports.initWorld = initWorld;
|
|
20
|
-
exports.startGame = startGame;
|
|
21
|
-
exports.loadAll = loadAll;
|
|
22
|
-
exports.loadJsonFromCache = loadJsonFromCache;
|
|
23
|
-
var CollideSystem_1 = require("./collider/CollideSystem");
|
|
24
|
-
var gworld_1 = require("./gworld");
|
|
25
|
-
var GUISystem_1 = require("./gworld/systems/GUISystem");
|
|
26
|
-
var NoRenderSystem_1 = require("./gworld/systems/NoRenderSystem");
|
|
27
|
-
var RenderSystem_1 = require("./gworld/systems/RenderSystem");
|
|
28
|
-
function initWorld(defaultFont) {
|
|
29
|
-
gworld_1.GameWorld.Instance.systems.add(RenderSystem_1.RenderSystem);
|
|
30
|
-
gworld_1.GameWorld.Instance.systems.add(CollideSystem_1.CollideSystem);
|
|
31
|
-
gworld_1.GameWorld.Instance.systems.add(GUISystem_1.GUISystem);
|
|
32
|
-
gworld_1.GameWorld.Instance.systems.add(NoRenderSystem_1.NoRenderSystem);
|
|
33
|
-
gworld_1.GameWorld.Instance.listUpdate.push(CollideSystem_1.CollideSystem);
|
|
34
|
-
gworld_1.GameWorld.Instance.systems.configureOnce(RenderSystem_1.RenderSystem);
|
|
35
|
-
gworld_1.GameWorld.Instance.systems.configureOnce(CollideSystem_1.CollideSystem);
|
|
36
|
-
gworld_1.GameWorld.Instance.systems.configureOnce(GUISystem_1.GUISystem);
|
|
37
|
-
gworld_1.GameWorld.Instance.systems.configureOnce(NoRenderSystem_1.NoRenderSystem);
|
|
1
|
+
import { CollideSystem } from './collider/CollideSystem';
|
|
2
|
+
import { GameWorld } from './gworld';
|
|
3
|
+
import { GUISystem } from './gworld/systems/GUISystem';
|
|
4
|
+
import { NoRenderSystem } from './gworld/systems/NoRenderSystem';
|
|
5
|
+
import { RenderSystem } from './gworld/systems/RenderSystem';
|
|
6
|
+
export function initWorld(defaultFont) {
|
|
7
|
+
GameWorld.Instance.systems.add(RenderSystem);
|
|
8
|
+
GameWorld.Instance.systems.add(CollideSystem);
|
|
9
|
+
GameWorld.Instance.systems.add(GUISystem);
|
|
10
|
+
GameWorld.Instance.systems.add(NoRenderSystem);
|
|
11
|
+
GameWorld.Instance.listUpdate.push(CollideSystem);
|
|
12
|
+
GameWorld.Instance.systems.configureOnce(RenderSystem);
|
|
13
|
+
GameWorld.Instance.systems.configureOnce(CollideSystem);
|
|
14
|
+
GameWorld.Instance.systems.configureOnce(GUISystem);
|
|
15
|
+
GameWorld.Instance.systems.configureOnce(NoRenderSystem);
|
|
38
16
|
if (defaultFont) {
|
|
39
|
-
|
|
17
|
+
const guiSystem = GameWorld.Instance.systems.get(GUISystem);
|
|
40
18
|
guiSystem.defaultFont = defaultFont;
|
|
41
19
|
}
|
|
42
20
|
}
|
|
43
|
-
function startGame(option,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
_super.prototype.ctor.call(_this); // always call this for compatibility with cocos2dx JS Javascript class system
|
|
50
|
-
_this.scheduleUpdate();
|
|
51
|
-
return _this;
|
|
21
|
+
export function startGame(option, { width, height }, cb) {
|
|
22
|
+
class BootScene extends cc.Scene {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
super.ctor(); // always call this for compatibility with cocos2dx JS Javascript class system
|
|
26
|
+
this.scheduleUpdate();
|
|
52
27
|
}
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
onEnter() {
|
|
29
|
+
super.onEnter();
|
|
55
30
|
cb();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}(cc.Scene));
|
|
31
|
+
}
|
|
32
|
+
update(dt) {
|
|
33
|
+
GameWorld.Instance.update(dt);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
62
36
|
cc._isContextMenuEnable = true;
|
|
63
37
|
cc.game.run(option, function onStart() {
|
|
64
38
|
// Pass true to enable retina display, disabled by default to improve performance
|
|
@@ -66,16 +40,15 @@ function startGame(option, _a, cb) {
|
|
|
66
40
|
// Adjust viewport meta
|
|
67
41
|
cc.view.adjustViewPort(true);
|
|
68
42
|
// Setup the resolution policy and design resolution size
|
|
69
|
-
|
|
43
|
+
const policy = width > height ? cc.ResolutionPolicy.FIXED_HEIGHT : cc.ResolutionPolicy.FIXED_WIDTH;
|
|
70
44
|
cc.view.setDesignResolutionSize(width, height, policy);
|
|
71
45
|
// The game will be resized when browser size change
|
|
72
46
|
cc.view.resizeWithBrowserSize(true);
|
|
73
47
|
cc.director.runScene(new BootScene());
|
|
74
48
|
});
|
|
75
49
|
}
|
|
76
|
-
function loadAll(assets, cb) {
|
|
77
|
-
|
|
78
|
-
cc.loader.load(assets.map(function (value) {
|
|
50
|
+
export function loadAll(assets = [], cb) {
|
|
51
|
+
cc.loader.load(assets.map((value) => {
|
|
79
52
|
if (value.endsWith('.ttf')) {
|
|
80
53
|
return {
|
|
81
54
|
type: 'font',
|
|
@@ -88,20 +61,20 @@ function loadAll(assets, cb) {
|
|
|
88
61
|
// console.log(result)
|
|
89
62
|
if (result instanceof cc.Texture2D) {
|
|
90
63
|
// cc.textureCache.addImage(result.url)
|
|
91
|
-
|
|
64
|
+
const frame = new cc.SpriteFrame(result.url, cc.rect(0, 0, result.getPixelsWide(), result.getPixelsHigh()));
|
|
92
65
|
// console.log('cc.Texture2D', result, frame)
|
|
93
66
|
cc.spriteFrameCache.addSpriteFrame(frame, result.url);
|
|
94
67
|
}
|
|
95
|
-
|
|
68
|
+
let percent = loadedCount / count;
|
|
96
69
|
percent = Math.min(percent, 1);
|
|
97
70
|
cb(percent);
|
|
98
71
|
}, function () {
|
|
99
72
|
setTimeout(cb, 500, 1);
|
|
100
73
|
});
|
|
101
74
|
}
|
|
102
|
-
function loadJsonFromCache(filePath) {
|
|
103
|
-
|
|
75
|
+
export function loadJsonFromCache(filePath) {
|
|
76
|
+
const res = cc.loader.getRes(filePath);
|
|
104
77
|
// console.log(filePath, res)
|
|
105
78
|
return res;
|
|
106
79
|
}
|
|
107
|
-
|
|
80
|
+
export const audioEngine = cc.audioEngine;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NodeComp } from '..';
|
|
2
|
+
type Meta = {
|
|
3
|
+
[key: number]: NodeComp;
|
|
4
|
+
};
|
|
5
|
+
export declare const makeContactListener: (world: Box2D.b2World, metadata: Meta, box2D: typeof Box2D) => Box2D.JSContactListener & {
|
|
6
|
+
BeginContact(contact: Box2D.b2Contact | number): void;
|
|
7
|
+
EndContact(contact: Box2D.b2Contact | number): void;
|
|
8
|
+
PreSolve(contact: Box2D.b2Contact | number, oldManifold: Box2D.b2Manifold | number): void;
|
|
9
|
+
PostSolve(contact: Box2D.b2Contact | number, impulse: Box2D.b2ContactImpulse | number): void;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ContactListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContactListener.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/ContactListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAG7B,KAAK,IAAI,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AACvC,eAAO,MAAM,mBAAmB,GAAI,OAAO,KAAK,CAAC,OAAO,EAAE,UAAU,IAAI,EAAE,OAAO,OAAO,KAAK;0BAWnE,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;wBAwBjC,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;sBAmBjC,KAAK,CAAC,SAAS,GAAG,MAAM,eAAe,KAAK,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI;uBAGtE,KAAK,CAAC,SAAS,GAAG,MAAM,WAAW,KAAK,CAAC,gBAAgB,GAAG,MAAM,GAAG,IAAI;CAK/F,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ColliderPhysics } from './PhysicsComponent';
|
|
2
|
+
export const makeContactListener = (world, metadata, box2D) => {
|
|
3
|
+
const { JSContactListener, getPointer, NULL } = box2D;
|
|
4
|
+
function getContactById(contact) {
|
|
5
|
+
for (let contactList = world.GetContactList(); getPointer(contactList) !== getPointer(NULL); contactList = contactList.GetNext()) {
|
|
6
|
+
if (getPointer(contactList) === contact) {
|
|
7
|
+
console.log('contactBegin', contact, getPointer(contactList), getPointer(NULL));
|
|
8
|
+
return contactList;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const listener = Object.assign(new JSContactListener(), {
|
|
13
|
+
BeginContact(contact) {
|
|
14
|
+
if (typeof contact === 'number') {
|
|
15
|
+
contact = getContactById(contact);
|
|
16
|
+
}
|
|
17
|
+
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
18
|
+
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
19
|
+
// world.addPostStepCallback(() => {
|
|
20
|
+
// // log('addPostStepCallback');
|
|
21
|
+
// listRemoveShape.forEach((s) => world.removeShape(s))
|
|
22
|
+
// listRemoveBody.forEach((b) => world.removeBody(b))
|
|
23
|
+
// listRemoveBody = []
|
|
24
|
+
// listRemoveShape = []
|
|
25
|
+
// })
|
|
26
|
+
const phys1 = ett1.getComponent(ColliderPhysics);
|
|
27
|
+
const phys2 = ett2.getComponent(ColliderPhysics);
|
|
28
|
+
if (phys1 && phys2) {
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionEnter')) {
|
|
30
|
+
phys1.props.onCollisionEnter(phys2);
|
|
31
|
+
}
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionEnter')) {
|
|
33
|
+
phys2.props.onCollisionEnter(phys1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
EndContact(contact) {
|
|
38
|
+
if (typeof contact === 'number') {
|
|
39
|
+
contact = getContactById(contact);
|
|
40
|
+
}
|
|
41
|
+
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
42
|
+
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
43
|
+
// const event1 = ett1.getComponent(NodeComp)
|
|
44
|
+
const phys1 = ett1.getComponent(ColliderPhysics);
|
|
45
|
+
const phys2 = ett2.getComponent(ColliderPhysics);
|
|
46
|
+
// const event2 = ett2.getComponent(NodeComp)
|
|
47
|
+
if (phys1 && phys2) {
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionExit')) {
|
|
49
|
+
phys1.props.onCollisionExit(phys2);
|
|
50
|
+
}
|
|
51
|
+
if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionExit')) {
|
|
52
|
+
phys2.props.onCollisionExit(phys1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
PreSolve(contact, oldManifold) {
|
|
57
|
+
console.log('collisionSeparate');
|
|
58
|
+
},
|
|
59
|
+
PostSolve(contact, impulse) {
|
|
60
|
+
console.log('collisionPost');
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return listener;
|
|
64
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { NoRenderComponentX } from '../gworld/core/decorator';
|
|
2
|
+
import { Vec2 } from '../polyfills';
|
|
3
|
+
import { PhysicsSprite } from './PhysicsSprite';
|
|
4
|
+
interface RigidBodyProps {
|
|
5
|
+
type?: 'static' | 'dynamic';
|
|
6
|
+
density?: Float;
|
|
7
|
+
restitution?: Float;
|
|
8
|
+
friction?: Float;
|
|
9
|
+
gravityScale?: Float;
|
|
10
|
+
}
|
|
11
|
+
export declare class RigidBody extends NoRenderComponentX<RigidBodyProps> {
|
|
12
|
+
body: Box2D.b2Body;
|
|
13
|
+
}
|
|
14
|
+
interface PhysicsMaterialProps {
|
|
15
|
+
friction?: number;
|
|
16
|
+
restitution?: number;
|
|
17
|
+
density?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class PhysicsMaterial extends NoRenderComponentX<PhysicsMaterialProps> {
|
|
20
|
+
}
|
|
21
|
+
interface ColliderPhysicsProps {
|
|
22
|
+
tag?: number;
|
|
23
|
+
group?: number;
|
|
24
|
+
offset?: Vec2;
|
|
25
|
+
onCollisionEnter?: (other: ColliderPhysics) => void;
|
|
26
|
+
onCollisionExit?: (other: ColliderPhysics) => void;
|
|
27
|
+
onCollisionStay?: (other: ColliderPhysics) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare class ColliderPhysics<T extends ColliderPhysicsProps = ColliderPhysicsProps> extends NoRenderComponentX<T, PhysicsSprite['node']> {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
instance: PhysicsSprite;
|
|
32
|
+
}
|
|
33
|
+
interface BoxColliderPhysicsProps extends ColliderPhysicsProps {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
}
|
|
37
|
+
export declare class BoxColliderPhysics extends ColliderPhysics<BoxColliderPhysicsProps> {
|
|
38
|
+
}
|
|
39
|
+
interface CircleColliderPhysicsProps extends ColliderPhysicsProps {
|
|
40
|
+
radius: number;
|
|
41
|
+
}
|
|
42
|
+
export declare class CircleColliderPhysics extends ColliderPhysics<CircleColliderPhysicsProps> {
|
|
43
|
+
}
|
|
44
|
+
interface PolygonColliderPhysicsProps extends ColliderPhysicsProps {
|
|
45
|
+
points: Array<Vec2>;
|
|
46
|
+
}
|
|
47
|
+
export declare class PolygonColliderPhysics extends ColliderPhysics<PolygonColliderPhysicsProps> {
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=PhysicsComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC3B,OAAO,CAAC,EAAE,KAAK,CAAA;IACf,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,YAAY,CAAC,EAAE,KAAK,CAAA;CACrB;AAED,qBAAa,SAAU,SAAQ,kBAAkB,CAAC,cAAc,CAAC;IAC/D,IAAI,EAAE,KAAK,CAAC,MAAM,CAAA;CAmBnB;AAED,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AACD,qBAAa,eAAgB,SAAQ,kBAAkB,CAAC,oBAAoB,CAAC;CAAG;AAEhF,UAAU,oBAAoB;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,IAAI,CAAA;IACb,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;IACnD,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;IAClD,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;CACnD;AAED,qBAAa,eAAe,CAAC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,kBAAkB,CAAC,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtI,OAAO,UAAO;IACd,QAAQ,EAAE,aAAa,CAAA;CACxB;AAED,UAAU,uBAAwB,SAAQ,oBAAoB;IAC5D,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AACD,qBAAa,kBAAmB,SAAQ,eAAe,CAAC,uBAAuB,CAAC;CAS/E;AACD,UAAU,0BAA2B,SAAQ,oBAAoB;IAC/D,MAAM,EAAE,MAAM,CAAA;CACf;AACD,qBAAa,qBAAsB,SAAQ,eAAe,CAAC,0BAA0B,CAAC;CAAG;AACzF,UAAU,2BAA4B,SAAQ,oBAAoB;IAChE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;CACpB;AACD,qBAAa,sBAAuB,SAAQ,eAAe,CAAC,2BAA2B,CAAC;CAAG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NoRenderComponentX } from '../gworld/core/decorator';
|
|
2
|
+
export class RigidBody extends NoRenderComponentX {
|
|
3
|
+
body;
|
|
4
|
+
}
|
|
5
|
+
export class PhysicsMaterial extends NoRenderComponentX {
|
|
6
|
+
}
|
|
7
|
+
export class ColliderPhysics extends NoRenderComponentX {
|
|
8
|
+
enabled = true;
|
|
9
|
+
instance;
|
|
10
|
+
}
|
|
11
|
+
export class BoxColliderPhysics extends ColliderPhysics {
|
|
12
|
+
}
|
|
13
|
+
export class CircleColliderPhysics extends ColliderPhysics {
|
|
14
|
+
}
|
|
15
|
+
export class PolygonColliderPhysics extends ColliderPhysics {
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class PhysicsSprite {
|
|
2
|
+
node: cc.Node;
|
|
3
|
+
physicsBody: Box2D.b2Body;
|
|
4
|
+
constructor(node: cc.Node, body: Box2D.b2Body);
|
|
5
|
+
update(dt: number): void;
|
|
6
|
+
getBody(): Box2D.b2Body;
|
|
7
|
+
get x(): number;
|
|
8
|
+
get y(): number;
|
|
9
|
+
get angle(): number;
|
|
10
|
+
addChild(child: cc.Node): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=PhysicsSprite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhysicsSprite.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSprite.ts"],"names":[],"mappings":"AAEA,qBAAa,aAAa;IACxB,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA;IACb,WAAW,EAAE,KAAK,CAAC,MAAM,CAAA;gBAEb,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM;IAM7C,MAAM,CAAC,EAAE,EAAE,MAAM;IAkBjB,OAAO;IAeP,IAAI,CAAC,WAEJ;IAED,IAAI,CAAC,WAEJ;IAMD,IAAI,KAAK,WAER;IAED,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI;CAGxB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Vec2 } from '../polyfills';
|
|
2
|
+
export class PhysicsSprite {
|
|
3
|
+
node;
|
|
4
|
+
physicsBody;
|
|
5
|
+
constructor(node, body) {
|
|
6
|
+
this.node = node;
|
|
7
|
+
this.physicsBody = body;
|
|
8
|
+
this.node.schedule(this.update.bind(this), 0, cc.REPEAT_FOREVER, 0);
|
|
9
|
+
}
|
|
10
|
+
update(dt) {
|
|
11
|
+
if (!this.physicsBody) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// const pos = this.physicsBody.GetPosition()
|
|
15
|
+
// use cc.lerp to smooth the position update
|
|
16
|
+
const pos = Vec2(cc.lerp(this.node.x, this.physicsBody.GetPosition().x, dt * 10), cc.lerp(this.node.y, this.physicsBody.GetPosition().y, dt * 10));
|
|
17
|
+
this.node.setPosition(pos.x, pos.y);
|
|
18
|
+
// lerp the rotation
|
|
19
|
+
this.node.setRotation(cc.lerp(this.node.rotation, cc.radiansToDegrees(this.physicsBody.GetAngle()), dt * 10));
|
|
20
|
+
// this.node.setRotation(cc.radiansToDegrees(this.physicsBody.GetAngle()))
|
|
21
|
+
// this.node.setScale(1 / pixelsPerMeter)
|
|
22
|
+
// this.node.setScale(1 / this.physicsBody.GetFixtureList().GetShape().GetRadius())
|
|
23
|
+
}
|
|
24
|
+
getBody() {
|
|
25
|
+
return this.physicsBody;
|
|
26
|
+
}
|
|
27
|
+
// set position(val: Box2D.b2Vec2) {
|
|
28
|
+
// this.physicsBody.setPosition(val)
|
|
29
|
+
// }
|
|
30
|
+
// set x(val) {
|
|
31
|
+
// this.physicsBody.setPosition(Vec2(val, this.y))
|
|
32
|
+
// }
|
|
33
|
+
// set y(val) {
|
|
34
|
+
// this.physicsBody.setPosition(Vec2(this.x, val))
|
|
35
|
+
// }
|
|
36
|
+
get x() {
|
|
37
|
+
return this.physicsBody.GetPosition().x;
|
|
38
|
+
}
|
|
39
|
+
get y() {
|
|
40
|
+
return this.physicsBody.GetPosition().x;
|
|
41
|
+
}
|
|
42
|
+
// set angle(val: number) {
|
|
43
|
+
// this.physicsBody.setAngle(val)
|
|
44
|
+
// }
|
|
45
|
+
get angle() {
|
|
46
|
+
return this.physicsBody.GetAngle();
|
|
47
|
+
}
|
|
48
|
+
addChild(child) {
|
|
49
|
+
this.node.addChild(child);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EntityManager, EventManager, System } from 'entityx-ts';
|
|
2
|
+
export declare let box2D: typeof Box2D;
|
|
3
|
+
export declare function initBox2d(cb: any): void;
|
|
4
|
+
export declare function setColliderMatrix(colliderMatrix?: boolean[][]): void;
|
|
5
|
+
export declare class PhysicsSystem implements System {
|
|
6
|
+
world: Box2D.b2World;
|
|
7
|
+
listRemoveBody: Box2D.b2Body[];
|
|
8
|
+
listRemoveShape: Box2D.b2Shape[];
|
|
9
|
+
colliderMatrix: boolean[][];
|
|
10
|
+
graphics: cc.DrawNode;
|
|
11
|
+
configure(event_manager: EventManager): void;
|
|
12
|
+
update(entities: EntityManager, events: EventManager, dt: number): void;
|
|
13
|
+
set enabled(val: any);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=PhysicsSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAe5E,eAAO,IAAI,KAAK,EAAE,OAAO,KAAK,CAAA;AAE9B,wBAAgB,SAAS,CAAC,EAAE,KAAA,QAK3B;AASD,wBAAgB,iBAAiB,CAAC,cAAc,cAAW,QAG1D;AAOD,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,EAAE,KAAK,CAAC,OAAO,CAAA;IACpB,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,CAAK;IACnC,eAAe,EAAE,KAAK,CAAC,OAAO,EAAE,CAAK;IACrC,cAAc,cAAW;IACzB,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAA;IAErB,SAAS,CAAC,aAAa,EAAE,YAAY;IA6ErC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;IAwBhE,IAAI,OAAO,CAAC,GAAG,KAAA,EAMd;CACF"}
|