@safe-engine/pixi 8.3.7 → 8.4.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 (139) hide show
  1. package/.github/workflows/npm-publish.yml +35 -0
  2. package/README.md +70 -5
  3. package/dist/app.d.ts +2 -5
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/app.js +44 -27
  6. package/dist/base/gworld.d.ts +2 -0
  7. package/dist/base/gworld.d.ts.map +1 -1
  8. package/dist/box2d-wasm/ContactListener.d.ts +12 -0
  9. package/dist/box2d-wasm/ContactListener.d.ts.map +1 -0
  10. package/dist/box2d-wasm/ContactListener.js +64 -0
  11. package/dist/box2d-wasm/PhysicsComponent.d.ts +50 -0
  12. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -0
  13. package/dist/box2d-wasm/PhysicsComponent.js +17 -0
  14. package/dist/box2d-wasm/PhysicsSprite.d.ts +11 -0
  15. package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -0
  16. package/dist/box2d-wasm/PhysicsSprite.js +30 -0
  17. package/dist/box2d-wasm/PhysicsSystem.d.ts +17 -0
  18. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -0
  19. package/dist/box2d-wasm/PhysicsSystem.js +145 -0
  20. package/dist/box2d-wasm/debugDraw.d.ts +67 -0
  21. package/dist/box2d-wasm/debugDraw.d.ts.map +1 -0
  22. package/dist/box2d-wasm/debugDraw.js +224 -0
  23. package/dist/box2d-wasm/index.d.ts +6 -0
  24. package/dist/box2d-wasm/index.d.ts.map +1 -0
  25. package/dist/box2d-wasm/index.js +17 -0
  26. package/dist/collider/CollideComponent.d.ts.map +1 -1
  27. package/dist/collider/CollideComponent.js +12 -13
  28. package/dist/collider/CollideSystem.d.ts.map +1 -1
  29. package/dist/collider/CollideSystem.js +1 -2
  30. package/dist/collider/helper/utils.d.ts +2 -0
  31. package/dist/collider/helper/utils.d.ts.map +1 -1
  32. package/dist/collider/helper/utils.js +22 -0
  33. package/dist/collider/index.d.ts +1 -0
  34. package/dist/collider/index.d.ts.map +1 -1
  35. package/dist/collider/index.js +12 -0
  36. package/dist/components/NodeComp.d.ts +6 -4
  37. package/dist/components/NodeComp.d.ts.map +1 -1
  38. package/dist/components/NodeComp.js +13 -13
  39. package/dist/components/Scene.d.ts.map +1 -1
  40. package/dist/components/Scene.js +3 -4
  41. package/dist/core/director.d.ts.map +1 -1
  42. package/dist/core/director.js +4 -3
  43. package/dist/dragonbones/DragonBonesSystem.d.ts +2 -1
  44. package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -1
  45. package/dist/dragonbones/DragonBonesSystem.js +2 -0
  46. package/dist/dragonbones/index.d.ts +1 -0
  47. package/dist/dragonbones/index.d.ts.map +1 -1
  48. package/dist/dragonbones/index.js +7 -0
  49. package/dist/gui/GUIComponent.d.ts +0 -9
  50. package/dist/gui/GUIComponent.d.ts.map +1 -1
  51. package/dist/gui/GUIComponent.js +0 -37
  52. package/dist/gui/GUISystem.d.ts +1 -0
  53. package/dist/gui/GUISystem.d.ts.map +1 -1
  54. package/dist/gui/GUISystem.js +2 -15
  55. package/dist/index.d.ts +1 -0
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +1 -0
  58. package/dist/planck/PhysicsComponent.d.ts +7 -7
  59. package/dist/planck/PhysicsComponent.js +4 -4
  60. package/dist/planck/PhysicsSystem.js +12 -12
  61. package/dist/richtext/RichTextComp.d.ts +17 -0
  62. package/dist/richtext/RichTextComp.d.ts.map +1 -0
  63. package/dist/richtext/RichTextComp.js +38 -0
  64. package/dist/richtext/RichTextSystem.d.ts +7 -0
  65. package/dist/richtext/RichTextSystem.d.ts.map +1 -0
  66. package/dist/richtext/RichTextSystem.js +25 -0
  67. package/dist/richtext/html-text-parser.d.ts +20 -0
  68. package/dist/richtext/html-text-parser.d.ts.map +1 -0
  69. package/dist/richtext/html-text-parser.js +64 -0
  70. package/dist/richtext/index.d.ts +3 -0
  71. package/dist/richtext/index.d.ts.map +1 -0
  72. package/dist/richtext/index.js +7 -0
  73. package/dist/spine/index.d.ts +1 -0
  74. package/dist/spine/index.d.ts.map +1 -1
  75. package/dist/spine/index.js +7 -0
  76. package/package.json +9 -11
  77. package/src/@types/index.d.ts +2 -0
  78. package/src/@types/safex.d.ts +15 -0
  79. package/src/app.ts +85 -0
  80. package/src/base/EnhancedComponent.ts +37 -0
  81. package/src/base/gworld.ts +19 -0
  82. package/src/base/index.ts +3 -0
  83. package/src/base/utils.ts +23 -0
  84. package/src/box2d-wasm/ContactListener.ts +66 -0
  85. package/src/box2d-wasm/PhysicsComponent.ts +83 -0
  86. package/src/box2d-wasm/PhysicsSprite.ts +42 -0
  87. package/src/box2d-wasm/PhysicsSystem.ts +145 -0
  88. package/src/box2d-wasm/debugDraw.ts +257 -0
  89. package/src/box2d-wasm/index.ts +19 -0
  90. package/src/collider/CollideComponent.ts +257 -0
  91. package/src/collider/CollideSystem.ts +166 -0
  92. package/src/collider/helper/Intersection.ts +139 -0
  93. package/src/collider/helper/utils.ts +37 -0
  94. package/src/collider/index.ts +16 -0
  95. package/src/components/BaseComponent.ts +17 -0
  96. package/src/components/NodeComp.ts +434 -0
  97. package/src/components/Scene.ts +17 -0
  98. package/src/core/Color.ts +7 -0
  99. package/src/core/LoadingBar.ts +63 -0
  100. package/src/core/NodePool.ts +28 -0
  101. package/src/core/Size.ts +21 -0
  102. package/src/core/director.ts +11 -0
  103. package/src/core/math.ts +13 -0
  104. package/src/dragonbones/DragonBonesComponent.ts +32 -0
  105. package/src/dragonbones/DragonBonesSystem.ts +35 -0
  106. package/src/dragonbones/index.ts +11 -0
  107. package/src/gui/GUIComponent.ts +159 -0
  108. package/src/gui/GUISystem.ts +116 -0
  109. package/src/helper/utils.ts +50 -0
  110. package/src/index.ts +23 -0
  111. package/src/norender/NoRenderComponent.ts +60 -0
  112. package/src/norender/NoRenderSystem.ts +66 -0
  113. package/src/planck/PhysicsComponent.ts +83 -0
  114. package/src/planck/PhysicsSprite.ts +43 -0
  115. package/src/planck/PhysicsSystem.ts +201 -0
  116. package/src/planck/index.ts +3 -0
  117. package/src/render/RenderComponent.ts +138 -0
  118. package/src/render/RenderSystem.ts +67 -0
  119. package/src/richtext/RichTextComp.ts +46 -0
  120. package/src/richtext/RichTextSystem.ts +26 -0
  121. package/src/richtext/html-text-parser.ts +87 -0
  122. package/src/richtext/index.ts +8 -0
  123. package/src/spine/SpineComponent.ts +18 -0
  124. package/src/spine/SpineSystem.ts +30 -0
  125. package/src/spine/index.ts +11 -0
  126. package/src/spine/lib/BatchableSpineSlot.ts +138 -0
  127. package/src/spine/lib/Spine.ts +910 -0
  128. package/src/spine/lib/SpineDebugRenderer.ts +615 -0
  129. package/src/spine/lib/SpinePipe.ts +203 -0
  130. package/src/spine/lib/SpineTexture.ts +143 -0
  131. package/src/spine/lib/assets/atlasLoader.ts +158 -0
  132. package/src/spine/lib/assets/skeletonLoader.ts +81 -0
  133. package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +92 -0
  134. package/src/spine/lib/darktint/DarkTintBatcher.ts +186 -0
  135. package/src/spine/lib/darktint/DarkTintShader.ts +74 -0
  136. package/src/spine/lib/darktint/darkTintBit.ts +77 -0
  137. package/src/spine/lib/index.ts +43 -0
  138. package/src/spine/lib/require-shim.ts +43 -0
  139. package/tsconfig.json +18 -0
