@safe-engine/pixi 8.4.6 → 8.5.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.
Files changed (98) hide show
  1. package/README.md +14 -23
  2. package/dist/box2d-wasm/ContactListener.d.ts +1 -1
  3. package/dist/box2d-wasm/ContactListener.d.ts.map +1 -1
  4. package/dist/box2d-wasm/ContactListener.js +50 -18
  5. package/dist/box2d-wasm/PhysicsComponent.d.ts +27 -30
  6. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  7. package/dist/box2d-wasm/PhysicsComponent.js +44 -11
  8. package/dist/box2d-wasm/PhysicsSprite.d.ts +3 -0
  9. package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
  10. package/dist/box2d-wasm/PhysicsSprite.js +24 -3
  11. package/dist/box2d-wasm/PhysicsSystem.d.ts +4 -2
  12. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
  13. package/dist/box2d-wasm/PhysicsSystem.js +134 -44
  14. package/dist/collider/CollideComponent.d.ts +27 -10
  15. package/dist/collider/CollideComponent.d.ts.map +1 -1
  16. package/dist/collider/CollideComponent.js +10 -12
  17. package/dist/collider/helper/Intersection.d.ts +6 -6
  18. package/dist/collider/helper/Intersection.d.ts.map +1 -1
  19. package/dist/collider/helper/Intersection.js +4 -4
  20. package/dist/components/NodeComp.js +1 -1
  21. package/dist/helper/utils.d.ts +0 -6
  22. package/dist/helper/utils.d.ts.map +1 -1
  23. package/dist/helper/utils.js +0 -12
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -0
  27. package/{src/spine/lib/require-shim.ts → dist/spine/lib/assets/atlasLoader.d.ts} +5 -14
  28. package/dist/spine/lib/assets/atlasLoader.d.ts.map +1 -0
  29. package/dist/spine/lib/assets/atlasLoader.js +122 -0
  30. package/{src/spine/lib/darktint/DarkTintShader.ts → dist/spine/lib/assets/skeletonLoader.d.ts} +3 -47
  31. package/dist/spine/lib/assets/skeletonLoader.d.ts.map +1 -0
  32. package/dist/spine/lib/assets/skeletonLoader.js +70 -0
  33. package/package.json +6 -2
  34. package/.github/workflows/npm-publish.yml +0 -35
  35. package/dist/@types/safex.d.ts +0 -15
  36. package/src/@types/index.d.ts +0 -2
  37. package/src/app.ts +0 -91
  38. package/src/base/EnhancedComponent.ts +0 -38
  39. package/src/base/gworld.ts +0 -20
  40. package/src/base/index.ts +0 -14
  41. package/src/base/utils.ts +0 -23
  42. package/src/box2d-wasm/ContactListener.ts +0 -66
  43. package/src/box2d-wasm/PhysicsComponent.ts +0 -83
  44. package/src/box2d-wasm/PhysicsSprite.ts +0 -42
  45. package/src/box2d-wasm/PhysicsSystem.ts +0 -142
  46. package/src/box2d-wasm/debugDraw.ts +0 -249
  47. package/src/box2d-wasm/index.ts +0 -19
  48. package/src/collider/CollideComponent.ts +0 -257
  49. package/src/collider/CollideSystem.ts +0 -166
  50. package/src/collider/helper/Intersection.ts +0 -139
  51. package/src/collider/helper/utils.ts +0 -37
  52. package/src/collider/index.ts +0 -16
  53. package/src/components/BaseComponent.ts +0 -17
  54. package/src/components/NodeComp.ts +0 -442
  55. package/src/components/Scene.ts +0 -17
  56. package/src/core/Color.ts +0 -7
  57. package/src/core/LoadingBar.ts +0 -63
  58. package/src/core/NodePool.ts +0 -28
  59. package/src/core/Size.ts +0 -21
  60. package/src/core/Vec2.ts +0 -108
  61. package/src/core/director.ts +0 -11
  62. package/src/core/index.ts +0 -7
  63. package/src/core/loader.ts +0 -14
  64. package/src/core/math.ts +0 -22
  65. package/src/dragonbones/DragonBonesComponent.ts +0 -32
  66. package/src/dragonbones/DragonBonesSystem.ts +0 -35
  67. package/src/dragonbones/index.ts +0 -11
  68. package/src/gui/GUIComponent.ts +0 -155
  69. package/src/gui/GUISystem.ts +0 -125
  70. package/src/helper/utils.ts +0 -50
  71. package/src/index.ts +0 -19
  72. package/src/norender/NoRenderComponent.ts +0 -60
  73. package/src/norender/NoRenderSystem.ts +0 -67
  74. package/src/norender/Touch.ts +0 -37
  75. package/src/planck/PhysicsComponent.ts +0 -83
  76. package/src/planck/PhysicsSprite.ts +0 -43
  77. package/src/planck/PhysicsSystem.ts +0 -201
  78. package/src/planck/index.ts +0 -3
  79. package/src/render/RenderComponent.ts +0 -132
  80. package/src/render/RenderSystem.ts +0 -64
  81. package/src/richtext/RichTextComp.ts +0 -50
  82. package/src/richtext/RichTextSystem.ts +0 -26
  83. package/src/richtext/html-text-parser.ts +0 -87
  84. package/src/richtext/index.ts +0 -8
  85. package/src/spine/SpineComponent.ts +0 -18
  86. package/src/spine/SpineSystem.ts +0 -30
  87. package/src/spine/index.ts +0 -11
  88. package/src/spine/lib/BatchableSpineSlot.ts +0 -138
  89. package/src/spine/lib/Spine.ts +0 -894
  90. package/src/spine/lib/SpineDebugRenderer.ts +0 -615
  91. package/src/spine/lib/SpinePipe.ts +0 -203
  92. package/src/spine/lib/SpineTexture.ts +0 -143
  93. package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
  94. package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
  95. package/src/spine/lib/darktint/darkTintBit.ts +0 -77
  96. package/src/spine/lib/index.ts +0 -43
  97. package/tsconfig.json +0 -18
  98. /package/{dist/@types → @types}/index.d.ts +0 -0
