@safe-engine/cocos 1.5.2 → 1.5.3

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.
@@ -0,0 +1,63 @@
1
+ import { EnhancedComponent } from '../gworld/components/EnhancedComponent';
2
+ export interface IEvent {
3
+ frame: number;
4
+ func: string;
5
+ params: string[];
6
+ isCalled: boolean;
7
+ }
8
+ export declare enum WrapMode {
9
+ Default = 0,
10
+ Normal = 1,
11
+ Loop = 2,
12
+ PingPong = 22,
13
+ Reverse = 36,
14
+ LoopReverse = 38,
15
+ PingPongReverse = 54
16
+ }
17
+ interface AnimProp {
18
+ frame: number;
19
+ value: number;
20
+ }
21
+ interface SpriteFrameProp {
22
+ frame: number;
23
+ value: string;
24
+ }
25
+ interface CurveData {
26
+ comps: {
27
+ spriteFrame: SpriteFrameProp[];
28
+ nextFrame: number;
29
+ };
30
+ props: {
31
+ [key: string]: AnimProp[];
32
+ };
33
+ }
34
+ export declare class AnimationClip {
35
+ static WrapMode: typeof WrapMode;
36
+ sample: number;
37
+ speed: number;
38
+ wrapMode: WrapMode;
39
+ events: IEvent[];
40
+ duration: number;
41
+ name: string;
42
+ curveData: CurveData;
43
+ }
44
+ export declare class AnimationComp extends EnhancedComponent {
45
+ defaultClip: AnimationClip;
46
+ clips: AnimationClip[];
47
+ playOnLoad: boolean;
48
+ private isPaused;
49
+ private elapsed;
50
+ private currentClip;
51
+ constructor(defaultClip: AnimationClip, clips: AnimationClip[], playOnLoad: boolean);
52
+ start(): void;
53
+ update(dt: Float): void;
54
+ getAnimationState(name: string): {
55
+ isPlaying: boolean;
56
+ };
57
+ play(name?: string): void;
58
+ pause(): void;
59
+ resume(): void;
60
+ stop(name?: string): void;
61
+ }
62
+ export {};
63
+ //# sourceMappingURL=AnimationComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimationComponent.d.ts","sourceRoot":"","sources":["../../src/animation/AnimationComponent.ts"],"names":[],"mappings":"AAA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AAU,EAAE,OAAO;IAOnF,KAAK;IASL,MAAM,CAAC,EAAE,EAAE,KAAK;IAqChB,iBAAiB,CAAC,IAAI,EAAE,MAAM;;;IAMvB,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM;IAoBlB,KAAK;IAKL,MAAM;IAKN,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM;CAI1B"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
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;
22
+ (function (WrapMode) {
23
+ WrapMode[WrapMode["Default"] = 0] = "Default";
24
+ WrapMode[WrapMode["Normal"] = 1] = "Normal";
25
+ WrapMode[WrapMode["Loop"] = 2] = "Loop";
26
+ WrapMode[WrapMode["PingPong"] = 22] = "PingPong";
27
+ WrapMode[WrapMode["Reverse"] = 36] = "Reverse";
28
+ WrapMode[WrapMode["LoopReverse"] = 38] = "LoopReverse";
29
+ WrapMode[WrapMode["PingPongReverse"] = 54] = "PingPongReverse";
30
+ })(WrapMode || (exports.WrapMode = WrapMode = {}));
31
+ var AnimationClip = /** @class */ (function () {
32
+ function AnimationClip() {
33
+ this.sample = 60;
34
+ this.speed = 1;
35
+ this.wrapMode = WrapMode.Normal;
36
+ this.events = [];
37
+ this.duration = 0;
38
+ }
39
+ AnimationClip.WrapMode = WrapMode;
40
+ return AnimationClip;
41
+ }());
42
+ exports.AnimationClip = AnimationClip;
43
+ // cc.AnimationClip = AnimationClip;
44
+ var AnimationComp = /** @class */ (function (_super) {
45
+ __extends(AnimationComp, _super);
46
+ function AnimationComp(defaultClip, clips, playOnLoad) {
47
+ var _this = _super.call(this) || this;
48
+ _this.isPaused = true;
49
+ _this.elapsed = 0;
50
+ _this.defaultClip = defaultClip;
51
+ _this.clips = clips;
52
+ _this.playOnLoad = playOnLoad;
53
+ return _this;
54
+ }
55
+ AnimationComp.prototype.start = function () {
56
+ var _this = this;
57
+ if (this.playOnLoad) {
58
+ setTimeout(function () {
59
+ _this.play();
60
+ }, 0);
61
+ }
62
+ // cc.log(this.clips);
63
+ };
64
+ AnimationComp.prototype.update = function (dt) {
65
+ var _this = this;
66
+ if (this.isPaused || !this.node.active) {
67
+ return;
68
+ }
69
+ var _a = this.currentClip, curveData = _a.curveData, wrapMode = _a.wrapMode, events = _a.events, duration = _a.duration, speed = _a.speed;
70
+ this.elapsed += dt * speed;
71
+ var _b = curveData.comps, spriteFrame = _b.spriteFrame, nextFrame = _b.nextFrame;
72
+ var nextFrameTime = spriteFrame[nextFrame].frame;
73
+ events.forEach(function (evt) {
74
+ var func = evt.func, frame = evt.frame, params = evt.params, isCalled = evt.isCalled;
75
+ if (!isCalled && _this.elapsed >= frame) {
76
+ evt.isCalled = true;
77
+ // this.node.emit(func, ...params)
78
+ }
79
+ });
80
+ if (this.elapsed >= nextFrameTime) {
81
+ var imageComp = this.node.getComponent(RenderComponent_1.SpriteRender);
82
+ if (imageComp) {
83
+ imageComp.spriteFrame = spriteFrame[nextFrame].value;
84
+ }
85
+ // cc.log(spriteFrame[nextFrame].value, nextFrameTime);
86
+ curveData.comps.nextFrame += 1;
87
+ curveData.comps.nextFrame = cc.clampf(curveData.comps.nextFrame, 0, spriteFrame.length - 1);
88
+ if (this.elapsed >= duration) {
89
+ if (wrapMode === WrapMode.Loop) {
90
+ curveData.comps.nextFrame = 0;
91
+ this.elapsed = 0;
92
+ events.forEach(function (evt) {
93
+ evt.isCalled = false;
94
+ });
95
+ }
96
+ else {
97
+ this.isPaused = true;
98
+ }
99
+ }
100
+ }
101
+ };
102
+ AnimationComp.prototype.getAnimationState = function (name) {
103
+ return {
104
+ isPlaying: !this.isPaused,
105
+ };
106
+ };
107
+ AnimationComp.prototype.play = function (name) {
108
+ this.elapsed = 0;
109
+ // cc.log('play', name, this.defaultClip.name);
110
+ if (!name) {
111
+ if (!this.defaultClip) {
112
+ return;
113
+ }
114
+ name = this.defaultClip.name;
115
+ }
116
+ else if (this.currentClip && name === this.currentClip.name) {
117
+ return;
118
+ }
119
+ this.currentClip = this.clips.find(function (clip) { return clip.name === name; });
120
+ this.currentClip.curveData.comps.nextFrame = 0;
121
+ // cc.log('name', name, this.currentClip);
122
+ this.currentClip.events.forEach(function (evt) {
123
+ evt.isCalled = false;
124
+ });
125
+ this.isPaused = false;
126
+ };
127
+ AnimationComp.prototype.pause = function () {
128
+ this.node.instance.pause();
129
+ this.isPaused = true;
130
+ };
131
+ AnimationComp.prototype.resume = function () {
132
+ this.node.instance.resume();
133
+ this.isPaused = false;
134
+ };
135
+ AnimationComp.prototype.stop = function (name) {
136
+ this.node.instance.unscheduleAllCallbacks();
137
+ this.isPaused = true;
138
+ };
139
+ return AnimationComp;
140
+ }(EnhancedComponent_1.EnhancedComponent));
141
+ exports.AnimationComp = AnimationComp;
@@ -0,0 +1,6 @@
1
+ import { EntityManager, EventManager, System } from 'entityx-ts';
2
+ export declare class AnimationSystem implements System {
3
+ configure(event_manager: EventManager): void;
4
+ update(entities: EntityManager, events: EventManager, dt: Float): void;
5
+ }
6
+ //# sourceMappingURL=AnimationSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimationSystem.d.ts","sourceRoot":"","sources":["../../src/animation/AnimationSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAK5E,qBAAa,eAAgB,YAAW,MAAM;IAC5C,SAAS,CAAC,aAAa,EAAE,YAAY;IAQrC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,KAAK;CAUhE"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnimationSystem = void 0;
4
+ var entityx_ts_1 = require("entityx-ts");
5
+ var NodeComp_1 = require("../gworld/components/NodeComp");
6
+ var AnimationComponent_1 = require("./AnimationComponent");
7
+ var AnimationSystem = /** @class */ (function () {
8
+ function AnimationSystem() {
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);
15
+ setTimeout(animation.start.bind(animation), 0);
16
+ });
17
+ };
18
+ AnimationSystem.prototype.update = function (entities, events, dt) {
19
+ var animations = entities.entities_with_components(AnimationComponent_1.AnimationComp);
20
+ // cc.log(animations);
21
+ animations.forEach(function (ett) {
22
+ var animation = ett.getComponent(AnimationComponent_1.AnimationComp);
23
+ if (animation.node && animation.node.active) {
24
+ animation.update(dt);
25
+ }
26
+ });
27
+ };
28
+ return AnimationSystem;
29
+ }());
30
+ exports.AnimationSystem = AnimationSystem;
@@ -0,0 +1,2 @@
1
+ export declare function setupAnimation(): void;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/animation/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,SAI7B"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupAnimation = setupAnimation;
4
+ var gworld_1 = require("../gworld");
5
+ var AnimationSystem_1 = require("./AnimationSystem");
6
+ function setupAnimation() {
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);
10
+ }
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,QAY7C;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,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;;;CAAA,EAAE,EAAE,EAAE,MAAM,IAAI,QA+B9E;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAO,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,QA4B5E;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAIxD;AAED,eAAO,MAAM,WAAW,uBAAiB,CAAA"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,QAc7C;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,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;;;CAAA,EAAE,EAAE,EAAE,MAAM,IAAI,QA+B9E;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAO,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,QA4B5E;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAIxD;AAED,eAAO,MAAM,WAAW,uBAAiB,CAAA"}
package/dist/app.js CHANGED
@@ -35,8 +35,10 @@ function initWorld(defaultFont) {
35
35
  gworld_1.GameWorld.Instance.systems.configureOnce(CollideSystem_1.CollideSystem);
36
36
  gworld_1.GameWorld.Instance.systems.configureOnce(GUISystem_1.GUISystem);
37
37
  gworld_1.GameWorld.Instance.systems.configureOnce(NoRenderSystem_1.NoRenderSystem);
38
- var guiSystem = gworld_1.GameWorld.Instance.systems.get(GUISystem_1.GUISystem);
39
- guiSystem.defaultFont = defaultFont;
38
+ if (defaultFont) {
39
+ var guiSystem = gworld_1.GameWorld.Instance.systems.get(GUISystem_1.GUISystem);
40
+ guiSystem.defaultFont = defaultFont;
41
+ }
40
42
  }