@@ -0,0 +1,87 @@
1
+ interface FontTag {
2
+ color?: string;
3
+ size?: number;
4
+ text: string;
5
+ }
6
+
7
+ type ParsedResult = FontTag[];
8
+
9
+ type StyledElement = {
10
+ tag?: string;
11
+ style?: { color?: string; size?: number };
12
+ text: string;
13
+ };
14
+
15
+ export function parseFontString(input: string): ParsedResult {
16
+ const regex = /<font\s+color=['"](#?[0-9a-fA-F]{6})['"](?:\s+size=(\d+))?>(.*?)<\/font>/gi;
17
+ const results: ParsedResult = [];
18
+ let lastIndex = 0;
19
+
20
+ let match: RegExpExecArray | null;
21
+ while ((match = regex.exec(input)) !== null) {
22
+ // Add plain text before the match if it exists
23
+ if (match.index > lastIndex) {
24
+ const plainText = input.slice(lastIndex, match.index)
25
+ if (plainText) {
26
+ results.push({ text: plainText });
27
+ }
28
+ }
29
+
30
+ const color = match[1];
31
+ const size = match[2] ? parseInt(match[2], 10) : undefined;
32
+ const text = match[3];
33
+
34
+ results.push({ color, size, text });
35
+
36
+ lastIndex = regex.lastIndex;
37
+ }
38
+
39
+ // Add remaining plain text after the last match
40
+ if (lastIndex < input.length) {
41
+ const plainText = input.slice(lastIndex);
42
+ if (plainText) {
43
+ results.push({ text: plainText });
44
+ }
45
+ }
46
+
47
+ return results;
48
+ }
49
+
50
+ export function transformToStyledElements(parsed: ParsedResult): StyledElement[] {
51
+ return parsed.map((item, index) => {
52
+ if (item.color || item.size) {
53
+ return {
54
+ tag: `b${index + 1}`,
55
+ style: { color: item.color, size: item.size },
56
+ text: item.text,
57
+ };
58
+ }
59
+ return {
60
+ text: item.text,
61
+ };
62
+ });
63
+ }
64
+
65
+ export function generateStringFromStyledElements(elements: StyledElement[]): string {
66
+ return elements
67
+ .map((element) => {
68
+ if (!element.tag) {
69
+ return element.text;
70
+ }
71
+ return `<${element.tag}>${element.text}</${element.tag}>`;
72
+ })
73
+ .join('');
74
+ }
75
+
76
+ export function generateStylesFromStyledElements(elements: StyledElement[]) {
77
+ const styles = {};
78
+ elements
79
+ .forEach((element) => {
80
+ const { tag, style } = element
81
+ if (!tag) {
82
+ return;
83
+ }
84
+ styles[element.tag] = style
85
+ })
86
+ return styles
87
+ }
@@ -0,0 +1,8 @@
1
+ import { GameWorld } from '..'
2
+ import { RichTextSystem } from './RichTextSystem'
3
+ export * from './RichTextComp'
4
+
5
+ export function setupRichText() {
6
+ GameWorld.Instance.systems.add(RichTextSystem)
7
+ GameWorld.Instance.systems.configureOnce(RichTextSystem)
8
+ }
@@ -0,0 +1,18 @@
1
+ import { ComponentX } from "../components/BaseComponent"
2
+
3
+ interface SpineData {
4
+ atlas: string
5
+ skeleton: string
6
+ texture?: string
7
+ }
8
+
9
+ interface SpineSkeletonProps {
10
+ data: SpineData
11
+ skin?: string
12
+ animation?: string
13
+ timeScale?: number
14
+ loop?: boolean
15
+ }
16
+ export class SpineSkeleton extends ComponentX<SpineSkeletonProps> {
17
+
18
+ }
@@ -0,0 +1,30 @@
1
+ import { EventManager, EventTypes, System } from 'entityx-ts'
2
+ import { Spine } from './lib'
3
+
4
+ import { NodeComp } from '../components/NodeComp'
5
+ import { SpineSkeleton } from './SpineComponent'
6
+
7
+ export class SpineSystem implements System {
8
+ configure(event_manager: EventManager) {
9
+ event_manager.subscribe(EventTypes.ComponentAdded, SpineSkeleton, ({ entity, component }) => {
10
+ // console.log('SpineSkeleton', component)
11
+ // const spine = entity.getComponent(SpineSkeleton)
12
+ const { data, skin, animation, loop, timeScale } = component.props
13
+ const node = Spine.from(data)
14
+ // node.skeleton.scaleY = -1
15
+ if (skin) {
16
+ node.skeleton.setSkinByName(skin)
17
+ }
18
+ if (animation) {
19
+ node.state.setAnimation(0, animation, loop)
20
+ }
21
+ if (timeScale) {
22
+ node.state.timeScale = timeScale
23
+ }
24
+ component.node = entity.assign(new NodeComp(node, entity))
25
+ })
26
+ }
27
+ // update() {
28
+ // throw new Error('Method not implemented.');
29
+ // }
30
+ }
@@ -0,0 +1,11 @@
1
+ import { GameWorld } from '..'
2
+ import { SpineSystem } from './SpineSystem'
3
+
4
+ export * from './SpineComponent'
5
+ export * from './SpineSystem'
6
+
7
+ export function setupSpine() {
8
+ GameWorld.Instance.systems.add(SpineSystem)
9
+ // GameWorld.Instance.listUpdate.push(SpineSystem)
10
+ GameWorld.Instance.systems.configureOnce(SpineSystem)
11
+ }
@@ -0,0 +1,138 @@
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
+
30
+ import { AttachmentCacheData, Spine } from './Spine.js';
31
+
32
+ import type { Batch, Batcher, BLEND_MODES, DefaultBatchableMeshElement, Matrix, Texture, Topology } from 'pixi.js';
33
+
34
+ export class BatchableSpineSlot implements DefaultBatchableMeshElement {
35
+ indexOffset = 0;
36
+ attributeOffset = 0;
37
+
38
+ indexSize!: number;
39
+ attributeSize!: number;
40
+
41
+ batcherName = 'darkTint';
42
+
43
+ topology: Topology = 'triangle-list';
44
+
45
+ readonly packAsQuad = false;
46
+
47
+ renderable!: Spine;
48
+
49
+ positions!: Float32Array;
50
+ indices!: number[] | Uint16Array;
51
+ uvs!: Float32Array;
52
+
53
+ roundPixels!: 0 | 1;
54
+ data!: AttachmentCacheData;
55
+ blendMode!: BLEND_MODES;
56
+
57
+ darkTint!: number;
58
+
59
+ texture!: Texture;
60
+
61
+ transform!: Matrix;
62
+
63
+ // used internally by batcher specific. Stored for efficient updating.
64
+ _textureId!: number;
65
+ _attributeStart!: number;
66
+ _indexStart!: number;
67
+ _batcher!: Batcher;
68
+ _batch!: Batch;
69
+
70
+
71
+ get color () {
72
+ const slotColor = this.data.color;
73
+
74
+ const parentColor: number = this.renderable.groupColor;
75
+ const parentAlpha: number = this.renderable.groupAlpha;
76
+ let abgr: number;
77
+
78
+ const mixedA = (slotColor.a * parentAlpha) * 255;
79
+
80
+ if (parentColor !== 0xFFFFFF) {
81
+ const parentB = (parentColor >> 16) & 0xFF;
82
+ const parentG = (parentColor >> 8) & 0xFF;
83
+ const parentR = parentColor & 0xFF;
84
+
85
+ const mixedR = (slotColor.r * parentR);
86
+ const mixedG = (slotColor.g * parentG);
87
+ const mixedB = (slotColor.b * parentB);
88
+
89
+ abgr = ((mixedA) << 24) | (mixedB << 16) | (mixedG << 8) | mixedR;
90
+ }
91
+ else {
92
+ abgr = ((mixedA) << 24) | ((slotColor.b * 255) << 16) | ((slotColor.g * 255) << 8) | (slotColor.r * 255);
93
+ }
94
+
95
+ return abgr;
96
+ }
97
+
98
+ get darkColor () {
99
+ const darkColor = this.data.darkColor;
100
+ return ((darkColor.b * 255) << 16) | ((darkColor.g * 255) << 8) | (darkColor.r * 255);
101
+ }
102
+
103
+ get groupTransform () { return this.renderable.groupTransform; }
104
+
105
+ setData (
106
+ renderable: Spine,
107
+ data: AttachmentCacheData,
108
+ blendMode: BLEND_MODES,
109
+ roundPixels: 0 | 1) {
110
+ this.renderable = renderable;
111
+ this.transform = renderable.groupTransform;
112
+ this.data = data;
113
+
114
+ if (data.clipped) {
115
+ const clippedData = data.clippedData;
116
+
117
+ this.indexSize = clippedData!.indicesCount;
118
+ this.attributeSize = clippedData!.vertexCount;
119
+ this.positions = clippedData!.vertices;
120
+ this.indices = clippedData!.indices;
121
+ this.uvs = clippedData!.uvs;
122
+ }
123
+ else {
124
+ this.indexSize = data.indices.length;
125
+ this.attributeSize = data.vertices.length / 2;
126
+ this.positions = data.vertices;
127
+ this.indices = data.indices;
128
+ this.uvs = data.uvs;
129
+ }
130
+
131
+ this.texture = data.texture;
132
+ this.roundPixels = roundPixels;
133
+
134
+ this.blendMode = blendMode;
135
+
136
+ this.batcherName = data.darkTint ? 'darkTint' : 'default';
137
+ }
138
+ }