@@ -0,0 +1,122 @@
1
+ /** ****************************************************************************
2
+ * Spine Runtimes License Agreement
3
+ * Last updated July 28, 2023. Replaces all prior versions.
4
+ *
5
+ * Copyright (c) 2013-2023, Esoteric Software LLC
6
+ *
7
+ * Integration of the Spine Runtimes into software or otherwise creating
8
+ * derivative works of the Spine Runtimes is permitted under the terms and
9
+ * conditions of Section 2 of the Spine Editor License Agreement:
10
+ * http://esotericsoftware.com/spine-editor-license
11
+ *
12
+ * Otherwise, it is permitted to integrate the Spine Runtimes into software or
13
+ * otherwise create derivative works of the Spine Runtimes (collectively,
14
+ * "Products"), provided that each user of the Products must obtain their own
15
+ * Spine Editor license and redistribution of the Products in any form must
16
+ * include this license and copyright notice.
17
+ *
18
+ * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
19
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
22
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
24
+ * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
25
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
27
+ * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *****************************************************************************/
29
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
30
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
+ return new (P || (P = Promise))(function (resolve, reject) {
32
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
35
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
36
+ });
37
+ };
38
+ import { checkExtension, DOMAdapter, extensions, ExtensionType, LoaderParserPriority, path, Resolver, TextureSource } from 'pixi.js';
39
+ import { SpineTexture } from '../SpineTexture.js';
40
+ import { TextureAtlas } from '@esotericsoftware/spine-core';
41
+ const spineTextureAtlasLoader = {
42
+ extension: ExtensionType.Asset,
43
+ resolver: {
44
+ test: (value) => checkExtension(value, ".atlas"),
45
+ parse: (value) => {
46
+ var _a, _b, _c;
47
+ const split = value.split('.');
48
+ return {
49
+ resolution: parseFloat((_c = (_b = (_a = Resolver.RETINA_PREFIX) === null || _a === void 0 ? void 0 : _a.exec(value)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : '1'),
50
+ format: split[split.length - 2],
51
+ src: value,
52
+ };
53
+ },
54
+ },
55
+ loader: {
56
+ extension: {
57
+ type: ExtensionType.LoadParser,
58
+ priority: LoaderParserPriority.Normal,
59
+ name: 'spineTextureAtlasLoader',
60
+ },
61
+ test(url) {
62
+ return checkExtension(url, '.atlas');
63
+ },
64
+ load(url) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const response = yield DOMAdapter.get().fetch(url);
67
+ const txt = yield response.text();
68
+ return txt;
69
+ });
70
+ },
71
+ testParse(asset, options) {
72
+ const isExtensionRight = checkExtension(options.src, '.atlas');
73
+ const isString = typeof asset === 'string';
74
+ return Promise.resolve(isExtensionRight && isString);
75
+ },
76
+ unload(atlas) {
77
+ atlas.dispose();
78
+ },
79
+ parse(asset, options, loader) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const metadata = options.data || {};
82
+ let basePath = path.dirname(options.src);
83
+ if (basePath && basePath.lastIndexOf('/') !== basePath.length - 1) {
84
+ basePath += '/';
85
+ }
86
+ // Retval is going to be a texture atlas. However we need to wait for it's callback to resolve this promise.
87
+ const retval = new TextureAtlas(asset);
88
+ // If the user gave me only one texture, that one is assumed to be the "first" texture in the atlas
89
+ if (metadata.images instanceof TextureSource || typeof metadata.images === 'string') {
90
+ const pixiTexture = metadata.images;
91
+ metadata.images = {};
92
+ metadata.images[retval.pages[0].name] = pixiTexture;
93
+ }
94
+ // we will wait for all promises for the textures at the same time at the end.
95
+ const textureLoadingPromises = [];
96
+ // fill the pages
97
+ for (const page of retval.pages) {
98
+ const pageName = page.name;
99
+ const providedPage = (metadata === null || metadata === void 0 ? void 0 : metadata.images) ? metadata.images[pageName] : undefined;
100
+ if (providedPage instanceof TextureSource) {
101
+ page.setTexture(SpineTexture.from(providedPage));
102
+ }
103
+ else {
104
+ // eslint-disable-next-line max-len
105
+ const url = providedPage !== null && providedPage !== void 0 ? providedPage : path.normalize([...basePath.split(path.sep), pageName].join(path.sep));
106
+ const assetsToLoadIn = {
107
+ src: url,
108
+ data: Object.assign(Object.assign({}, metadata.imageMetadata), { alphaMode: page.pma ? 'premultiplied-alpha' : 'premultiply-alpha-on-upload' })
109
+ };
110
+ const pixiPromise = loader.load(assetsToLoadIn).then((texture) => {
111
+ page.setTexture(SpineTexture.from(texture.source));
112
+ });
113
+ textureLoadingPromises.push(pixiPromise);
114
+ }
115
+ }
116
+ yield Promise.all(textureLoadingPromises);
117
+ return retval;
118
+ });
119
+ },
120
+ },
121
+ };
122
+ extensions.add(spineTextureAtlasLoader);
@@ -1,4 +1,4 @@
1
- /******************************************************************************
1
+ /** ****************************************************************************
2
2
  * Spine Runtimes License Agreement
3
3
  * Last updated July 28, 2023. Replaces all prior versions.
4
4
  *
@@ -26,49 +26,5 @@
26
26
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
27
27
  * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
  *****************************************************************************/
