@safe-engine/pixi 1.0.0
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/.github/workflows/npm-publish.yml +35 -0
- package/README.md +4 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +102 -0
- package/dist/components/EnhancedComponent.d.ts +22 -0
- package/dist/components/EnhancedComponent.d.ts.map +1 -0
- package/dist/components/EnhancedComponent.js +62 -0
- package/dist/components/GUIComponent.d.ts +72 -0
- package/dist/components/GUIComponent.d.ts.map +1 -0
- package/dist/components/GUIComponent.js +178 -0
- package/dist/components/NodeComp.d.ts +104 -0
- package/dist/components/NodeComp.d.ts.map +1 -0
- package/dist/components/NodeComp.js +420 -0
- package/dist/components/RenderComponent.d.ts +29 -0
- package/dist/components/RenderComponent.d.ts.map +1 -0
- package/dist/components/RenderComponent.js +89 -0
- package/dist/core/Color.d.ts +7 -0
- package/dist/core/Color.d.ts.map +1 -0
- package/dist/core/Color.js +6 -0
- package/dist/core/LoadingBar.d.ts +13 -0
- package/dist/core/LoadingBar.d.ts.map +1 -0
- package/dist/core/LoadingBar.js +55 -0
- package/dist/core/Scene.d.ts +6 -0
- package/dist/core/Scene.d.ts.map +1 -0
- package/dist/core/Scene.js +39 -0
- package/dist/core/Size.d.ts +10 -0
- package/dist/core/Size.d.ts.map +1 -0
- package/dist/core/Size.js +22 -0
- package/dist/core/Vec2.d.ts +20 -0
- package/dist/core/Vec2.d.ts.map +1 -0
- package/dist/core/Vec2.js +70 -0
- package/dist/core/decorator.d.ts +9 -0
- package/dist/core/decorator.d.ts.map +1 -0
- package/dist/core/decorator.js +46 -0
- package/dist/gworld.d.ts +8 -0
- package/dist/gworld.d.ts.map +1 -0
- package/dist/gworld.js +43 -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 +353 -0
- package/dist/helper/utils.d.ts +17 -0
- package/dist/helper/utils.d.ts.map +1 -0
- package/dist/helper/utils.js +64 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/systems/GUISystem.d.ts +7 -0
- package/dist/systems/GUISystem.d.ts.map +1 -0
- package/dist/systems/GUISystem.js +94 -0
- package/dist/systems/RenderSystem.d.ts +15 -0
- package/dist/systems/RenderSystem.d.ts.map +1 -0
- package/dist/systems/RenderSystem.js +100 -0
- package/package.json +30 -0
- package/src/app.ts +51 -0
- package/src/components/EnhancedComponent.ts +57 -0
- package/src/components/GUIComponent.ts +147 -0
- package/src/components/NodeComp.ts +409 -0
- package/src/components/RenderComponent.ts +65 -0
- package/src/core/Color.ts +3 -0
- package/src/core/LoadingBar.ts +33 -0
- package/src/core/Scene.ts +17 -0
- package/src/core/Size.ts +21 -0
- package/src/core/Vec2.ts +52 -0
- package/src/core/decorator.ts +18 -0
- package/src/gworld.ts +17 -0
- package/src/helper/html-text-parser.ts +364 -0
- package/src/helper/utils.ts +64 -0
- package/src/index.ts +10 -0
- package/src/systems/GUISystem.ts +95 -0
- package/src/systems/RenderSystem.ts +100 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Size = void 0;
|
|
4
|
+
exports.registerSystem = registerSystem;
|
|
5
|
+
exports.instantiate = instantiate;
|
|
6
|
+
exports.size = size;
|
|
7
|
+
var entityx_ts_1 = require("entityx-ts");
|
|
8
|
+
var __1 = require("..");
|
|
9
|
+
var gworld_1 = require("../gworld");
|
|
10
|
+
function registerSystem(component) {
|
|
11
|
+
if (gworld_1.GameWorld.Instance.systems.isRegistered("".concat(component.name, "System"))) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
var NewSystem = /** @class */ (function () {
|
|
15
|
+
function NewSystem() {
|
|
16
|
+
}
|
|
17
|
+
NewSystem.prototype.configure = function (event_manager) {
|
|
18
|
+
console.log('configure registerSystem', component.name);
|
|
19
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(component), this);
|
|
20
|
+
};
|
|
21
|
+
NewSystem.prototype.receive = function (type, event) {
|
|
22
|
+
switch (type) {
|
|
23
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(component): {
|
|
24
|
+
var ett = event.entity;
|
|
25
|
+
var newComp = ett.getComponent(component);
|
|
26
|
+
newComp.node = ett.getComponent(__1.NodeComp);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
default:
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
NewSystem.prototype.update = function (entities, events, dt) {
|
|
34
|
+
for (var _i = 0, _a = entities.entities_with_components(component); _i < _a.length; _i++) {
|
|
35
|
+
var entt = _a[_i];
|
|
36
|
+
var comp = entt.getComponent(component);
|
|
37
|
+
// console.log('comp', comp.constructor.name, typeof comp['update'] === 'function')
|
|
38
|
+
if (comp.node.active && typeof comp['update'] === 'function') {
|
|
39
|
+
comp['update'](dt);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return NewSystem;
|
|
44
|
+
}());
|
|
45
|
+
Object.defineProperty(NewSystem, 'name', { value: "".concat(component.name, "System") });
|
|
46
|
+
gworld_1.GameWorld.Instance.systems.add(NewSystem);
|
|
47
|
+
gworld_1.GameWorld.Instance.systems.configureOnce(NewSystem);
|
|
48
|
+
gworld_1.GameWorld.Instance.listUpdate.push(NewSystem);
|
|
49
|
+
return NewSystem;
|
|
50
|
+
}
|
|
51
|
+
function instantiate(ComponentType, data) {
|
|
52
|
+
return ComponentType.create(data);
|
|
53
|
+
}
|
|
54
|
+
var Size = /** @class */ (function () {
|
|
55
|
+
function Size(width, height) {
|
|
56
|
+
this.width = width;
|
|
57
|
+
this.height = height;
|
|
58
|
+
}
|
|
59
|
+
return Size;
|
|
60
|
+
}());
|
|
61
|
+
exports.Size = Size;
|
|
62
|
+
function size(width, height) {
|
|
63
|
+
return new Size(width, height);
|
|
64
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { addGameCanvasTo, app, initWorld, setupResolution } from './app';
|
|
2
|
+
export * from './components/GUIComponent';
|
|
3
|
+
export { NodeComp } from './components/NodeComp';
|
|
4
|
+
export * from './components/RenderComponent';
|
|
5
|
+
export { ComponentX, NoRenderComponentX } from './core/decorator';
|
|
6
|
+
export { SceneComponent } from './core/Scene';
|
|
7
|
+
export * from './core/Size';
|
|
8
|
+
export { Vec2 } from './core/Vec2';
|
|
9
|
+
export { GameWorld } from './gworld';
|
|
10
|
+
export { instantiate, registerSystem } from './helper/utils';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,SAAS,EAAC,eAAe,EAAE,MAAM,OAAO,CAAA;AACvE,cAAc,2BAA2B,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAG,IAAI,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.registerSystem = exports.instantiate = exports.GameWorld = exports.Vec2 = exports.SceneComponent = exports.NoRenderComponentX = exports.ComponentX = exports.NodeComp = exports.setupResolution = exports.initWorld = exports.app = exports.addGameCanvasTo = void 0;
|
|
18
|
+
var app_1 = require("./app");
|
|
19
|
+
Object.defineProperty(exports, "addGameCanvasTo", { enumerable: true, get: function () { return app_1.addGameCanvasTo; } });
|
|
20
|
+
Object.defineProperty(exports, "app", { enumerable: true, get: function () { return app_1.app; } });
|
|
21
|
+
Object.defineProperty(exports, "initWorld", { enumerable: true, get: function () { return app_1.initWorld; } });
|
|
22
|
+
Object.defineProperty(exports, "setupResolution", { enumerable: true, get: function () { return app_1.setupResolution; } });
|
|
23
|
+
__exportStar(require("./components/GUIComponent"), exports);
|
|
24
|
+
var NodeComp_1 = require("./components/NodeComp");
|
|
25
|
+
Object.defineProperty(exports, "NodeComp", { enumerable: true, get: function () { return NodeComp_1.NodeComp; } });
|
|
26
|
+
__exportStar(require("./components/RenderComponent"), exports);
|
|
27
|
+
var decorator_1 = require("./core/decorator");
|
|
28
|
+
Object.defineProperty(exports, "ComponentX", { enumerable: true, get: function () { return decorator_1.ComponentX; } });
|
|
29
|
+
Object.defineProperty(exports, "NoRenderComponentX", { enumerable: true, get: function () { return decorator_1.NoRenderComponentX; } });
|
|
30
|
+
var Scene_1 = require("./core/Scene");
|
|
31
|
+
Object.defineProperty(exports, "SceneComponent", { enumerable: true, get: function () { return Scene_1.SceneComponent; } });
|
|
32
|
+
__exportStar(require("./core/Size"), exports);
|
|
33
|
+
var Vec2_1 = require("./core/Vec2");
|
|
34
|
+
Object.defineProperty(exports, "Vec2", { enumerable: true, get: function () { return Vec2_1.Vec2; } });
|
|
35
|
+
var gworld_1 = require("./gworld");
|
|
36
|
+
Object.defineProperty(exports, "GameWorld", { enumerable: true, get: function () { return gworld_1.GameWorld; } });
|
|
37
|
+
var utils_1 = require("./helper/utils");
|
|
38
|
+
Object.defineProperty(exports, "instantiate", { enumerable: true, get: function () { return utils_1.instantiate; } });
|
|
39
|
+
Object.defineProperty(exports, "registerSystem", { enumerable: true, get: function () { return utils_1.registerSystem; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EventManager, EventReceive, System } from 'entityx-ts';
|
|
2
|
+
export declare class GUISystem implements System {
|
|
3
|
+
configure(event_manager: EventManager): void;
|
|
4
|
+
receive(type: string, event: EventReceive): void;
|
|
5
|
+
update(): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=GUISystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GUISystem.d.ts","sourceRoot":"","sources":["../../src/systems/GUISystem.ts"],"names":[],"mappings":"AACA,OAAO,EACgB,YAAY,EAAE,YAAY,EAC/C,MAAM,EACP,MAAM,YAAY,CAAA;AAQnB,qBAAa,SAAU,YAAW,MAAM;IACtC,SAAS,CAAC,aAAa,EAAE,YAAY;IAOrC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY;IAuEzC,MAAM;CAGP"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GUISystem = void 0;
|
|
4
|
+
var ui_1 = require("@pixi/ui");
|
|
5
|
+
var entityx_ts_1 = require("entityx-ts");
|
|
6
|
+
var pixi_js_1 = require("pixi.js");
|
|
7
|
+
var pixi_action_ease_1 = require("pixi-action-ease");
|
|
8
|
+
var __1 = require("..");
|
|
9
|
+
var GUIComponent_1 = require("../components/GUIComponent");
|
|
10
|
+
var LoadingBar_1 = require("../core/LoadingBar");
|
|
11
|
+
var GUISystem = /** @class */ (function () {
|
|
12
|
+
function GUISystem() {
|
|
13
|
+
}
|
|
14
|
+
GUISystem.prototype.configure = function (event_manager) {
|
|
15
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.ButtonComp), this);
|
|
16
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.ProgressBarComp), this);
|
|
17
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.ScrollView), this);
|
|
18
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.LabelComp), this);
|
|
19
|
+
// event_manager.subscribe(ComponentAddedEvent(BlockInputEventsComp), this);
|
|
20
|
+
};
|
|
21
|
+
GUISystem.prototype.receive = function (type, event) {
|
|
22
|
+
switch (type) {
|
|
23
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.ButtonComp): {
|
|
24
|
+
console.log('ComponentAddedEvent ButtonComp', event);
|
|
25
|
+
var ett = event.entity;
|
|
26
|
+
var button_1 = ett.getComponent(GUIComponent_1.ButtonComp);
|
|
27
|
+
var nodeComp = ett.getComponent(__1.NodeComp);
|
|
28
|
+
// const { normalImage, selectedImage, disableImage, texType, zoomScale } = button
|
|
29
|
+
var node = new ui_1.Button(nodeComp.instance);
|
|
30
|
+
// node.setZoomScale(zoomScale - 1)
|
|
31
|
+
button_1.node = nodeComp;
|
|
32
|
+
// button.node = ett.assign(new NodeComp(node, ett))
|
|
33
|
+
node.onPress.connect(function () {
|
|
34
|
+
// console.log('onPress.connect')
|
|
35
|
+
var scale = pixi_action_ease_1.ScaleTo.create(0.12, 1.2);
|
|
36
|
+
var scaleDown = pixi_action_ease_1.ScaleTo.create(0.12, 1);
|
|
37
|
+
var seq = pixi_action_ease_1.Sequence.create(scale, pixi_action_ease_1.CallFunc.create(function () {
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(button_1, 'onPress')) {
|
|
39
|
+
button_1.onPress(button_1);
|
|
40
|
+
}
|
|
41
|
+
}), scaleDown);
|
|
42
|
+
var ease = pixi_action_ease_1.EaseBackIn.create(seq);
|
|
43
|
+
button_1.node.runAction(ease);
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.ProgressBarComp): {
|
|
48
|
+
console.log('ComponentAddedEvent ProgressBarComp', event);
|
|
49
|
+
var ett = event.entity;
|
|
50
|
+
var bar = ett.getComponent(GUIComponent_1.ProgressBarComp);
|
|
51
|
+
var spriteComp = ett.getComponent(__1.SpriteRender);
|
|
52
|
+
if (!spriteComp)
|
|
53
|
+
throw Error('ProgressBarComp need SpriteRender');
|
|
54
|
+
var progress = bar.progress, mode = bar.mode;
|
|
55
|
+
var node = new LoadingBar_1.LoadingBar(mode, spriteComp.node.instance);
|
|
56
|
+
spriteComp.node.instance.mask = node;
|
|
57
|
+
bar.node = ett.assign(new __1.NodeComp(node, ett));
|
|
58
|
+
node.progress = progress;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.ScrollView): {
|
|
62
|
+
console.log('ComponentAddedEvent ScrollView', event);
|
|
63
|
+
var ett = event.entity;
|
|
64
|
+
var scroll_1 = event.component;
|
|
65
|
+
var width = scroll_1.width, height = scroll_1.height;
|
|
66
|
+
var view = new ui_1.ScrollBox({ width: width, height: height });
|
|
67
|
+
scroll_1.node = ett.assign(new __1.NodeComp(view, ett));
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(GUIComponent_1.LabelComp): {
|
|
71
|
+
console.log('ComponentAddedEvent LabelComp', event);
|
|
72
|
+
var ett = event.entity;
|
|
73
|
+
var label = ett.getComponent(GUIComponent_1.LabelComp);
|
|
74
|
+
var node = new pixi_js_1.Text();
|
|
75
|
+
// node.texture.rotate = 8
|
|
76
|
+
node.style.fill = '#fff';
|
|
77
|
+
label.node = ett.assign(new __1.NodeComp(node, ett));
|
|
78
|
+
var _a = label.string, string = _a === void 0 ? '' : _a, _b = label.font, font = _b === void 0 ? '' : _b, size = label.size;
|
|
79
|
+
if (font)
|
|
80
|
+
label.setFont(font);
|
|
81
|
+
label.setSize(size);
|
|
82
|
+
label.setString(string);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
GUISystem.prototype.update = function () {
|
|
90
|
+
// throw new Error('Method not implemented.');
|
|
91
|
+
};
|
|
92
|
+
return GUISystem;
|
|
93
|
+
}());
|
|
94
|
+
exports.GUISystem = GUISystem;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventManager, EventReceive, System } from 'entityx-ts';
|
|
2
|
+
export declare enum SpriteTypes {
|
|
3
|
+
SIMPLE = 0,
|
|
4
|
+
SLICED = 1,
|
|
5
|
+
TILED = 2,
|
|
6
|
+
FILLED = 3,
|
|
7
|
+
MESH = 4,
|
|
8
|
+
ANIMATION = 5
|
|
9
|
+
}
|
|
10
|
+
export declare class RenderSystem implements System {
|
|
11
|
+
configure(event_manager: EventManager): void;
|
|
12
|
+
receive(type: string, event: EventReceive): void;
|
|
13
|
+
update(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=RenderSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/systems/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EACuC,YAAY,EAAE,YAAY,EACtE,MAAM,EACP,MAAM,YAAY,CAAA;AAOnB,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AAED,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAUrC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY;IAkEzC,MAAM;CAGP"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RenderSystem = exports.SpriteTypes = void 0;
|
|
4
|
+
var entityx_ts_1 = require("entityx-ts");
|
|
5
|
+
var pixi_js_1 = require("pixi.js");
|
|
6
|
+
var __1 = require("..");
|
|
7
|
+
var RenderComponent_1 = require("../components/RenderComponent");
|
|
8
|
+
var LoadingBar_1 = require("../core/LoadingBar");
|
|
9
|
+
var SpriteTypes;
|
|
10
|
+
(function (SpriteTypes) {
|
|
11
|
+
SpriteTypes[SpriteTypes["SIMPLE"] = 0] = "SIMPLE";
|
|
12
|
+
SpriteTypes[SpriteTypes["SLICED"] = 1] = "SLICED";
|
|
13
|
+
SpriteTypes[SpriteTypes["TILED"] = 2] = "TILED";
|
|
14
|
+
SpriteTypes[SpriteTypes["FILLED"] = 3] = "FILLED";
|
|
15
|
+
SpriteTypes[SpriteTypes["MESH"] = 4] = "MESH";
|
|
16
|
+
SpriteTypes[SpriteTypes["ANIMATION"] = 5] = "ANIMATION";
|
|
17
|
+
})(SpriteTypes || (exports.SpriteTypes = SpriteTypes = {}));
|
|
18
|
+
var RenderSystem = /** @class */ (function () {
|
|
19
|
+
function RenderSystem() {
|
|
20
|
+
}
|
|
21
|
+
RenderSystem.prototype.configure = function (event_manager) {
|
|
22
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(RenderComponent_1.NodeRender), this);
|
|
23
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(RenderComponent_1.SpriteRender), this);
|
|
24
|
+
// event_manager.subscribe(ComponentAddedEvent(ImageRender), this)
|
|
25
|
+
// event_manager.subscribe(ComponentAddedEvent(MaskRender), this)
|
|
26
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(RenderComponent_1.GraphicsRender), this);
|
|
27
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentAddedEvent)(__1.NodeComp), this);
|
|
28
|
+
event_manager.subscribe((0, entityx_ts_1.ComponentRemovedEvent)(__1.NodeComp), this);
|
|
29
|
+
};
|
|
30
|
+
RenderSystem.prototype.receive = function (type, event) {
|
|
31
|
+
switch (type) {
|
|
32
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(RenderComponent_1.NodeRender): {
|
|
33
|
+
// console.log('NodeRender', event)
|
|
34
|
+
var ett = event.entity;
|
|
35
|
+
var nodeRenderComp = ett.getComponent(RenderComponent_1.NodeRender);
|
|
36
|
+
var node = new pixi_js_1.Container();
|
|
37
|
+
nodeRenderComp.node = ett.assign(new __1.NodeComp(node, ett));
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(RenderComponent_1.SpriteRender): {
|
|
41
|
+
// console.log('ComponentAddedEvent SpriteRender', event)
|
|
42
|
+
var ett = event.entity;
|
|
43
|
+
var spriteComp = ett.getComponent(RenderComponent_1.SpriteRender);
|
|
44
|
+
var spriteFrame = spriteComp.spriteFrame, type_1 = spriteComp.type, fillType = spriteComp.fillType, fillRange = spriteComp.fillRange, fillCenter = spriteComp.fillCenter;
|
|
45
|
+
var node = pixi_js_1.Sprite.from(spriteFrame);
|
|
46
|
+
if (type_1 === SpriteTypes.FILLED) {
|
|
47
|
+
// console.log('fillType', fillType)
|
|
48
|
+
var loadingBar = new LoadingBar_1.LoadingBar(fillType, node);
|
|
49
|
+
if (fillRange)
|
|
50
|
+
loadingBar.progress = fillRange;
|
|
51
|
+
if (fillCenter)
|
|
52
|
+
loadingBar.fillCenter = fillCenter;
|
|
53
|
+
spriteComp.loadingBar = loadingBar;
|
|
54
|
+
// node.setMidpoint(fillCenter)
|
|
55
|
+
}
|
|
56
|
+
// node.texture.rotate = 8
|
|
57
|
+
spriteComp.node = ett.assign(new __1.NodeComp(node, ett));
|
|
58
|
+
// spriteComp.node.anchorX = 0.5
|
|
59
|
+
// spriteComp.node.anchorY = 0.5
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
// case ComponentAddedEvent(MaskRender): {
|
|
63
|
+
// console.log('MaskRender', event.component);
|
|
64
|
+
// const ett = event.entity
|
|
65
|
+
// const maskComp = event.entity.getComponent(MaskRender)
|
|
66
|
+
// const { type, segments, inverted } = maskComp
|
|
67
|
+
// const node = new cc.ClippingNode()
|
|
68
|
+
// node.setInverted(inverted)
|
|
69
|
+
// maskComp.node = ett.assign(new NodeComp(node, ett))
|
|
70
|
+
// break
|
|
71
|
+
// }
|
|
72
|
+
case (0, entityx_ts_1.ComponentAddedEvent)(RenderComponent_1.GraphicsRender): {
|
|
73
|
+
console.log('MaskRender', event.component);
|
|
74
|
+
var ett = event.entity;
|
|
75
|
+
var graphics = event.entity.getComponent(RenderComponent_1.GraphicsRender);
|
|
76
|
+
var lineWidth = graphics.lineWidth, strokeColor = graphics.strokeColor, fillColor = graphics.fillColor;
|
|
77
|
+
var node = new pixi_js_1.Graphics();
|
|
78
|
+
node.beginFill(fillColor);
|
|
79
|
+
node.lineStyle(lineWidth, strokeColor);
|
|
80
|
+
graphics.node = ett.assign(new __1.NodeComp(node, ett));
|
|
81
|
+
// node.drawCircle(0, 0, 100)
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case (0, entityx_ts_1.ComponentRemovedEvent)(__1.NodeComp): {
|
|
85
|
+
var node = event.component;
|
|
86
|
+
if (node) {
|
|
87
|
+
node.instance.removeFromParent();
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
RenderSystem.prototype.update = function () {
|
|
96
|
+
// throw new Error('Method not implemented.');
|
|
97
|
+
};
|
|
98
|
+
return RenderSystem;
|
|
99
|
+
}());
|
|
100
|
+
exports.RenderSystem = RenderSystem;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@safe-engine/pixi",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"export": "safex build -p ios",
|
|
10
|
+
"start": "parcel src/index.html -p 8080",
|
|
11
|
+
"dev": "parcel src/index.html -p 8080 --no-cache",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"fix": "eslint ./src --ext .ts --fix"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@pixi/ui": "^2.1.5",
|
|
20
|
+
"entityx-ts": "^1.0.0",
|
|
21
|
+
"howler-pixi-loader-middleware": "^5.0.0",
|
|
22
|
+
"lodash": "^4.17.21",
|
|
23
|
+
"pixi-action-ease": "^1.0.12",
|
|
24
|
+
"pixi.js": "^8.4.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/lodash": "^4.17.7",
|
|
28
|
+
"typescript": "^5.6.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Application } from 'pixi.js'
|
|
2
|
+
import { actionManager } from 'pixi-action-ease'
|
|
3
|
+
|
|
4
|
+
import { GameWorld } from './gworld'
|
|
5
|
+
import { GUISystem } from './systems/GUISystem'
|
|
6
|
+
import { RenderSystem } from './systems/RenderSystem'
|
|
7
|
+
|
|
8
|
+
export const app = new Application()
|
|
9
|
+
|
|
10
|
+
export function setupResolution(designedResolution = { width: 720, height: 1280 }) {
|
|
11
|
+
const { width, height } = designedResolution
|
|
12
|
+
app.renderer.resize(width, height)
|
|
13
|
+
// app.stage.position.y = app.renderer.height / app.renderer.resolution
|
|
14
|
+
// app.stage.scale.y = -1
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function addGameCanvasTo(id = 'game') {
|
|
18
|
+
await app.init({
|
|
19
|
+
antialias: true,
|
|
20
|
+
resolution: window.devicePixelRatio,
|
|
21
|
+
eventFeatures: {
|
|
22
|
+
move: true,
|
|
23
|
+
/** disables the global move events which can be very expensive in large scenes */
|
|
24
|
+
globalMove: false,
|
|
25
|
+
click: true,
|
|
26
|
+
wheel: false,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
// app.ticker.speed = 0.5
|
|
30
|
+
// Listen for frame updates
|
|
31
|
+
app.ticker.add(() => {
|
|
32
|
+
const dt = app.ticker.deltaMS * 0.001
|
|
33
|
+
actionManager.update(dt)
|
|
34
|
+
GameWorld.Instance.update(dt)
|
|
35
|
+
})
|
|
36
|
+
Object.assign(app.canvas.style, {
|
|
37
|
+
width: `${window.innerWidth}px`,
|
|
38
|
+
// height: `${window.innerHeight}px`,
|
|
39
|
+
overflow: 'hidden',
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const gameDiv = document.getElementById(id)
|
|
43
|
+
gameDiv.appendChild(app.canvas)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function initWorld() {
|
|
47
|
+
GameWorld.Instance.systems.add(RenderSystem)
|
|
48
|
+
GameWorld.Instance.systems.add(GUISystem)
|
|
49
|
+
GameWorld.Instance.systems.configureOnce(RenderSystem)
|
|
50
|
+
GameWorld.Instance.systems.configureOnce(GUISystem)
|
|
51
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Constructor } from 'entityx-ts'
|
|
2
|
+
import { actionManager, Animation, CallFunc, DelayTime, Repeat, Sequence } from 'pixi-action-ease'
|
|
3
|
+
|
|
4
|
+
import { NodeComp } from './NodeComp'
|
|
5
|
+
|
|
6
|
+
export class EnhancedComponent {
|
|
7
|
+
constructor(...args: any[]) {
|
|
8
|
+
const [data] = args
|
|
9
|
+
if (data) {
|
|
10
|
+
// console.log('constructor', this.constructor.name, data)
|
|
11
|
+
Object.keys(data).forEach((key) => {
|
|
12
|
+
this[key] = data[key]
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
node: NodeComp
|
|
17
|
+
static hasRender = true
|
|
18
|
+
actionsMap: { [key: string]: Animation } = {}
|
|
19
|
+
addComponent<T extends EnhancedComponent>(instance): T {
|
|
20
|
+
return this.node.addComponent(instance)
|
|
21
|
+
}
|
|
22
|
+
getComponent<T extends ComponentType>(component: Constructor<T>): T {
|
|
23
|
+
return this.node.getComponent(component)
|
|
24
|
+
}
|
|
25
|
+
schedule(callback: (dt?: number) => void, interval: number, repeat = -1, delay = 0, key?: string) {
|
|
26
|
+
const action = Sequence.create(DelayTime.create(interval), CallFunc.create(callback))
|
|
27
|
+
const repeatAct = Repeat.create(action, repeat)
|
|
28
|
+
const seq = Sequence.create(DelayTime.create(delay), repeatAct)
|
|
29
|
+
const animation = actionManager.runAction(this.node.instance as any, seq)
|
|
30
|
+
this.actionsMap[key] = animation
|
|
31
|
+
}
|
|
32
|
+
unschedule(callback: (arg?: unknown) => void, key?: string) {
|
|
33
|
+
// this.node.instance.unschedule(callback.bind(this))
|
|
34
|
+
this.actionsMap[key].stop()
|
|
35
|
+
}
|
|
36
|
+
unscheduleAllCallbacks() {
|
|
37
|
+
Object.values(this.actionsMap).forEach((action: Animation) => {
|
|
38
|
+
action.stop()
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
scheduleOnce(callback: (arg?: unknown) => void, delay: number, key?: string) {
|
|
42
|
+
const action = Sequence.create(DelayTime.create(delay), CallFunc.create(callback))
|
|
43
|
+
const animation = actionManager.runAction(this.node.instance as any, action)
|
|
44
|
+
this.actionsMap[key] = animation
|
|
45
|
+
}
|
|
46
|
+
getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[] {
|
|
47
|
+
return this.node.getComponentsInChildren(component)
|
|
48
|
+
}
|
|
49
|
+
getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T {
|
|
50
|
+
return this.node.getComponentInChildren(component)
|
|
51
|
+
}
|
|
52
|
+
isEqual(other: EnhancedComponent) {
|
|
53
|
+
return this.node.entity.id === other.node.entity.id
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ComponentType = EnhancedComponent | NodeComp
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Assets, Text } from 'pixi.js'
|
|
2
|
+
|
|
3
|
+
import { Size, Vec2 } from '..'
|
|
4
|
+
import { Color4B } from '../core/Color'
|
|
5
|
+
import { ComponentX, NoRenderComponentX } from '../core/decorator'
|
|
6
|
+
import { LoadingBar, LoadingBarMode } from '../core/LoadingBar'
|
|
7
|
+
import { HtmlTextParser } from '../helper/html-text-parser'
|
|
8
|
+
|
|
9
|
+
const _htmlTextParser = new HtmlTextParser()
|
|
10
|
+
export const FillType = {
|
|
11
|
+
HORIZONTAL: 0,
|
|
12
|
+
VERTICAL: 1,
|
|
13
|
+
RADIAL: 2,
|
|
14
|
+
}
|
|
15
|
+
type Keys = keyof typeof FillType
|
|
16
|
+
type Values = (typeof FillType)[Keys]
|
|
17
|
+
|
|
18
|
+
export class ButtonComp extends NoRenderComponentX {
|
|
19
|
+
normalImage: string
|
|
20
|
+
selectedImage: string
|
|
21
|
+
disableImage: string
|
|
22
|
+
zoomScale: number
|
|
23
|
+
onPress: (target: ButtonComp) => void
|
|
24
|
+
|
|
25
|
+
setOnPress(cb: (target: ButtonComp) => void) {
|
|
26
|
+
this.onPress = cb
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
set enabled(val) {
|
|
30
|
+
this.node.instance.interactive = val
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class ProgressBarComp extends NoRenderComponentX {
|
|
35
|
+
mode = LoadingBarMode.BAR
|
|
36
|
+
private _progress: number
|
|
37
|
+
isReverse: boolean
|
|
38
|
+
|
|
39
|
+
get progress() {
|
|
40
|
+
return this._progress
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set progress(val: number) {
|
|
44
|
+
this._progress = val
|
|
45
|
+
;(this.node.instance as LoadingBar).progress = val
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class LabelComp extends ComponentX {
|
|
50
|
+
font: string
|
|
51
|
+
string: string
|
|
52
|
+
size = 64
|
|
53
|
+
|
|
54
|
+
getString() {
|
|
55
|
+
if (this.node.instance instanceof Text) {
|
|
56
|
+
return this.node.instance.text
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setString(val: string) {
|
|
61
|
+
if (this.node.instance instanceof Text) {
|
|
62
|
+
this.node.instance.text = val
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getSize() {
|
|
67
|
+
if (this.node.instance instanceof Text) {
|
|
68
|
+
return this.node.instance.style.fontSize
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
setSize(val) {
|
|
72
|
+
if (this.node.instance instanceof Text) {
|
|
73
|
+
this.node.instance.style.fontSize = val
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getFont() {
|
|
78
|
+
if (this.node.instance instanceof Text) {
|
|
79
|
+
return this.node.instance.style.fontFamily as string
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setFont(val: string) {
|
|
84
|
+
// console.log('set font', val, Assets.get(val))
|
|
85
|
+
if (this.node.instance instanceof Text) {
|
|
86
|
+
if (Assets.get(val)) this.node.instance.style.fontFamily = Assets.get(val).family
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class ScrollView extends ComponentX {
|
|
92
|
+
width: number
|
|
93
|
+
height: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class BlockInputEventsComp extends NoRenderComponentX {}
|
|
97
|
+
|
|
98
|
+
export class ProgressTimerComp extends ComponentX {
|
|
99
|
+
spriteFrame: string
|
|
100
|
+
fillType: Values
|
|
101
|
+
fillRange: number
|
|
102
|
+
fillCenter: Vec2
|
|
103
|
+
isReverse: boolean
|
|
104
|
+
|
|
105
|
+
getFillRange() {
|
|
106
|
+
// if (this.node.instance instanceof cc.ProgressTimer) {
|
|
107
|
+
// return this.node.instance.getPercentage() * 0.01
|
|
108
|
+
// }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
setFillStart(val: number) {
|
|
112
|
+
// if (this.node.instance instanceof cc.ProgressTimer) {
|
|
113
|
+
// this.node.instance.setMidpoint(Vec2(val, val))
|
|
114
|
+
// }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
setFillRange(val: number) {
|
|
118
|
+
// if (this.node.instance instanceof cc.ProgressTimer) {
|
|
119
|
+
// this.node.instance.setPercentage(val * 100)
|
|
120
|
+
// }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export class RichTextComp extends ComponentX {
|
|
125
|
+
protected font: string
|
|
126
|
+
protected string: string
|
|
127
|
+
protected size: number
|
|
128
|
+
|
|
129
|
+
getString() {
|
|
130
|
+
return this.string
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setString(val: string) {
|
|
134
|
+
this.string = val
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export class LabelOutlineComp extends NoRenderComponentX {
|
|
139
|
+
color: typeof Color4B
|
|
140
|
+
width: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export class LabelShadowComp extends NoRenderComponentX {
|
|
144
|
+
color: typeof Color4B
|
|
145
|
+
blur: number
|
|
146
|
+
offset: Size
|
|
147
|
+
}
|