@safe-engine/cocos 1.0.1
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/@types/index.d.ts +61 -0
- package/@types/safex.d.ts +103 -0
- package/README.md +10 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +24 -0
- package/dist/dragonbones/cocos/CocosArmatureDisplay.d.ts +77 -0
- package/dist/dragonbones/cocos/CocosArmatureDisplay.d.ts.map +1 -0
- package/dist/dragonbones/cocos/CocosArmatureDisplay.js +227 -0
- package/dist/dragonbones/cocos/CocosFactory.d.ts +128 -0
- package/dist/dragonbones/cocos/CocosFactory.d.ts.map +1 -0
- package/dist/dragonbones/cocos/CocosFactory.js +231 -0
- package/dist/dragonbones/cocos/CocosSlot.d.ts +49 -0
- package/dist/dragonbones/cocos/CocosSlot.d.ts.map +1 -0
- package/dist/dragonbones/cocos/CocosSlot.js +385 -0
- package/dist/dragonbones/cocos/CocosTextureAtlasData.d.ts +53 -0
- package/dist/dragonbones/cocos/CocosTextureAtlasData.d.ts.map +1 -0
- package/dist/dragonbones/cocos/CocosTextureAtlasData.js +158 -0
- package/dist/dragonbones/dragonBones.d.ts +3 -0
- package/dist/dragonbones/dragonBones.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones.js +4788 -0
- package/dist/dragonbones/index.d.ts +20 -0
- package/dist/dragonbones/index.d.ts.map +1 -0
- package/dist/dragonbones/index.js +112 -0
- package/dist/gworld/components/AnimationComponent.d.ts +65 -0
- package/dist/gworld/components/AnimationComponent.d.ts.map +1 -0
- package/dist/gworld/components/AnimationComponent.js +141 -0
- package/dist/gworld/components/CollideComponent.d.ts +64 -0
- package/dist/gworld/components/CollideComponent.d.ts.map +1 -0
- package/dist/gworld/components/CollideComponent.js +266 -0
- package/dist/gworld/components/EnhancedComponent.d.ts +21 -0
- package/dist/gworld/components/EnhancedComponent.d.ts.map +1 -0
- package/dist/gworld/components/EnhancedComponent.js +50 -0
- package/dist/gworld/components/GUIComponent.d.ts +62 -0
- package/dist/gworld/components/GUIComponent.d.ts.map +1 -0
- package/dist/gworld/components/GUIComponent.js +158 -0
- package/dist/gworld/components/NoRenderComponent.d.ts +36 -0
- package/dist/gworld/components/NoRenderComponent.d.ts.map +1 -0
- package/dist/gworld/components/NoRenderComponent.js +74 -0
- package/dist/gworld/components/NodeComp.d.ts +184 -0
- package/dist/gworld/components/NodeComp.d.ts.map +1 -0
- package/dist/gworld/components/NodeComp.js +425 -0
- package/dist/gworld/components/RenderComponent.d.ts +53 -0
- package/dist/gworld/components/RenderComponent.d.ts.map +1 -0
- package/dist/gworld/components/RenderComponent.js +158 -0
- package/dist/gworld/core/Scene.d.ts +5 -0
- package/dist/gworld/core/Scene.d.ts.map +1 -0
- package/dist/gworld/core/Scene.js +38 -0
- package/dist/gworld/core/decorator.d.ts +9 -0
- package/dist/gworld/core/decorator.d.ts.map +1 -0
- package/dist/gworld/core/decorator.js +43 -0
- package/dist/gworld/index.d.ts +8 -0
- package/dist/gworld/index.d.ts.map +1 -0
- package/dist/gworld/index.js +43 -0
- package/dist/gworld/systems/AnimationSystem.d.ts +7 -0
- package/dist/gworld/systems/AnimationSystem.d.ts.map +1 -0
- package/dist/gworld/systems/AnimationSystem.js +38 -0
- package/dist/gworld/systems/CollideSystem.d.ts +19 -0
- package/dist/gworld/systems/CollideSystem.d.ts.map +1 -0
- package/dist/gworld/systems/CollideSystem.js +183 -0
- package/dist/gworld/systems/GUISystem.d.ts +7 -0
- package/dist/gworld/systems/GUISystem.d.ts.map +1 -0
- package/dist/gworld/systems/GUISystem.js +147 -0
- package/dist/gworld/systems/NoRenderSystem.d.ts +7 -0
- package/dist/gworld/systems/NoRenderSystem.d.ts.map +1 -0
- package/dist/gworld/systems/NoRenderSystem.js +93 -0
- package/dist/gworld/systems/RenderSystem.d.ts +15 -0
- package/dist/gworld/systems/RenderSystem.d.ts.map +1 -0
- package/dist/gworld/systems/RenderSystem.js +115 -0
- package/dist/helper/Intersection.d.ts +6 -0
- package/dist/helper/Intersection.d.ts.map +1 -0
- package/dist/helper/Intersection.js +117 -0
- package/dist/helper/NodePool.d.ts +9 -0
- package/dist/helper/NodePool.d.ts.map +1 -0
- package/dist/helper/NodePool.js +29 -0
- package/dist/helper/action.d.ts +9 -0
- package/dist/helper/action.d.ts.map +1 -0
- package/dist/helper/action.js +34 -0
- package/dist/helper/director.d.ts +3 -0
- package/dist/helper/director.d.ts.map +1 -0
- package/dist/helper/director.js +10 -0
- package/dist/helper/html-text-parser.d.ts +30 -0
- package/dist/helper/html-text-parser.d.ts.map +1 -0
- package/dist/helper/html-text-parser.js +354 -0
- package/dist/helper/math.d.ts +4 -0
- package/dist/helper/math.d.ts.map +1 -0
- package/dist/helper/math.js +9 -0
- package/dist/helper/utils.d.ts +14 -0
- package/dist/helper/utils.d.ts.map +1 -0
- package/dist/helper/utils.js +81 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/polyfills.d.ts +54 -0
- package/dist/polyfills.d.ts.map +1 -0
- package/dist/polyfills.js +168 -0
- package/dist/spine/CCSkeleton.d.ts +2 -0
- package/dist/spine/CCSkeleton.d.ts.map +1 -0
- package/dist/spine/CCSkeleton.js +380 -0
- package/dist/spine/CCSkeletonAnimation.d.ts +16 -0
- package/dist/spine/CCSkeletonAnimation.d.ts.map +1 -0
- package/dist/spine/CCSkeletonAnimation.js +353 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +2 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.js +229 -0
- package/dist/spine/CCSkeletonTexture.d.ts +2 -0
- package/dist/spine/CCSkeletonTexture.d.ts.map +1 -0
- package/dist/spine/CCSkeletonTexture.js +98 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts +2 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.js +317 -0
- package/package.json +32 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EntityManager, EventManager, EventReceive, System } from 'entityx-ts';
|
|
2
|
+
import { DragonBonesData, DragonBonesProps } from '../../@types/safex';
|
|
3
|
+
import { ComponentX } from '../gworld/core/decorator';
|
|
4
|
+
export declare class DragonBones extends ComponentX<DragonBonesProps> {
|
|
5
|
+
data: DragonBonesData;
|
|
6
|
+
atlas: string;
|
|
7
|
+
skin: string;
|
|
8
|
+
animation: string;
|
|
9
|
+
loop: boolean;
|
|
10
|
+
timeScale: number;
|
|
11
|
+
setAnimation(name: string, loop?: boolean): void;
|
|
12
|
+
setSkeletonData(data: string): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class DragonBonesSystem implements System {
|
|
15
|
+
configure(event_manager: EventManager): void;
|
|
16
|
+
receive(type: string, event: EventReceive): void;
|
|
17
|
+
update(entities: EntityManager, events: EventManager, dt: number): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function setupDragonBones(): void;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dragonbones/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,MAAM,EACP,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGtE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAKrD,qBAAa,WAAY,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IAC3D,IAAI,EAAE,eAAe,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IAEjB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ;IAOvC,eAAe,CAAC,IAAI,EAAE,MAAM;CAK7B;AAED,qBAAa,iBAAkB,YAAW,MAAM;IAC9C,SAAS,CAAC,aAAa,EAAE,YAAY;IAMrC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY;IAgDzC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAMjE;AAED,wBAAgB,gBAAgB,SAK/B"}
|
|
@@ -0,0 +1,112 @@
|
|
|
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.DragonBonesSystem = exports.DragonBones = void 0;
|
|
19
|
+
exports.setupDragonBones = setupDragonBones;
|
|
20
|
+
var dragonbones_js_1 = require("@cocos/dragonbones-js");
|
|
21
|
+
var entityx_ts_1 = require("entityx-ts");
|
|
22
|
+
var gworld_1 = require("../gworld");
|
|
23
|
+
var NodeComp_1 = require("../gworld/components/NodeComp");
|
|
24
|
+
var decorator_1 = require("../gworld/core/decorator");
|
|
25
|
+
var CocosFactory_1 = require("./cocos/CocosFactory");
|
|
26
|
+
// import { dragonBones } from './dragonBones'
|
|
27
|
+
var DragonBones = /** @class */ (function (_super) {
|
|
28
|
+
__extends(DragonBones, _super);
|
|
29
|
+
function DragonBones() {
|
|
30
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
31
|
+
}
|
|
32
|
+
DragonBones.prototype.setAnimation = function (name, loop) {
|
|
33
|
+
if (loop === void 0) { loop = false; }
|
|
34
|
+
var skel = this.node.instance;
|
|
35
|
+
if (skel.setAnimation) {
|
|
36
|
+
skel.setAnimation(0, name, loop);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
DragonBones.prototype.setSkeletonData = function (data) {
|
|
40
|
+
var skel = this.node.instance;
|
|
41
|
+
var atlas = data.replace('.json', '.atlas');
|
|
42
|
+
skel.initWithArgs(data, atlas, this.node.scale);
|
|
43
|
+
};
|
|
44
|
+
return DragonBones;
|
|
45
|
+
}(decorator_1.ComponentX));
|
|
46
|
+
exports.DragonBones = DragonBones;
|
|
47
|
+
var DragonBonesSystem = /** @class */ (function () {
|
|
48
|
+
function DragonBonesSystem() {
|
|
49
|
+
}
|
|
50
|
+
DragonBonesSystem.prototype.configure = function (event_manager) {
|
|
51
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(DragonBones), this);
|
|
52
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentRemovedEvent)(DragonBones), this);
|
|
53
|
+
// const factory = CocosFactory.factory;
|
|
54
|
+
};
|
|
55
|
+
DragonBonesSystem.prototype.receive = function (type, event) {
|
|
56
|
+
switch (type) {
|
|
57
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(DragonBones): {
|
|
58
|
+
console.log('DragonBones', event);
|
|
59
|
+
var ett = event.entity;
|
|
60
|
+
var dbComp = event.entity.getComponent(DragonBones);
|
|
61
|
+
var data = dbComp.data, animation = dbComp.animation, loop = dbComp.loop, timeScale = dbComp.timeScale;
|
|
62
|
+
// const texturePath = atlas.replace('.json', '.png')
|
|
63
|
+
var atlas = data.atlas, skeleton = data.skeleton, texture = data.texture;
|
|
64
|
+
// cc.textureCache.addImage(texture)
|
|
65
|
+
var factory = CocosFactory_1.CocosFactory.factory;
|
|
66
|
+
var dataSkel = cc.loader.getRes(skeleton);
|
|
67
|
+
var dataAtlas = cc.loader.getRes(atlas);
|
|
68
|
+
var textureCache = cc.textureCache.getTextureForKey(texture);
|
|
69
|
+
// texture.initWithFile(texturePath);
|
|
70
|
+
factory.parseDragonBonesData(dataSkel);
|
|
71
|
+
factory.parseTextureAtlasData(dataAtlas, textureCache);
|
|
72
|
+
// factory.loadDragonBonesData(skel);
|
|
73
|
+
// console.log(skeleton, dataSkel);
|
|
74
|
+
var armature = factory.buildArmature(dataSkel.armature[0].name);
|
|
75
|
+
// console.log('armature', armature)
|
|
76
|
+
var node = armature.getDisplay();
|
|
77
|
+
console.log('node', node);
|
|
78
|
+
dragonbones_js_1.WorldClock.clock.add(armature);
|
|
79
|
+
// armature.animation.gotoAndPlay('walk', 0.2);
|
|
80
|
+
var state = armature.animation.gotoAndPlay(animation, 0, 0, 0);
|
|
81
|
+
console.log('state', state);
|
|
82
|
+
// if (skin) {
|
|
83
|
+
// node.setSkin(skin)
|
|
84
|
+
// }
|
|
85
|
+
if (animation) {
|
|
86
|
+
// node.setAnimation(0, animation, loop)
|
|
87
|
+
}
|
|
88
|
+
dbComp.node = ett.assign(new NodeComp_1.NodeComp(node, ett));
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case (0, entityx_ts_1.ComponentRemovedEvent)(DragonBones): {
|
|
92
|
+
var component = event.component;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
default:
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
DragonBonesSystem.prototype.update = function (entities, events, dt) {
|
|
100
|
+
// throw new Error('Method not implemented.');
|
|
101
|
+
// console.log('update', dt)
|
|
102
|
+
dragonbones_js_1.WorldClock.clock.advanceTime(dt);
|
|
103
|
+
// CocosFactory.advanceTime(dt);
|
|
104
|
+
};
|
|
105
|
+
return DragonBonesSystem;
|
|
106
|
+
}());
|
|
107
|
+
exports.DragonBonesSystem = DragonBonesSystem;
|
|
108
|
+
function setupDragonBones() {
|
|
109
|
+
gworld_1.GameWorld.Instance.systems.add(DragonBonesSystem);
|
|
110
|
+
gworld_1.GameWorld.Instance.listUpdate.push(DragonBonesSystem);
|
|
111
|
+
gworld_1.GameWorld.Instance.systems.configureOnce(DragonBonesSystem);
|
|
112
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { EnhancedComponent } from './EnhancedComponent';
|
|
2
|
+
export declare namespace AnimationClip {
|
|
3
|
+
interface IEvent {
|
|
4
|
+
frame: number;
|
|
5
|
+
func: string;
|
|
6
|
+
params: string[];
|
|
7
|
+
isCalled: boolean;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare enum WrapMode {
|
|
11
|
+
Default = 0,
|
|
12
|
+
Normal = 1,
|
|
13
|
+
Loop = 2,
|
|
14
|
+
PingPong = 22,
|
|
15
|
+
Reverse = 36,
|
|
16
|
+
LoopReverse = 38,
|
|
17
|
+
PingPongReverse = 54
|
|
18
|
+
}
|
|
19
|
+
interface AnimProp {
|
|
20
|
+
frame: number;
|
|
21
|
+
value: number;
|
|
22
|
+
}
|
|
23
|
+
interface SpriteFrameProp {
|
|
24
|
+
frame: number;
|
|
25
|
+
value: string;
|
|
26
|
+
}
|
|
27
|
+
interface CurveData {
|
|
28
|
+
comps: {
|
|
29
|
+
spriteFrame: SpriteFrameProp[];
|
|
30
|
+
nextFrame: number;
|
|
31
|
+
};
|
|
32
|
+
props: {
|
|
33
|
+
[key: string]: AnimProp[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare class AnimationClip {
|
|
37
|
+
static WrapMode: typeof WrapMode;
|
|
38
|
+
sample: number;
|
|
39
|
+
speed: number;
|
|
40
|
+
wrapMode: WrapMode;
|
|
41
|
+
events: AnimationClip.IEvent[];
|
|
42
|
+
duration: number;
|
|
43
|
+
name: string;
|
|
44
|
+
curveData: CurveData;
|
|
45
|
+
}
|
|
46
|
+
export declare class AnimationComp extends EnhancedComponent {
|
|
47
|
+
defaultClip: AnimationClip;
|
|
48
|
+
clips: AnimationClip[];
|
|
49
|
+
playOnLoad: boolean;
|
|
50
|
+
private isPaused;
|
|
51
|
+
private elapsed;
|
|
52
|
+
private currentClip;
|
|
53
|
+
constructor(defaultClip: AnimationClip, clips: AnimationClip[], playOnLoad: boolean);
|
|
54
|
+
start(): void;
|
|
55
|
+
update(dt: Float): void;
|
|
56
|
+
getAnimationState(name: string): {
|
|
57
|
+
isPlaying: boolean;
|
|
58
|
+
};
|
|
59
|
+
play(name?: string): void;
|
|
60
|
+
pause(): void;
|
|
61
|
+
resume(): void;
|
|
62
|
+
stop(name?: string): void;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=AnimationComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimationComponent.d.ts","sourceRoot":"","sources":["../../../src/gworld/components/AnimationComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGvD,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,UAAiB,MAAM;QACrB,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,EAAE,CAAA;QAChB,QAAQ,EAAE,OAAO,CAAA;KAClB;CACF;AAED,oBAAY,QAAQ;IAClB,OAAO,IAAI;IACX,MAAM,IAAI;IACV,IAAI,IAAI;IACR,QAAQ,KAAK;IACb,OAAO,KAAK;IACZ,WAAW,KAAK;IAChB,eAAe,KAAK;CACrB;AAED,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,UAAU,SAAS;IACjB,KAAK,EAAE;QAAE,WAAW,EAAE,eAAe,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5D,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAA;KAAE,CAAA;CACrC;AAED,qBAAa,aAAa;IACxB,OAAc,QAAQ,kBAAW;IAC1B,MAAM,SAAK;IACX,KAAK,SAAI;IACT,QAAQ,WAAkB;IAC1B,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,CAAK;IACnC,QAAQ,SAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,SAAS,CAAA;CACrB;AAID,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,WAAW,EAAE,aAAa,CAAA;IAC1B,KAAK,EAAE,aAAa,EAAE,CAAA;IACtB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,QAAQ,CAAO;IACvB,OAAO,CAAC,OAAO,CAAI;IACnB,OAAO,CAAC,WAAW,CAAe;gBAEtB,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,UAAU,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("./EnhancedComponent");
|
|
20
|
+
var RenderComponent_1 = require("./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,64 @@
|
|
|
1
|
+
import { Vec2 } from '../../polyfills';
|
|
2
|
+
import { NoRenderComponentX } from '../core/decorator';
|
|
3
|
+
interface ColliderProps {
|
|
4
|
+
offset?: Vec2;
|
|
5
|
+
tag?: number;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
onCollisionEnter?: (other: Collider) => void;
|
|
8
|
+
onCollisionExit?: (other: Collider) => void;
|
|
9
|
+
onCollisionStay?: (other: Collider) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare class Collider<T = ColliderProps> extends NoRenderComponentX<T> {
|
|
12
|
+
_worldPoints: cc.Vec2[] | cc.Point[];
|
|
13
|
+
_worldPosition: cc.Vec2 | cc.Point;
|
|
14
|
+
_worldRadius: any;
|
|
15
|
+
_AABB: cc.Rect;
|
|
16
|
+
_preAabb: cc.Rect;
|
|
17
|
+
getAABB(): cc.Rect;
|
|
18
|
+
get world(): {
|
|
19
|
+
points: cc.Point[] | cc.Vec2[];
|
|
20
|
+
preAabb: cc.Rect;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface BoxColliderProps extends ColliderProps {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
}
|
|
27
|
+
export declare class BoxCollider extends Collider<BoxColliderProps> {
|
|
28
|
+
get size(): cc.Size;
|
|
29
|
+
set size(s: cc.Size);
|
|
30
|
+
update(dt: any, draw: cc.DrawNode): void;
|
|
31
|
+
}
|
|
32
|
+
interface CircleColliderProps extends ColliderProps {
|
|
33
|
+
radius: number;
|
|
34
|
+
}
|
|
35
|
+
export declare class CircleCollider extends Collider<CircleColliderProps> {
|
|
36
|
+
update(dt: any, draw: cc.DrawNode): void;
|
|
37
|
+
}
|
|
38
|
+
interface PolygonColliderProps extends ColliderProps {
|
|
39
|
+
points: Array<Vec2>;
|
|
40
|
+
}
|
|
41
|
+
export declare class PolygonCollider extends Collider<PolygonColliderProps> {
|
|
42
|
+
get points(): Vec2[];
|
|
43
|
+
set points(points: Vec2[]);
|
|
44
|
+
update(dt: any, draw: cc.DrawNode): void;
|
|
45
|
+
}
|
|
46
|
+
export declare enum CollisionType {
|
|
47
|
+
NONE = 0,
|
|
48
|
+
ENTER = 1,
|
|
49
|
+
STAY = 2,
|
|
50
|
+
EXIT = 3
|
|
51
|
+
}
|
|
52
|
+
export declare class Contract {
|
|
53
|
+
_collider1: Collider;
|
|
54
|
+
_collider2: Collider;
|
|
55
|
+
_touching: boolean;
|
|
56
|
+
_isPolygonPolygon: boolean;
|
|
57
|
+
_isCircleCircle: boolean;
|
|
58
|
+
_isPolygonCircle: boolean;
|
|
59
|
+
constructor(collider1: Collider, collider2: Collider);
|
|
60
|
+
updateState(): CollisionType;
|
|
61
|
+
test(): any;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=CollideComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollideComponent.d.ts","sourceRoot":"","sources":["../../../src/gworld/components/CollideComponent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAYtD,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,IAAI,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAA;IAC5C,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAA;IAC3C,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAA;CAC5C;AACD,qBAAa,QAAQ,CAAC,CAAC,GAAG,aAAa,CAAE,SAAQ,kBAAkB,CAAC,CAAC,CAAC;IACpE,YAAY,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAK;IACzC,cAAc,EAAE,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAA;IAClC,YAAY,MAAA;IACZ,KAAK,EAAE,EAAE,CAAC,IAAI,CAAsB;IACpC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAsB;IAGvC,OAAO;IAGP,IAAI,KAAK;;;MAKR;CACF;AAED,UAAU,gBAAiB,SAAQ,aAAa;IAC9C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AACD,qBAAa,WAAY,SAAQ,QAAQ,CAAC,gBAAgB,CAAC;IACzD,IAAI,IAAI,IAII,EAAE,CAAC,IAAI,CAFlB;IAED,IAAI,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,EAGlB;IAED,MAAM,CAAC,EAAE,KAAA,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ;CA4B7B;AAED,UAAU,mBAAoB,SAAQ,aAAa;IACjD,MAAM,EAAE,MAAM,CAAA;CACf;AACD,qBAAa,cAAe,SAAQ,QAAQ,CAAC,mBAAmB,CAAC;IAC/D,MAAM,CAAC,EAAE,KAAA,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ;CAqB7B;AAED,UAAU,oBAAqB,SAAQ,aAAa;IAClD,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;CACpB;AAED,qBAAa,eAAgB,SAAQ,QAAQ,CAAC,oBAAoB,CAAC;IACjE,IAAI,MAAM,IAAI,IAAI,EAAE,CAInB;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,EAExB;IAED,MAAM,CAAC,EAAE,KAAA,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ;CAqB7B;AAED,oBAAY,aAAa;IACvB,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,IAAI,IAAA;CACL;AASD,qBAAa,QAAQ;IACnB,UAAU,EAAE,QAAQ,CAAA;IACpB,UAAU,EAAE,QAAQ,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,eAAe,EAAE,OAAO,CAAA;IACxB,gBAAgB,EAAE,OAAO,CAAA;gBAEb,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ;IAsBpD,WAAW;IAeX,IAAI;CAyBL"}
|
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.Contract = exports.CollisionType = exports.PolygonCollider = exports.CircleCollider = exports.BoxCollider = exports.Collider = void 0;
|
|
22
|
+
var max_1 = __importDefault(require("lodash/max"));
|
|
23
|
+
var min_1 = __importDefault(require("lodash/min"));
|
|
24
|
+
var polyfills_1 = require("../../polyfills");
|
|
25
|
+
var decorator_1 = require("../core/decorator");
|
|
26
|
+
function getNodeToWorldTransformAR(node) {
|
|
27
|
+
var t = node.instance.getNodeToWorldTransform();
|
|
28
|
+
var anchorPointSize = node.instance.getAnchorPointInPoints();
|
|
29
|
+
var transform = cc.affineTransformTranslate(t, anchorPointSize.x, anchorPointSize.y);
|
|
30
|
+
return transform;
|
|
31
|
+
}
|
|
32
|
+
function cloneRect(origin) {
|
|
33
|
+
return cc.rect(origin.x, origin.y, origin.width, origin.height);
|
|
34
|
+
}
|
|
35
|
+
var Collider = /** @class */ (function (_super) {
|
|
36
|
+
__extends(Collider, _super);
|
|
37
|
+
function Collider() {
|
|
38
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
39
|
+
_this._worldPoints = [];
|
|
40
|
+
_this._AABB = cc.rect(0, 0, 0, 0);
|
|
41
|
+
_this._preAabb = cc.rect(0, 0, 0, 0);
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
// update(dt: number, draw?: cc.DrawNode) {}
|
|
45
|
+
Collider.prototype.getAABB = function () {
|
|
46
|
+
return this._AABB;
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(Collider.prototype, "world", {
|
|
49
|
+
get: function () {
|
|
50
|
+
return {
|
|
51
|
+
points: this._worldPoints,
|
|
52
|
+
preAabb: this._preAabb,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
enumerable: false,
|
|
56
|
+
configurable: true
|
|
57
|
+
});
|
|
58
|
+
return Collider;
|
|
59
|
+
}(decorator_1.NoRenderComponentX));
|
|
60
|
+
exports.Collider = Collider;
|
|
61
|
+
var BoxCollider = /** @class */ (function (_super) {
|
|
62
|
+
__extends(BoxCollider, _super);
|
|
63
|
+
function BoxCollider() {
|
|
64
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
65
|
+
}
|
|
66
|
+
Object.defineProperty(BoxCollider.prototype, "size", {
|
|
67
|
+
get: function () {
|
|
68
|
+
return cc.size(this.props.width, this.props.height);
|
|
69
|
+
},
|
|
70
|
+
set: function (s) {
|
|
71
|
+
this.props.width = s.width;
|
|
72
|
+
this.props.height = s.height;
|
|
73
|
+
},
|
|
74
|
+
enumerable: false,
|
|
75
|
+
configurable: true
|
|
76
|
+
});
|
|
77
|
+
BoxCollider.prototype.update = function (dt, draw) {
|
|
78
|
+
if (!this.node) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
var collider = this.getComponent(Collider);
|
|
82
|
+
var _a = collider.props.offset || (0, polyfills_1.Vec2)(0, 0), x = _a.x, y = _a.y;
|
|
83
|
+
var hw = this.props.width * 0.5;
|
|
84
|
+
var hh = this.props.height * 0.5;
|
|
85
|
+
var transform = getNodeToWorldTransformAR(this.node);
|
|
86
|
+
var rect = cc.rect(x - hw, y - hh, this.props.width, this.props.height);
|
|
87
|
+
var rectTrs = cc.rectApplyAffineTransform(rect, transform);
|
|
88
|
+
// cc.log(rectTrs);
|
|
89
|
+
collider._worldPoints[0] = (0, polyfills_1.Vec2)(rectTrs.x, rectTrs.y);
|
|
90
|
+
collider._worldPoints[1] = (0, polyfills_1.Vec2)(rectTrs.x, rectTrs.y + rectTrs.height);
|
|
91
|
+
collider._worldPoints[2] = (0, polyfills_1.Vec2)(rectTrs.x + rectTrs.width, rectTrs.y + rectTrs.height);
|
|
92
|
+
collider._worldPoints[3] = (0, polyfills_1.Vec2)(rectTrs.x + rectTrs.width, rectTrs.y);
|
|
93
|
+
var listX = collider._worldPoints.map(function (_a) {
|
|
94
|
+
var x = _a.x;
|
|
95
|
+
return x;
|
|
96
|
+
});
|
|
97
|
+
var listY = collider._worldPoints.map(function (_a) {
|
|
98
|
+
var y = _a.y;
|
|
99
|
+
return y;
|
|
100
|
+
});
|
|
101
|
+
collider._preAabb = cloneRect(collider._AABB);
|
|
102
|
+
collider._AABB.x = (0, min_1.default)(listX);
|
|
103
|
+
collider._AABB.y = (0, min_1.default)(listY);
|
|
104
|
+
collider._AABB.width = (0, max_1.default)(listX) - collider._AABB.x;
|
|
105
|
+
collider._AABB.height = (0, max_1.default)(listY) - collider._AABB.y;
|
|
106
|
+
if (draw) {
|
|
107
|
+
draw.drawPoly(collider._worldPoints, null, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return BoxCollider;
|
|
111
|
+
}(Collider));
|
|
112
|
+
exports.BoxCollider = BoxCollider;
|
|
113
|
+
var CircleCollider = /** @class */ (function (_super) {
|
|
114
|
+
__extends(CircleCollider, _super);
|
|
115
|
+
function CircleCollider() {
|
|
116
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
117
|
+
}
|
|
118
|
+
CircleCollider.prototype.update = function (dt, draw) {
|
|
119
|
+
if (!this.node) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var transform = getNodeToWorldTransformAR(this.node);
|
|
123
|
+
var collider = this.getComponent(Collider);
|
|
124
|
+
collider._worldRadius = this.props.radius * this.node.scaleX;
|
|
125
|
+
collider._worldPosition = cc.pointApplyAffineTransform(collider.props.offset, transform);
|
|
126
|
+
if (draw) {
|
|
127
|
+
draw.drawDot(collider._worldPosition, collider._worldRadius, cc.Color.DEBUG_FILL_COLOR);
|
|
128
|
+
draw.drawCircle(collider._worldPosition, collider._worldRadius, 0, 64, true, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
129
|
+
}
|
|
130
|
+
collider._preAabb = cloneRect(collider._AABB);
|
|
131
|
+
collider._AABB.x = collider._worldPosition.x - collider._worldRadius;
|
|
132
|
+
collider._AABB.y = collider._worldPosition.y - collider._worldRadius;
|
|
133
|
+
collider._AABB.width = collider._worldRadius * 2;
|
|
134
|
+
collider._AABB.height = collider._AABB.width;
|
|
135
|
+
// draw.drawRect(cc.p(this._AABB.x, this._AABB.y),
|
|
136
|
+
// cc.p(this._worldPosition.x + this._worldRadius, this._worldPosition.y + this._worldRadius),
|
|
137
|
+
// cc.Color.WHITE, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
138
|
+
};
|
|
139
|
+
return CircleCollider;
|
|
140
|
+
}(Collider));
|
|
141
|
+
exports.CircleCollider = CircleCollider;
|
|
142
|
+
var PolygonCollider = /** @class */ (function (_super) {
|
|
143
|
+
__extends(PolygonCollider, _super);
|
|
144
|
+
function PolygonCollider() {
|
|
145
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
146
|
+
}
|
|
147
|
+
Object.defineProperty(PolygonCollider.prototype, "points", {
|
|
148
|
+
get: function () {
|
|
149
|
+
var _a = this.props.offset, x = _a.x, y = _a.y;
|
|
150
|
+
var pointsList = this.props.points.map(function (p) { return (0, polyfills_1.Vec2)(p.x + x, p.y + y); });
|
|
151
|
+
return pointsList;
|
|
152
|
+
},
|
|
153
|
+
set: function (points) {
|
|
154
|
+
this.props.points = points;
|
|
155
|
+
},
|
|
156
|
+
enumerable: false,
|
|
157
|
+
configurable: true
|
|
158
|
+
});
|
|
159
|
+
PolygonCollider.prototype.update = function (dt, draw) {
|
|
160
|
+
if (!this.node) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
var transform = getNodeToWorldTransformAR(this.node);
|
|
164
|
+
var collider = this.getComponent(Collider);
|
|
165
|
+
collider._worldPoints = this.points.map(function (p) { return cc.pointApplyAffineTransform(p, transform); });
|
|
166
|
+
// cc.log(polyPoints);
|
|
167
|
+
if (draw) {
|
|
168
|
+
draw.drawPoly(collider._worldPoints, cc.Color.DEBUG_FILL_COLOR, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
169
|
+
}
|
|
170
|
+
var listX = collider._worldPoints.map(function (_a) {
|
|
171
|
+
var x = _a.x;
|
|
172
|
+
return x;
|
|
173
|
+
});
|
|
174
|
+
var listY = collider._worldPoints.map(function (_a) {
|
|
175
|
+
var y = _a.y;
|
|
176
|
+
return y;
|
|
177
|
+
});
|
|
178
|
+
collider._preAabb = cloneRect(collider._AABB);
|
|
179
|
+
collider._AABB.x = (0, min_1.default)(listX);
|
|
180
|
+
collider._AABB.y = (0, min_1.default)(listY);
|
|
181
|
+
collider._AABB.width = (0, max_1.default)(listX) - collider._AABB.x;
|
|
182
|
+
collider._AABB.height = (0, max_1.default)(listY) - collider._AABB.y;
|
|
183
|
+
// draw.drawRect(cc.p(this._AABB.x, this._AABB.y), cc.p(max(listX), max(listY)),
|
|
184
|
+
// cc.Color.WHITE, 3, cc.Color.DEBUG_BORDER_COLOR);
|
|
185
|
+
};
|
|
186
|
+
return PolygonCollider;
|
|
187
|
+
}(Collider));
|
|
188
|
+
exports.PolygonCollider = PolygonCollider;
|
|
189
|
+
var CollisionType;
|
|
190
|
+
(function (CollisionType) {
|
|
191
|
+
CollisionType[CollisionType["NONE"] = 0] = "NONE";
|
|
192
|
+
CollisionType[CollisionType["ENTER"] = 1] = "ENTER";
|
|
193
|
+
CollisionType[CollisionType["STAY"] = 2] = "STAY";
|
|
194
|
+
CollisionType[CollisionType["EXIT"] = 3] = "EXIT";
|
|
195
|
+
})(CollisionType || (exports.CollisionType = CollisionType = {}));
|
|
196
|
+
function isPolygonCollider(col) {
|
|
197
|
+
return col.getComponent(PolygonCollider) || col.getComponent(BoxCollider);
|
|
198
|
+
}
|
|
199
|
+
function isCircleCollider(col) {
|
|
200
|
+
return col.getComponent(CircleCollider);
|
|
201
|
+
}
|
|
202
|
+
var Contract = /** @class */ (function () {
|
|
203
|
+
function Contract(collider1, collider2) {
|
|
204
|
+
this._collider1 = collider1;
|
|
205
|
+
this._collider2 = collider2;
|
|
206
|
+
var isCollider1Polygon = isPolygonCollider(collider1);
|
|
207
|
+
var isCollider2Polygon = isPolygonCollider(collider2);
|
|
208
|
+
var isCollider1Circle = isCircleCollider(collider1);
|
|
209
|
+
var isCollider2Circle = isCircleCollider(collider2);
|
|
210
|
+
if (isCollider1Polygon && isCollider2Polygon) {
|
|
211
|
+
this._isPolygonPolygon = true;
|
|
212
|
+
}
|
|
213
|
+
else if (isCollider1Circle && isCollider2Circle) {
|
|
214
|
+
this._isCircleCircle = true;
|
|
215
|
+
}
|
|
216
|
+
else if (isCollider1Polygon && isCollider2Circle) {
|
|
217
|
+
this._isPolygonCircle = true;
|
|
218
|
+
}
|
|
219
|
+
else if (isCollider1Circle && isCollider2Polygon) {
|
|
220
|
+
this._isPolygonCircle = true;
|
|
221
|
+
this._collider1 = collider2;
|
|
222
|
+
this._collider2 = collider1;
|
|
223
|
+
}
|
|
224
|
+
// cc.log(this._isPolygonPolygon);
|
|
225
|
+
}
|
|
226
|
+
Contract.prototype.updateState = function () {
|
|
227
|
+
var result = this.test();
|
|
228
|
+
var type = CollisionType.NONE;
|
|
229
|
+
if (result && !this._touching) {
|
|
230
|
+
this._touching = true;
|
|
231
|
+
type = CollisionType.ENTER;
|
|
232
|
+
}
|
|
233
|
+
else if (result && this._touching) {
|
|
234
|
+
type = CollisionType.STAY;
|
|
235
|
+
}
|
|
236
|
+
else if (!result && this._touching) {
|
|
237
|
+
this._touching = false;
|
|
238
|
+
type = CollisionType.EXIT;
|
|
239
|
+
}
|
|
240
|
+
return type;
|
|
241
|
+
};
|
|
242
|
+
Contract.prototype.test = function () {
|
|
243
|
+
// if (!shouldCollider(this._collider1, this._collider2)) {
|
|
244
|
+
// return false;
|
|
245
|
+
// }
|
|
246
|
+
// cc.log(this._collider1.getAABB(), this._collider2.getAABB());
|
|
247
|
+
if (!cc.rectIntersectsRect(this._collider1.getAABB(), this._collider2.getAABB())) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
if (this._isPolygonPolygon) {
|
|
251
|
+
return cc.Intersection.polygonPolygon(this._collider1._worldPoints, this._collider2._worldPoints);
|
|
252
|
+
}
|
|
253
|
+
if (this._isCircleCircle) {
|
|
254
|
+
var p1 = this._collider1;
|
|
255
|
+
var p2 = this._collider2;
|
|
256
|
+
return cc.Intersection.circleCircle(p1._worldPosition, p1._worldRadius, p2._worldPosition, p2._worldRadius);
|
|
257
|
+
}
|
|
258
|
+
if (this._isPolygonCircle) {
|
|
259
|
+
var p2 = this._collider2;
|
|
260
|
+
return cc.Intersection.polygonCircle(this._collider1._worldPoints, p2._worldPosition, p2._worldRadius);
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
};
|
|
264
|
+
return Contract;
|
|
265
|
+
}());
|
|
266
|
+
exports.Contract = Contract;
|