29
-
30
- import {
31
- colorBit,
32
- colorBitGl,
33
- compileHighShaderGlProgram,
34
- compileHighShaderGpuProgram,
35
- generateTextureBatchBit,
36
- generateTextureBatchBitGl,
37
- getBatchSamplersUniformGroup,
38
- roundPixelsBit,
39
- roundPixelsBitGl,
40
- Shader
41
- } from 'pixi.js';
42
- import { darkTintBit, darkTintBitGl } from './darkTintBit.js';
43
-
44
- export class DarkTintShader extends Shader {
45
- constructor (maxTextures: number) {
46
- const glProgram = compileHighShaderGlProgram({
47
- name: 'dark-tint-batch',
48
- bits: [
49
- colorBitGl,
50
- darkTintBitGl,
51
- generateTextureBatchBitGl(maxTextures),
52
- roundPixelsBitGl,
53
- ]
54
- });
55
-
56
- const gpuProgram = compileHighShaderGpuProgram({
57
- name: 'dark-tint-batch',
58
- bits: [
59
- colorBit,
60
- darkTintBit,
61
- generateTextureBatchBit(maxTextures),
62
- roundPixelsBit,
63
- ]
64
- });
65
-
66
- super({
67
- glProgram,
68
- gpuProgram,
69
- resources: {
70
- batchSamplers: getBatchSamplersUniformGroup(maxTextures),
71
- }
72
- });
73
- }
74
- }
29
+ export {};
30
+ //# sourceMappingURL=skeletonLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skeletonLoader.d.ts","sourceRoot":"","sources":["../../../../src/spine/lib/assets/skeletonLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;+EA2B+E"}
@@ -0,0 +1,70 @@
1
+ /** ****************************************************************************
2
+ * Spine Runtimes License Agreement
3
+ * Last updated July 28, 2023. Replaces all prior versions.
4
+ *
5
+ * Copyright (c) 2013-2023, Esoteric Software LLC
6
+ *
7
+ * Integration of the Spine Runtimes into software or otherwise creating
8
+ * derivative works of the Spine Runtimes is permitted under the terms and
9
+ * conditions of Section 2 of the Spine Editor License Agreement:
10
+ * http://esotericsoftware.com/spine-editor-license
11
+ *
12
+ * Otherwise, it is permitted to integrate the Spine Runtimes into software or
13
+ * otherwise create derivative works of the Spine Runtimes (collectively,
14
+ * "Products"), provided that each user of the Products must obtain their own
15
+ * Spine Editor license and redistribution of the Products in any form must
16
+ * include this license and copyright notice.
17
+ *
18
+ * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
19
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
22
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
24
+ * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
25
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
27
+ * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *****************************************************************************/
29
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
30
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
+ return new (P || (P = Promise))(function (resolve, reject) {
32
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
35
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
36
+ });
37
+ };
38
+ import { checkExtension, DOMAdapter, extensions, ExtensionType, LoaderParserPriority } from 'pixi.js';
39
+ function isJson(resource) {
40
+ return Object.prototype.hasOwnProperty.call(resource, 'bones');
41
+ }
42
+ function isBuffer(resource) {
43
+ return resource instanceof Uint8Array;
44
+ }
45
+ const spineLoaderExtension = {
46
+ extension: ExtensionType.Asset,
47
+ loader: {
48
+ extension: {
49
+ type: ExtensionType.LoadParser,
50
+ priority: LoaderParserPriority.Normal,
51
+ name: 'spineSkeletonLoader',
52
+ },
53
+ test(url) {
54
+ return checkExtension(url, '.skel');
55
+ },
56
+ load(url) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const response = yield DOMAdapter.get().fetch(url);
59
+ const buffer = new Uint8Array(yield response.arrayBuffer());
60
+ return buffer;
61
+ });
62
+ },
63
+ testParse(asset, options) {
64
+ const isJsonSpineModel = checkExtension(options.src, '.json') && isJson(asset);
65
+ const isBinarySpineModel = checkExtension(options.src, '.skel') && isBuffer(asset);
66
+ return Promise.resolve(isJsonSpineModel || isBinarySpineModel);
67
+ },
68
+ },
69
+ };
70
+ extensions.add(spineLoaderExtension);
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@safe-engine/pixi",
3
- "version": "8.4.6",
3
+ "version": "8.5.1",
4
4
  "description": "safex pixi plugin",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "@types"