41
43
  function startGame(option, _a, cb) {
42
44
  var width = _a.width, height = _a.height;
@@ -1,2 +1,2 @@
1
- export declare function setupCollider(): void;
1
+ export declare function setupCollider(colliderMatrix?: any, debug?: boolean): void;
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collider/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,SAI5B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collider/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CAAC,cAAc,CAAC,KAAA,EAAE,KAAK,UAAQ,QAS3D"}
@@ -3,8 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupCollider = setupCollider;
4
4
  var gworld_1 = require("../gworld");
5
5
  var CollideSystem_1 = require("./CollideSystem");
6
- function setupCollider() {
6
+ function setupCollider(colliderMatrix, debug) {
7
+ if (debug === void 0) { debug = false; }
7
8
  gworld_1.GameWorld.Instance.systems.add(CollideSystem_1.CollideSystem);
8
9
  gworld_1.GameWorld.Instance.listUpdate.push(CollideSystem_1.CollideSystem);
9
10
  gworld_1.GameWorld.Instance.systems.configureOnce(CollideSystem_1.CollideSystem);
11
+ var collideSystem = gworld_1.GameWorld.Instance.systems.get(CollideSystem_1.CollideSystem);
12
+ if (colliderMatrix) {
13
+ collideSystem.colliderMatrix = colliderMatrix;
14
+ }
15
+ collideSystem.toggleDebugDraw(debug);
10
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@safe-engine/cocos",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "safe-engine with cocos renderer support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",