11
+ ],
8
12
  "scripts": {
9
13
  "export": "safex build -p ios",
10
14
  "start": "parcel src/index.html -p 8080",
11
15
  "dev": "parcel src/index.html -p 8080 --no-cache",
12
- "build": "tsc & copyfiles -f ./src/@types/* ./dist/@types",
16
+ "build": "tsc",
13
17
  "fix": "eslint ./src --ext .ts --fix"
14
18
  },
15
19
  "keywords": [],
@@ -1,35 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Publish NPM Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
- workflow_dispatch: # Allows you to run this workflow manually
10
-
11
- jobs:
12
- build:
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v4
16
- - uses: actions/setup-node@v3
17
- with:
18
- node-version: 20
19
- - run: npm ci
20
- - run: npm run build
21
-
22
- publish-npm:
23
- needs: build
24
- runs-on: ubuntu-latest
25
- steps:
26
- - uses: actions/checkout@v4
27
- - uses: actions/setup-node@v3
28
- with:
29
- node-version: 20
30
- registry-url: https://registry.npmjs.org/
31
- - run: npm ci
32
- - run: npm run build
33
- - run: npm publish
34
- env:
35
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
@@ -1,15 +0,0 @@
1
- import { NodeComp } from "..";
2
-
3
- interface BaseComponentProps {
4
- $ref?: object;
5
- $refNode?: NodeComp<any>
6
- $push?: object[];
7
- node?: Partial<NodeComp>;
8
- }
9
-
10
- interface NodeCompProps {
11
- nodeName?: string
12
- }
13
-
14
- interface LoadingBarProps {
15
- }
@@ -1,2 +0,0 @@
1
- type Float = number
2
- type Integer = number
package/src/app.ts DELETED
@@ -1,91 +0,0 @@
1
- import { actionManager } from 'pixi-action-ease'
2
- import { Application, AssetsClass, Renderer } from 'pixi.js'
3
-
4
- import { GameWorld } from './base'
5
- import { CollideSystem } from './collider'
6
- import { GUISystem } from './gui/GUISystem'
7
- import { NoRenderSystem } from './norender/NoRenderSystem'
8
- import { RenderSystem } from './render/RenderSystem'
9
-
10
- export async function startGame(
11
- defaultFont,
12
- designedResolution = { width: 720, height: 1280 },
13
- assetManager: AssetsClass,
14
- id = 'gameCanvas',
15
- ): Promise<Application<Renderer>> {
16
- const app = new Application()
17
- await app.init({
18
- antialias: true,
19
- resolution: window.devicePixelRatio,
20
- resizeTo: window,
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
- canvas: document.getElementById(id) as HTMLCanvasElement,
29
- })
30
- // GameWorld.Instance.setup(NodeComp, app.stage)
31
- Object.assign(app.canvas.style, {
32
- width: `${window.innerWidth}px`,
33
- height: `${window.innerHeight}px`,
34
- overflow: 'visible',
35
- })
36
- const { width, height } = designedResolution
37
- app.renderer.resize(width, height)
38
- // app.stage.position.y = app.renderer.height / app.renderer.resolution
39
- // app.stage.scale.y = -1
40
- GameWorld.Instance.app = app
41
- GameWorld.Instance.assetManager = assetManager
42
- initWorld(defaultFont)
43
- startGameLoop(GameWorld.Instance)
44
- return app
45
- }
46
-
47
- function startGameLoop(world: GameWorld) {
48
- // Listen for frame updates
49
- world.app.ticker.add(() => {
50
- const dt = world.app.ticker.deltaMS * 0.001
51
- actionManager.update(dt)
52
- world.update(dt)
53
- })
54
- // app.ticker.speed = 0.5
55
- }
56
-
57
- // const systemsList = [RenderSystem, GUISystem, SpineSystem, DragonBonesSystem, CollideSystem, NoRenderSystem]
58
- // export function startGameSystems(list = []) {
59
- // const world = GameWorld.Instance
60
- // systemsList.forEach(system => {
61
- // world.systems.add(system)
62
- // world.systems.configureOnce(system)
63
- // })
64
- // world.listUpdate.push(CollideSystem)
65
- // // world.listUpdate.push(PhysicsSystem)
66
- // list.forEach(system => {
67
- // world.systems.add(system)
68
- // world.systems.configureOnce(system)
69
- // world.listUpdate.push(system)
70
- // })
71
- // startGameLoop(world)
72
- // // console.log('startGameLoop', world.listUpdate)
73
- // }
74
-
75
- function initWorld(defaultFont?: string) {
76
- const world = GameWorld.Instance
77
- world.systems.add(RenderSystem)
78
- world.systems.add(CollideSystem)
79
- world.systems.add(GUISystem)
80
- world.systems.add(NoRenderSystem)
81
- world.listUpdate.push(CollideSystem)
82
- world.systems.configureOnce(RenderSystem)
83
- world.systems.configureOnce(CollideSystem)
84
- world.systems.configureOnce(GUISystem)
85
- world.systems.configureOnce(NoRenderSystem)
86
- if (defaultFont) {
87
- const guiSystem = world.systems.get(GUISystem)
88
- guiSystem.defaultFont = defaultFont
89
- }
90
- // startGameLoop(world, app)
91
- }
@@ -1,38 +0,0 @@
1
- import { Constructor } from 'entityx-ts'
2
- import { BaseComponentProps } from '..'
3
- import { NodeComp } from '../components/NodeComp'
4
-
5
- export class EnhancedComponent<Props = {}, N extends NodeComp<any> = NodeComp<any>> {
6
- props: Props = {} as any
7
- enabled = true
8
- constructor(data?: BaseComponentProps<EnhancedComponent> & Props) {
9
- this.init(data)
10
- }
11
- init(data?: Props) {
12
- if (data) {
13
- // console.log('constructor', this.constructor.name, data)
14
- Object.keys(data).forEach((key) => {
15
- this.props[key] = data[key]
16
- })
17
- }
18
- }
19
- node: N
20
-
21
- addComponent<T extends EnhancedComponent>(instance): T {
22
- return this.node.addComponent(instance)
23
- }
24
- getComponent<T extends ComponentType>(component: Constructor<T>): T {
25
- return this.node.getComponent(component)
26
- }
27
- getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[] {
28
- return this.node.getComponentsInChildren(component)
29
- }
30
- getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T {
31
- return this.node.getComponentInChildren(component)
32
- }
33
- isEqual(other: EnhancedComponent) {
34
- return this.node.entity.id === other.node.entity.id
35
- }
36
- }
37
-
38
- export type ComponentType = EnhancedComponent | NodeComp
@@ -1,20 +0,0 @@
1
- import { Constructor, System, World } from 'entityx-ts'
2
- import { Application, AssetsClass } from 'pixi.js'
3
-
4
- export class GameWorld extends World {
5
- listUpdate: (System | Constructor<System>)[] = []
6
- app: Application
7
- assetManager: AssetsClass
8
- update(dt: number) {
9
- this.listUpdate.forEach((system: any) => {
10
- this.systems.update(system, dt)
11
- })
12
- }
13
-
14
- private static _instance: GameWorld
15
-
16
- public static get Instance() {
17
- // Do you need arguments? Make it a regular static method instead.
18
- return this._instance || (this._instance = new this())
19
- }
20
- }
package/src/base/index.ts DELETED
@@ -1,14 +0,0 @@
1
- import { NodeComp } from '../components/NodeComp'
2
-
3
- export * from './EnhancedComponent'
4
- export * from './gworld'
5
- export * from './utils'
6
-
7
- export interface BaseComponentProps<T> {
8
- $ref?: T
9
- $push?: T[]
10
- $refNode?: NodeComp
11
- $pushNode?: NodeComp[]
12
- node?: Partial<NodeComp>
13
- // [$key: `$${string}`]: string
14
- }
package/src/base/utils.ts DELETED
@@ -1,23 +0,0 @@
1
- import { Constructor } from 'entityx-ts'
2
-
3
- import { GameWorld } from '..'
4
- import { ComponentX, NoRenderComponentX } from '../components/BaseComponent'
5
-
6
- export type GetProps<T> = T extends ComponentX<infer P> ? P : T extends NoRenderComponentX<infer Q> ? Q : never
7
-
8
- export function instantiate<T extends ComponentX>(ComponentType: Constructor<T>, data?: GetProps<T>): T {
9
- const instance = new ComponentType()
10
- instance.init(data)
11
- // console.log(ComponentType.name, data, instance)
12
- if (!instance.render) {
13
- return instance
14
- }
15
- return instance.render()
16
- }
17
-
18
- export function loadScene<T extends ComponentX>(ComponentType: Constructor<T>) {
19
- const world = GameWorld.Instance
20
- world.entities.reset()
21
- const instance = new ComponentType()
22
- instance.render()
23
- }
@@ -1,66 +0,0 @@
1
- import { NodeComp } from "..";
2
- import { ColliderPhysics } from "./PhysicsComponent";
3
- type Meta = { [key: number]: NodeComp }
4
- export const makeContactListener = (world: Box2D.b2World, metadata: Meta, box2D: typeof Box2D) => {
5
- const { JSContactListener, getPointer, NULL } = box2D
6
- function getContactById(contact: number) {
7
- for (let contactList = world.GetContactList(); getPointer(contactList) !== getPointer(NULL); contactList = contactList.GetNext()) {
8
- if (getPointer(contactList) === contact) {
9
- console.log('contactBegin', contact, getPointer(contactList), getPointer(NULL));
10
- return contactList
11
- }
12
- }
13
- }
14
- const listener = Object.assign(new JSContactListener(), {
15
- BeginContact(contact: Box2D.b2Contact | number): void {
16
- if (typeof contact === 'number') {
17
- contact = getContactById(contact)
18
- }
19
- const ett1: NodeComp = metadata[getPointer(contact.GetFixtureA().GetBody())]
20
- const ett2: NodeComp = metadata[getPointer(contact.GetFixtureB().GetBody())]
21
- // world.addPostStepCallback(() => {
22
- // // log('addPostStepCallback');
23
- // listRemoveShape.forEach((s) => world.removeShape(s))
24
- // listRemoveBody.forEach((b) => world.removeBody(b))
25
- // listRemoveBody = []
26
- // listRemoveShape = []
27
- // })
28
- const phys1 = ett1.getComponent(ColliderPhysics)
29
- const phys2 = ett2.getComponent(ColliderPhysics)
30
- if (phys1 && phys2) {
31
- if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionEnter')) {
32
- phys1.props.onCollisionEnter(phys2)
33
- }
34
- if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionEnter')) {
35
- phys2.props.onCollisionEnter(phys1)
36
- }
37
- }
38
- },
39
- EndContact(contact: Box2D.b2Contact | number): void {
40
- if (typeof contact === 'number') {
41
- contact = getContactById(contact)
42
- }
43
- const ett1: NodeComp = metadata[getPointer(contact.GetFixtureA().GetBody())]
44
- const ett2: NodeComp = metadata[getPointer(contact.GetFixtureB().GetBody())]
45
- // const event1 = ett1.getComponent(NodeComp)
46
- const phys1 = ett1.getComponent(ColliderPhysics)
47
- const phys2 = ett2.getComponent(ColliderPhysics)
48
- // const event2 = ett2.getComponent(NodeComp)
49
- if (phys1 && phys2) {
50
- if (Object.prototype.hasOwnProperty.call(phys1, 'onCollisionExit')) {
51
- phys1.props.onCollisionExit(phys2)
52
- }
53
- if (Object.prototype.hasOwnProperty.call(phys2, 'onCollisionExit')) {
54
- phys2.props.onCollisionExit(phys1)
55
- }
56
- }
57
- },
58
- PreSolve(contact: Box2D.b2Contact | number, oldManifold: Box2D.b2Manifold | number): void {
59
- console.log('collisionSeparate');
60
- },
61
- PostSolve(contact: Box2D.b2Contact | number, impulse: Box2D.b2ContactImpulse | number): void {
62
- console.log('collisionPost');
63
- }
64
- });
65
- return listener
66
- }
@@ -1,83 +0,0 @@
1
- import { BodyType, Vec2 } from 'planck'
2
- import { NoRenderComponentX } from '..'
3
- import { PhysicsSprite } from './PhysicsSprite'
4
-
5
- interface RigidBodyProps {
6
- type?: BodyType
7
- density?: Float
8
- restitution?: Float
9
- friction?: Float
10
- gravityScale?: Float
11
- }
12
-
13
- export class RigidBody extends NoRenderComponentX<RigidBodyProps> {
14
- body: Box2D.b2Body
15
- // set linearVelocity(vel: Vec2) {
16
- // if (!this.node) {
17
- // return
18
- // }
19
- // const physics = this.node.instance
20
- // if (physics instanceof Sprite) {
21
- // physics.getBody().setVel(vel)
22
- // }
23
- // }
24
-
25
- // get linearVelocity() {
26
- // if (!this.node) {
27
- // return Vec2.ZERO
28
- // }
29
- // const physics = this.node.instance
30
- // const vel = (physics as Sprite).getBody().getVel()
31
- // return v2(vel)
32
- // }
33
- }
34
-
35
- interface PhysicsMaterialProps {
36
- friction?: number
37
- restitution?: number
38
- density?: number
39
- }
40
- export class PhysicsMaterial extends NoRenderComponentX<PhysicsMaterialProps> {
41
-
42
- }
43
-
44
- interface ColliderPhysicsProps {
45
- tag?: number
46
- group?: number
47
- offset?: Vec2
48
- onCollisionEnter?: (other: ColliderPhysics) => void
49
- onCollisionExit?: (other: ColliderPhysics) => void
50
- onCollisionStay?: (other: ColliderPhysics) => void
51
- }
52
-
53
- export class ColliderPhysics<T extends ColliderPhysicsProps = ColliderPhysicsProps> extends NoRenderComponentX<T, PhysicsSprite['node']> {
54
- enabled = true
55
- instance: PhysicsSprite
56
- }
57
-
58
- interface BoxColliderPhysicsProps extends ColliderPhysicsProps {
59
- width: number
60
- height: number
61
- }
62
- export class BoxColliderPhysics extends ColliderPhysics<BoxColliderPhysicsProps> {
63
-
64
- // set onCollisionEnter(val) {
65
- // const phys1 = this.getComponent(ColliderPhysics)
66
- // phys1._onCollisionEnter = val
67
- // }
68
-
69
- // get onCollisionEnter() {
70
- // const phys1 = this.getComponent(ColliderPhysics)
71
- // return phys1._onCollisionEnter
72
- // }
73
- }
74
- interface CircleColliderPhysicsProps extends ColliderPhysicsProps {
75
- radius: number
76
- }
77
- export class CircleColliderPhysics extends ColliderPhysics<CircleColliderPhysicsProps> {
78
- }
79
- interface PolygonColliderPhysicsProps extends ColliderPhysicsProps {
80
- points: Array<Vec2>
81
- }
82
- export class PolygonColliderPhysics extends ColliderPhysics<PolygonColliderPhysicsProps> {
83
- }