canvasengine 2.0.1-beta.1 → 2.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.
Files changed (212) hide show
  1. package/dist/DebugRenderer-DkjTAc48.js +1384 -0
  2. package/dist/DebugRenderer-DkjTAc48.js.map +1 -0
  3. package/dist/components/Button.d.ts +185 -0
  4. package/dist/components/Button.d.ts.map +1 -0
  5. package/dist/components/Canvas.d.ts +17 -0
  6. package/dist/components/Canvas.d.ts.map +1 -0
  7. package/dist/components/Container.d.ts +25 -0
  8. package/dist/components/Container.d.ts.map +1 -0
  9. package/dist/components/DOMContainer.d.ts +28 -0
  10. package/dist/components/DOMContainer.d.ts.map +1 -0
  11. package/dist/components/DOMElement.d.ts +54 -0
  12. package/dist/components/DOMElement.d.ts.map +1 -0
  13. package/dist/components/DOMSprite.d.ts +127 -0
  14. package/dist/components/DOMSprite.d.ts.map +1 -0
  15. package/dist/components/DisplayObject.d.ts +18 -0
  16. package/dist/components/DisplayObject.d.ts.map +1 -0
  17. package/dist/components/FocusContainer.d.ts +129 -0
  18. package/dist/components/FocusContainer.d.ts.map +1 -0
  19. package/dist/components/Graphic.d.ts +64 -0
  20. package/dist/components/Graphic.d.ts.map +1 -0
  21. package/dist/components/Joystick.d.ts +37 -0
  22. package/dist/components/Joystick.d.ts.map +1 -0
  23. package/dist/components/Mesh.d.ts +138 -0
  24. package/dist/components/Mesh.d.ts.map +1 -0
  25. package/dist/components/NineSliceSprite.d.ts +16 -0
  26. package/dist/components/NineSliceSprite.d.ts.map +1 -0
  27. package/dist/components/ParticleEmitter.d.ts +4 -0
  28. package/dist/components/ParticleEmitter.d.ts.map +1 -0
  29. package/dist/components/Scene.d.ts +2 -0
  30. package/dist/components/Scene.d.ts.map +1 -0
  31. package/dist/components/Sprite.d.ts +182 -0
  32. package/dist/components/Sprite.d.ts.map +1 -0
  33. package/dist/components/Text.d.ts +24 -0
  34. package/dist/components/Text.d.ts.map +1 -0
  35. package/dist/components/TilingSprite.d.ts +17 -0
  36. package/dist/components/TilingSprite.d.ts.map +1 -0
  37. package/dist/components/Video.d.ts +14 -0
  38. package/dist/components/Video.d.ts.map +1 -0
  39. package/dist/components/Viewport.d.ts +52 -0
  40. package/dist/components/Viewport.d.ts.map +1 -0
  41. package/dist/components/index.d.ts +20 -0
  42. package/dist/components/index.d.ts.map +1 -0
  43. package/dist/components/types/DisplayObject.d.ts +127 -0
  44. package/dist/components/types/DisplayObject.d.ts.map +1 -0
  45. package/dist/components/types/MouseEvent.d.ts +4 -0
  46. package/dist/components/types/MouseEvent.d.ts.map +1 -0
  47. package/dist/components/types/Spritesheet.d.ts +248 -0
  48. package/dist/components/types/Spritesheet.d.ts.map +1 -0
  49. package/dist/components/types/index.d.ts +4 -0
  50. package/dist/components/types/index.d.ts.map +1 -0
  51. package/dist/directives/Controls.d.ts +112 -0
  52. package/dist/directives/Controls.d.ts.map +1 -0
  53. package/dist/directives/ControlsBase.d.ts +199 -0
  54. package/dist/directives/ControlsBase.d.ts.map +1 -0
  55. package/dist/directives/Drag.d.ts +69 -0
  56. package/dist/directives/Drag.d.ts.map +1 -0
  57. package/dist/directives/Flash.d.ts +116 -0
  58. package/dist/directives/Flash.d.ts.map +1 -0
  59. package/dist/directives/FocusNavigation.d.ts +52 -0
  60. package/dist/directives/FocusNavigation.d.ts.map +1 -0
  61. package/dist/directives/FogVisibility.d.ts +47 -0
  62. package/dist/directives/FogVisibility.d.ts.map +1 -0
  63. package/dist/directives/GamepadControls.d.ts +224 -0
  64. package/dist/directives/GamepadControls.d.ts.map +1 -0
  65. package/dist/directives/JoystickControls.d.ts +171 -0
  66. package/dist/directives/JoystickControls.d.ts.map +1 -0
  67. package/dist/directives/KeyboardControls.d.ts +219 -0
  68. package/dist/directives/KeyboardControls.d.ts.map +1 -0
  69. package/dist/directives/Scheduler.d.ts +36 -0
  70. package/dist/directives/Scheduler.d.ts.map +1 -0
  71. package/dist/directives/Shake.d.ts +98 -0
  72. package/dist/directives/Shake.d.ts.map +1 -0
  73. package/dist/directives/Sound.d.ts +25 -0
  74. package/dist/directives/Sound.d.ts.map +1 -0
  75. package/dist/directives/SpriteEffects.d.ts +70 -0
  76. package/dist/directives/SpriteEffects.d.ts.map +1 -0
  77. package/dist/directives/Transition.d.ts +10 -0
  78. package/dist/directives/Transition.d.ts.map +1 -0
  79. package/dist/directives/ViewportCull.d.ts +11 -0
  80. package/dist/directives/ViewportCull.d.ts.map +1 -0
  81. package/dist/directives/ViewportFollow.d.ts +18 -0
  82. package/dist/directives/ViewportFollow.d.ts.map +1 -0
  83. package/dist/directives/index.d.ts +15 -0
  84. package/dist/directives/index.d.ts.map +1 -0
  85. package/dist/dist-BOOc43Qm.js +778 -0
  86. package/dist/dist-BOOc43Qm.js.map +1 -0
  87. package/dist/engine/FocusManager.d.ts +174 -0
  88. package/dist/engine/FocusManager.d.ts.map +1 -0
  89. package/dist/engine/animation.d.ts +72 -0
  90. package/dist/engine/animation.d.ts.map +1 -0
  91. package/dist/engine/bootstrap.d.ts +52 -0
  92. package/dist/engine/bootstrap.d.ts.map +1 -0
  93. package/dist/engine/directive.d.ts +13 -0
  94. package/dist/engine/directive.d.ts.map +1 -0
  95. package/dist/engine/reactive.d.ts +139 -0
  96. package/dist/engine/reactive.d.ts.map +1 -0
  97. package/dist/engine/signal.d.ts +74 -0
  98. package/dist/engine/signal.d.ts.map +1 -0
  99. package/dist/engine/trigger.d.ts +54 -0
  100. package/dist/engine/trigger.d.ts.map +1 -0
  101. package/dist/engine/utils.d.ts +89 -0
  102. package/dist/engine/utils.d.ts.map +1 -0
  103. package/dist/hooks/addContext.d.ts +2 -0
  104. package/dist/hooks/addContext.d.ts.map +1 -0
  105. package/dist/hooks/useFocus.d.ts +60 -0
  106. package/dist/hooks/useFocus.d.ts.map +1 -0
  107. package/dist/hooks/useProps.d.ts +53 -0
  108. package/dist/hooks/useProps.d.ts.map +1 -0
  109. package/dist/hooks/useRef.d.ts +4 -0
  110. package/dist/hooks/useRef.d.ts.map +1 -0
  111. package/dist/index.d.ts +19 -844
  112. package/dist/index.d.ts.map +1 -0
  113. package/dist/index.global.js +189 -0
  114. package/dist/index.global.js.map +1 -0
  115. package/dist/index.js +15156 -3287
  116. package/dist/index.js.map +1 -1
  117. package/dist/utils/Ease.d.ts +17 -0
  118. package/dist/utils/Ease.d.ts.map +1 -0
  119. package/dist/utils/GlobalAssetLoader.d.ts +141 -0
  120. package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
  121. package/dist/utils/RadialGradient.d.ts +57 -0
  122. package/dist/utils/RadialGradient.d.ts.map +1 -0
  123. package/dist/utils/functions.d.ts +2 -0
  124. package/dist/utils/functions.d.ts.map +1 -0
  125. package/dist/utils/tabindex.d.ts +16 -0
  126. package/dist/utils/tabindex.d.ts.map +1 -0
  127. package/index.d.ts +1 -3
  128. package/package.json +19 -52
  129. package/src/components/Button.ts +406 -0
  130. package/src/components/Canvas.ts +82 -51
  131. package/src/components/Container.ts +31 -4
  132. package/src/components/DOMContainer.ts +387 -0
  133. package/src/components/DOMElement.ts +556 -0
  134. package/src/components/DOMSprite.ts +1044 -0
  135. package/src/components/DisplayObject.ts +423 -202
  136. package/src/components/FocusContainer.ts +368 -0
  137. package/src/components/Graphic.ts +255 -68
  138. package/src/components/Joystick.ts +269 -0
  139. package/src/components/Mesh.ts +239 -0
  140. package/src/components/NineSliceSprite.ts +4 -1
  141. package/src/components/ParticleEmitter.ts +12 -8
  142. package/src/components/Sprite.ts +441 -54
  143. package/src/components/Text.ts +270 -26
  144. package/src/components/Video.ts +110 -0
  145. package/src/components/Viewport.ts +122 -63
  146. package/src/components/index.ts +12 -5
  147. package/src/components/types/DisplayObject.ts +64 -5
  148. package/src/components/types/Spritesheet.ts +0 -118
  149. package/src/directives/Controls.ts +254 -0
  150. package/src/directives/ControlsBase.ts +267 -0
  151. package/src/directives/Drag.ts +357 -52
  152. package/src/directives/Flash.ts +419 -0
  153. package/src/directives/FocusNavigation.ts +113 -0
  154. package/src/directives/FogVisibility.ts +273 -0
  155. package/src/directives/GamepadControls.ts +537 -0
  156. package/src/directives/JoystickControls.ts +396 -0
  157. package/src/directives/KeyboardControls.ts +86 -431
  158. package/src/directives/Scheduler.ts +21 -16
  159. package/src/directives/Shake.ts +298 -0
  160. package/src/directives/Sound.ts +94 -31
  161. package/src/directives/SpriteEffects.ts +461 -0
  162. package/src/directives/ViewportFollow.ts +40 -9
  163. package/src/directives/index.ts +14 -6
  164. package/src/engine/FocusManager.ts +510 -0
  165. package/src/engine/animation.ts +175 -21
  166. package/src/engine/bootstrap.ts +140 -6
  167. package/src/engine/directive.ts +4 -4
  168. package/src/engine/reactive.ts +1266 -167
  169. package/src/engine/signal.ts +335 -47
  170. package/src/engine/trigger.ts +95 -12
  171. package/src/engine/utils.ts +101 -9
  172. package/src/hooks/useFocus.ts +91 -0
  173. package/src/hooks/useProps.ts +92 -7
  174. package/src/index.ts +13 -6
  175. package/src/types/pixi-cull.d.ts +7 -0
  176. package/src/utils/GlobalAssetLoader.ts +257 -0
  177. package/src/utils/RadialGradient.ts +29 -0
  178. package/src/utils/functions.ts +7 -0
  179. package/src/utils/tabindex.ts +70 -0
  180. package/testing/index.ts +42 -0
  181. package/tsconfig.json +15 -25
  182. package/vite.config.ts +39 -0
  183. package/.cursorrules +0 -0
  184. package/.github/workflows/ci.yml +0 -29
  185. package/README.md +0 -79
  186. package/dist/compiler/vite.js +0 -119
  187. package/dist/compiler/vite.js.map +0 -1
  188. package/logo.png +0 -0
  189. package/src/compiler/grammar.pegjs +0 -180
  190. package/src/compiler/vite.ts +0 -166
  191. package/src/components/DrawMap/index.ts +0 -65
  192. package/src/components/Tilemap/Tile.ts +0 -79
  193. package/src/components/Tilemap/TileGroup.ts +0 -207
  194. package/src/components/Tilemap/TileLayer.ts +0 -163
  195. package/src/components/Tilemap/TileSet.ts +0 -41
  196. package/src/components/Tilemap/index.ts +0 -80
  197. package/src/presets/Bar.ts +0 -89
  198. package/src/presets/Button.ts +0 -0
  199. package/src/presets/Joystick.ts +0 -286
  200. package/src/presets/NightAmbiant.ts +0 -122
  201. package/src/presets/Particle.ts +0 -53
  202. package/starter/assets/logo.png +0 -0
  203. package/starter/components/app.ce +0 -18
  204. package/starter/components/hello.ce +0 -35
  205. package/starter/index.html +0 -21
  206. package/starter/main.ts +0 -6
  207. package/starter/package.json +0 -20
  208. package/starter/tsconfig.json +0 -32
  209. package/starter/vite.config.ts +0 -12
  210. package/tsconfig.node.json +0 -10
  211. package/tsup.config.ts +0 -28
  212. package/vitest.config.ts +0 -12
@@ -1,180 +0,0 @@
1
- {
2
- function generateError(message, location) {
3
- const { start, end } = location;
4
- const errorMessage = `${message}\n` +
5
- `at line ${start.line}, column ${start.column} to line ${end.line}, column ${end.column}`;
6
- throw new Error(errorMessage);
7
- }
8
- }
9
-
10
- start
11
- = _ elements:(element)* _ {
12
- if (elements.length === 1) {
13
- return elements[0];
14
- }
15
- return `[${elements.join(',')}]`;
16
- }
17
-
18
- element
19
- = forLoop
20
- / ifCondition
21
- / selfClosingElement
22
- / openCloseElement
23
- / comment
24
-
25
- selfClosingElement
26
- = _ "<" _ tagName:tagName _ attributes:attributes _ "/>" _ {
27
- const attrs = attributes.length > 0 ? `{ ${attributes.join(', ')} }` : null;
28
- return attrs ? `h(${tagName}, ${attrs})` : `h(${tagName})`;
29
- }
30
-
31
- openCloseElement
32
- = "<" _ tagName:tagName _ attributes:attributes _ ">" _ content:content _ "</" _ closingTagName:tagName _ ">" {
33
- if (tagName !== closingTagName) {
34
- error("Mismatched opening and closing tags");
35
- }
36
- const attrs = attributes.length > 0 ? `{ ${attributes.join(', ')} }` : null;
37
- const children = content ? content : null;
38
- if (attrs && children) {
39
- return `h(${tagName}, ${attrs}, ${children})`;
40
- } else if (attrs) {
41
- return `h(${tagName}, ${attrs})`;
42
- } else if (children) {
43
- return `h(${tagName}, null, ${children})`;
44
- } else {
45
- return `h(${tagName})`;
46
- }
47
- }
48
-
49
- / "<" _ tagName:tagName _ attributes:attributes _ {
50
- generateError("Syntaxe d'élément invalide", location());
51
- }
52
-
53
- attributes
54
- = attrs:(attribute (_ attribute)*)? {
55
- return attrs
56
- ? [attrs[0]].concat(attrs[1].map(a => a[1]))
57
- : [];
58
- }
59
-
60
- attribute
61
- = staticAttribute
62
- / dynamicAttribute
63
- / eventHandler
64
-
65
- eventHandler
66
- = "@" eventName:identifier _ "=" _ "{" _ handlerName:attributeValue _ "}" {
67
- return `${eventName}: ${handlerName}`;
68
- }
69
- / "@" eventName:attributeName _ {
70
- return eventName;
71
- }
72
-
73
- dynamicAttribute
74
- = attributeName:attributeName _ "=" _ "{" _ attributeValue:attributeValue _ "}" {
75
- if (attributeValue.trim().match(/^[a-zA-Z_]\w*$/)) {
76
- return `${attributeName}: ${attributeValue}`;
77
- } else {
78
- return `${attributeName}: computed(() => ${attributeValue.replace(/@?[a-zA-Z_][a-zA-Z0-9_]*(?!:)/g, (match) => {
79
- if (match.startsWith('@')) {
80
- return match.substring(1);
81
- }
82
- return `${match}()`;
83
- })})`;
84
- }
85
- }
86
- / attributeName:attributeName _ {
87
- return attributeName;
88
- }
89
-
90
- attributeValue
91
- = $([^{}]* ("{" [^{}]* "}" [^{}]*)*) {
92
- const t = text().trim()
93
- if (t.startsWith("{") && t.endsWith("}")) {
94
- return `(${t})`;
95
- }
96
- return t
97
- }
98
-
99
- staticAttribute
100
- = attributeName:attributeName _ "=" _ "\"" attributeValue:staticValue "\"" {
101
- return `${attributeName}: ${attributeValue}`;
102
- }
103
-
104
- eventAttribute
105
- = "(" _ eventName:eventName _ ")" _ "=" _ "\"" eventAction:eventAction "\"" {
106
- return `${eventName}: () => { ${eventAction} }`;
107
- }
108
-
109
- staticValue
110
- = [^"]+ {
111
- var val = text();
112
- return isNaN(val) ? `'${val}'` : val;
113
- }
114
-
115
- content
116
- = elements:(element)* {
117
- const filteredElements = elements.filter(el => el !== null);
118
- if (filteredElements.length === 0) return null;
119
- if (filteredElements.length === 1) return filteredElements[0];
120
- return `[${filteredElements.join(', ')}]`;
121
- }
122
-
123
- textNode
124
- = text:$([^<]+) {
125
- const trimmed = text.trim();
126
- return trimmed ? `'${trimmed}'` : null;
127
- }
128
-
129
- textElement
130
- = text:[^<>]+ {
131
- const trimmed = text.join('').trim();
132
- return trimmed ? JSON.stringify(trimmed) : null;
133
- }
134
-
135
- forLoop
136
- = _ "@for" _ "(" _ variableName:identifier _ "of" _ iterable:identifier _ ")" _ "{" _ content:content _ "}" _ {
137
- return `loop(${iterable}, (${variableName}) => ${content})`;
138
- }
139
-
140
- ifCondition
141
- = _ "@if" _ "(" _ condition:condition _ ")" _ "{" _ content:content _ "}" _ {
142
- return `cond(${condition}, () => ${content})`;
143
- }
144
-
145
- tagName
146
- = [a-zA-Z][a-zA-Z0-9]* { return text(); }
147
-
148
- attributeName
149
- = [a-zA-Z][a-zA-Z0-9-]* { return text(); }
150
-
151
- eventName
152
- = [a-zA-Z][a-zA-Z0-9-]* { return text(); }
153
-
154
- variableName
155
- = [a-zA-Z_][a-zA-Z0-9_]* { return text(); }
156
-
157
- iterable
158
- = [a-zA-Z_][a-zA-Z0-9_]* { return text(); }
159
-
160
- condition
161
- = $([^)]*) { return text().trim(); }
162
-
163
- eventAction
164
- = [^"]* { return text(); }
165
-
166
- _ 'whitespace'
167
- = [ \t\n\r]*
168
-
169
- identifier
170
- = [a-zA-Z_][a-zA-Z0-9_]* { return text(); }
171
-
172
- comment
173
- = singleComment+ {
174
- return null
175
- }
176
-
177
- singleComment
178
- = "<!--" _ content:((!("-->") .)* "-->") _ {
179
- return null;
180
- }
@@ -1,166 +0,0 @@
1
- import { createFilter } from "vite";
2
- import { parse } from "acorn";
3
- import fs from "fs";
4
- import pkg from "peggy";
5
- import path from "path";
6
- import * as ts from "typescript"; // Import TypeScript package
7
- import { fileURLToPath } from 'url';
8
-
9
- const { generate } = pkg;
10
-
11
- const DEV_SRC = "../../src"
12
-
13
- export default function canvasengine() {
14
- const filter = createFilter("**/*.ce");
15
-
16
- // Convert import.meta.url to a file path
17
- const __filename = fileURLToPath(import.meta.url);
18
- const __dirname = path.dirname(__filename);
19
-
20
- const grammar = fs.readFileSync(
21
- path.join(__dirname, "grammar.pegjs").replace("dist/compiler/grammar.pegjs", "src/compiler/grammar.pegjs"),
22
- "utf8");
23
- const parser = generate(grammar);
24
- const isDev = process.env.NODE_ENV === "development";
25
- const FLAG_COMMENT = "/*--[TPL]--*/";
26
-
27
- const PRIMITIVE_COMPONENTS = [
28
- "Canvas",
29
- "Sprite",
30
- "Text",
31
- "Joystick",
32
- "Viewport",
33
- "Graphics",
34
- "Container",
35
- "ImageMap",
36
- "NineSliceSprite",
37
- "Rect",
38
- "Circle",
39
- "svg"
40
- ];
41
-
42
- return {
43
- name: "vite-plugin-ce",
44
- transform(code: string, id: string) {
45
- if (!filter(id)) return;
46
-
47
- // Extract the script content
48
- const scriptMatch = code.match(/<script>([\s\S]*?)<\/script>/);
49
- let scriptContent = scriptMatch ? scriptMatch[1].trim() : "";
50
-
51
- // Transform SVG tags to Svg components
52
- let template = code.replace(/<script>[\s\S]*?<\/script>/, "")
53
- .replace(/^\s+|\s+$/g, '');
54
-
55
- // Add SVG transformation
56
- template = template.replace(/<svg>([\s\S]*?)<\/svg>/g, (match, content) => {
57
- return `<Svg content="${content.trim()}" />`;
58
- });
59
-
60
- const parsedTemplate = parser.parse(template);
61
-
62
- // trick to avoid typescript remove imports in scriptContent
63
- scriptContent += FLAG_COMMENT + parsedTemplate
64
-
65
- let transpiledCode = ts.transpileModule(scriptContent, {
66
- compilerOptions: {
67
- module: ts.ModuleKind.Preserve,
68
- },
69
- }).outputText;
70
-
71
- // remove code after /*---*/
72
- transpiledCode = transpiledCode.split(FLAG_COMMENT)[0]
73
-
74
- // Use Acorn to parse the script content
75
- const parsed = parse(transpiledCode, {
76
- sourceType: "module",
77
- ecmaVersion: 2020,
78
- });
79
-
80
- // Extract imports
81
- const imports = parsed.body.filter(
82
- (node) => node.type === "ImportDeclaration"
83
- );
84
-
85
- // Extract non-import statements from scriptContent
86
- const nonImportCode = parsed.body
87
- .filter((node) => node.type !== "ImportDeclaration")
88
- .map((node) => transpiledCode.slice(node.start, node.end))
89
- .join("\n");
90
-
91
- let importsCode = imports
92
- .map((imp) => {
93
- let importCode = transpiledCode.slice(imp.start, imp.end);
94
- if (isDev && importCode.includes("from 'canvasengine'")) {
95
- importCode = importCode.replace(
96
- "from 'canvasengine'",
97
- `from '${DEV_SRC}'`
98
- );
99
- }
100
- return importCode;
101
- })
102
- .join("\n");
103
-
104
- // Define an array for required imports
105
- const requiredImports = ["h", "computed", "cond", "loop"];
106
-
107
- // Check for missing imports
108
- const missingImports = requiredImports.filter(
109
- (importName) =>
110
- !imports.some(
111
- (imp) =>
112
- imp.specifiers &&
113
- imp.specifiers.some(
114
- (spec) =>
115
- spec.type === "ImportSpecifier" &&
116
- spec.imported &&
117
- 'name' in spec.imported &&
118
- spec.imported.name === importName
119
- )
120
- )
121
- );
122
-
123
- // Add missing imports
124
- if (missingImports.length > 0) {
125
- const additionalImportCode = `import { ${missingImports.join(
126
- ", "
127
- )} } from ${isDev ? `'${DEV_SRC}'` : "'canvasengine'"};`;
128
- importsCode = `${additionalImportCode}\n${importsCode}`;
129
- }
130
-
131
- // Check for primitive components in parsedTemplate
132
- const primitiveImports = PRIMITIVE_COMPONENTS.filter((component) =>
133
- parsedTemplate.includes(`h(${component}`)
134
- );
135
-
136
- // Add missing imports for primitive components
137
- primitiveImports.forEach((component) => {
138
- const importStatement = `import { ${component} } from ${
139
- isDev ? `'${DEV_SRC}'` : "'canvasengine'"
140
- };`;
141
- if (!importsCode.includes(importStatement)) {
142
- importsCode = `${importStatement}\n${importsCode}`;
143
- }
144
- });
145
-
146
- // Generate the output
147
- const output = String.raw`
148
- ${importsCode}
149
- import { useProps, useDefineProps } from ${isDev ? `'${DEV_SRC}'` : "'canvasengine'"}
150
-
151
- export default function component($$props) {
152
- const $props = useProps($$props)
153
- const defineProps = useDefineProps($$props)
154
- ${nonImportCode}
155
- let $this = ${parsedTemplate}
156
- return $this
157
- }
158
- `;
159
-
160
- return {
161
- code: output,
162
- map: null,
163
- };
164
- },
165
- };
166
- }
@@ -1,65 +0,0 @@
1
- import { effect, signal } from "@signe/reactive";
2
- import { loop } from "../../engine/reactive";
3
- import { h } from "../../engine/signal";
4
- import { useProps } from "../../hooks/useProps";
5
- import { Container } from "../Container";
6
- import { Sprite } from "../Sprite";
7
-
8
- interface TileData {
9
- id: number;
10
- rect: [number, number, number, number];
11
- drawIn: [number, number];
12
- layerIndex: number;
13
- }
14
-
15
- export function ImageMap(props) {
16
- const { imageSource, tileData } = useProps(props);
17
- const tiles = signal<TileData[]>([]);
18
-
19
- effect(async () => {
20
- const data = await fetch(tileData()).then((response) => response.json());
21
- const objects = data;
22
- if (props.objects) {
23
- objects.push(...props.objects(data));
24
- }
25
- tiles.set(objects);
26
- });
27
-
28
- const createLayeredTiles = () => {
29
- const layers = [createTileLayer(0), createTileLayer(1, true), createTileLayer(2)];
30
-
31
- return h(Container, props, ...layers);
32
- };
33
-
34
- const createTileLayer = (layerIndex: number, sortableChildren = false) => {
35
- return h(
36
- Container,
37
- {
38
- sortableChildren,
39
- },
40
- loop(tiles, (object) => {
41
-
42
- if (object.tag && layerIndex == 1) {
43
- return object
44
- }
45
-
46
- object.layerIndex ||= 1;
47
- if (object.layerIndex !== layerIndex) return null;
48
-
49
- const [x, y, width, height] = object.rect;
50
- const [drawX, drawY] = object.drawIn;
51
-
52
- return h(Sprite, {
53
- image: imageSource(),
54
- x: drawX,
55
- y: drawY,
56
- rectangle: { x, y, width, height },
57
- zIndex: drawY + height - 70,
58
- // zIndex: 0
59
- });
60
- })
61
- );
62
- };
63
-
64
- return createLayeredTiles();
65
- }
@@ -1,79 +0,0 @@
1
- import { CompositeTilemap } from "@pixi/tilemap";
2
- import { Tile as TiledTileClass } from '@rpgjs/tiled';
3
- import { AnimatedSprite, Texture, groupD8 } from "pixi.js";
4
- import { TileSet } from "./TileSet";
5
-
6
- export class Tile extends AnimatedSprite {
7
- static getTextures(tile: TiledTileClass, tileSet: TileSet) {
8
- const textures: Texture[] = [];
9
-
10
- if (tile.animations && tile.animations.length) {
11
- tile.animations.forEach(frame => {
12
- textures.push(tileSet.textures[frame.tileid])
13
- });
14
- } else {
15
- textures.push(tileSet.textures[tile.gid - tileSet.firstgid])
16
- }
17
-
18
- return textures;
19
- }
20
-
21
- animations: { tileid: number, duration: number }[] = []
22
- _x: number = 0
23
- _y: number = 0
24
- pointsBufIndex: number
25
- properties: any = {}
26
-
27
- constructor(
28
- private tile: TiledTileClass,
29
- private tileSet: TileSet
30
- ) {
31
- super(Tile.getTextures(tile, tileSet));
32
- this.animations = tile.animations || []
33
- this.properties = tile.properties
34
- this.textures = Tile.getTextures(tile, tileSet)
35
- this.texture = this.textures[0] as Texture
36
- this.flip()
37
- }
38
-
39
- get gid() {
40
- return this.tile.gid
41
- }
42
-
43
- setAnimation(frame: CompositeTilemap) {
44
- const size = this.animations.length
45
- if (size > 1) {
46
- const offset = (this.animations[1].tileid - this.animations[0].tileid) * this.width
47
- frame.tileAnimX(offset, size)
48
- }
49
- }
50
-
51
- flip() {
52
- let symmetry
53
- let i = 0
54
- const add = (symmetrySecond) => {
55
- i++
56
- if (symmetry) symmetry = groupD8.add(symmetry, symmetrySecond)
57
- else symmetry = symmetrySecond
58
- }
59
-
60
- if (this.tile.horizontalFlip) {
61
- add(groupD8.MIRROR_HORIZONTAL)
62
- }
63
-
64
- if (this.tile.verticalFlip) {
65
- add(groupD8.MIRROR_VERTICAL)
66
- }
67
-
68
- if (this.tile.diagonalFlip) {
69
- if (i % 2 == 0) {
70
- add(groupD8.MAIN_DIAGONAL)
71
- }
72
- else {
73
- add(groupD8.REVERSE_DIAGONAL)
74
- }
75
- }
76
-
77
- //if (symmetry) this.texture.rotate = symmetry
78
- }
79
- }
@@ -1,207 +0,0 @@
1
- interface TileOptions {
2
- tilesetIndex?: number
3
- tileId: number
4
- x: number
5
- y: number
6
- }
7
-
8
- interface TilesGroupOptions {
9
- ignore?: boolean
10
- probability?: number
11
- baseHeight?: number
12
- baseWidth?: number
13
- rectMargin?: number
14
- baseOffsetX?: number
15
- baseOffsetY?: number
16
- }
17
-
18
- export class TileInfo {
19
- tilesetIndex?: number
20
- tileId: number
21
- flags: Map<string, any> = new Map()
22
- id: number = Math.random()
23
-
24
- constructor(obj: TileOptions) {
25
- this.tilesetIndex = obj.tilesetIndex ?? 0
26
- this.tileId = obj.tileId
27
- }
28
-
29
- addFlag(key: string, value: any) {
30
- this.flags.set(key, value)
31
- }
32
- }
33
-
34
- export class TilesGroup {
35
- tiles: (TileInfo | null)[][] = []
36
- width: number
37
- height: number
38
- ignore: boolean = false
39
- probability: number = 1
40
- baseHeight: number = 1
41
- baseWidth?: number
42
- baseOffsetX: number = 0
43
- baseOffsetY: number = 0
44
- rectMargin: number = 0
45
-
46
- constructor(tiles: TileOptions[], public tilesetIndex: number = 0, options: TilesGroupOptions = {}) {
47
- const pointsX = tiles.map(tile => tile.x)
48
- const pointsY = tiles.map(tile => tile.y)
49
- const offsetX = Math.min(...pointsX)
50
- const offsetY = Math.min(...pointsY)
51
- this.width = Math.max(...pointsX) - offsetX + 1
52
- this.height = Math.max(...pointsY) - offsetY + 1
53
- this.ignore = !!options.ignore
54
- this.probability = options.probability ?? 1
55
- this.baseHeight = options.baseHeight ?? 1
56
- this.baseWidth = options.baseWidth
57
- this.rectMargin = options.rectMargin ?? 0
58
- this.baseOffsetX = options.baseOffsetX ?? 0
59
- this.baseOffsetY = options.baseOffsetY ?? 0
60
- this.fillTiles()
61
- for (let tile of tiles) {
62
- this.addTile(tile.x - offsetX, tile.y - offsetY, tile)
63
- }
64
- }
65
-
66
- getRect(x: number, y: number): { minX: number, minY: number, maxX: number, maxY: number } {
67
- const margin = this.rectMargin
68
- return {
69
- minX: x - margin + this.baseOffsetX,
70
- minY: y - this.tilesBaseHeight - margin - this.baseOffsetY,
71
- maxX: x + this.tilesBaseWidth + margin,
72
- maxY: y + margin
73
- }
74
- }
75
-
76
- get tilesBase() {
77
- return this.tiles[this.tiles.length - 1]
78
- }
79
-
80
- get tilesBaseWidth(): number {
81
- return this.baseWidth ?? this.tilesBase.length
82
- }
83
-
84
- get tilesBaseHeight(): number {
85
- return this.baseHeight
86
- }
87
-
88
- forEach(cb: (tileInfo: TileInfo | null, x: number, y: number) => void) {
89
- for (let i = 0; i < this.tiles.length; i++) {
90
- for (let j = 0; j < this.tiles[i].length; j++) {
91
- cb(this.tiles[i][j], j, i)
92
- }
93
- }
94
- }
95
-
96
- find(cb: (tileInfo: TileInfo | null, x: number, y: number) => boolean): TileInfo | null {
97
- let found: TileInfo | null = null
98
- this.forEach((tileInfo, x, y) => {
99
- const bool = cb(tileInfo, x, y)
100
- if (bool) found = tileInfo
101
- })
102
- return found
103
- }
104
-
105
- getOffsetY(): number {
106
- const tilesBase = this.tilesBase
107
- let offset = 0
108
- this.forEach((tile, x, y) => {
109
- if (tile?.tileId == (tilesBase?.[0]?.tileId)) {
110
- offset = y
111
- }
112
- })
113
- return offset
114
- }
115
-
116
- fillTiles() {
117
- for (let i = 0; i < this.height; i++) {
118
- this.tiles[i] = []
119
- for (let j = 0; j < this.width; j++) {
120
- this.tiles[i][j] = null
121
- }
122
- }
123
- }
124
-
125
- shiftToTopLeft(): void {
126
- const matrix = this.tiles
127
-
128
- // Find the first non-undefined element and its position
129
- const foundFirst = () => {
130
- let firstElementRow = -1;
131
- let firstElementColumn = -1;
132
-
133
- for (let col = 0; col < matrix.length; col++) {
134
- if (!matrix[col]) matrix[col] = []
135
- for (let row = 0; row < matrix[col].length; row++) {
136
- if (matrix[col][row] !== undefined) {
137
- firstElementRow = row;
138
- firstElementColumn = col;
139
- return {
140
- firstElementRow,
141
- firstElementColumn
142
- };
143
- }
144
- }
145
- }
146
-
147
- return {
148
- firstElementRow,
149
- firstElementColumn
150
- }
151
- }
152
-
153
- const { firstElementRow, firstElementColumn } = foundFirst()
154
-
155
- // If no non-undefined element is found, return the original matrix
156
- if (firstElementRow === -1) {
157
- return;
158
- }
159
-
160
- // Shift the matrix elements
161
- const newMatrix: (TileInfo | null)[][] = [];
162
- for (let col = firstElementColumn; col < matrix.length; col++) {
163
- const newRow: (TileInfo | null)[] = [];
164
- for (let row = firstElementRow; row < matrix[col].length; row++) {
165
- newRow.push(matrix[col][row]);
166
- }
167
- newMatrix.push(newRow);
168
- }
169
-
170
- this.tiles = newMatrix;
171
-
172
- this.width = this.tiles[0].length
173
- this.height = this.tiles.length
174
- }
175
-
176
- addTile(x: number, y: number, tileOptions: TileOptions) {
177
- if (!this.tiles[y]) this.tiles[y] = []
178
- this.tiles[y][x] = new TileInfo(tileOptions)
179
- }
180
-
181
- addTileFlag(x: number, y: number, key: string, value: any) {
182
- this.getTile(x, y)?.addFlag(key, value)
183
- }
184
-
185
- getTile(x: number, y: number): TileInfo | null {
186
- return this.tiles[y]?.[x]
187
- }
188
-
189
- getTilesByFlag(key: string, value: any): { tileInfo: TileInfo, x: number, y: number }[] {
190
- const array: any = []
191
- this.forEach((tileInfo, x, y) => {
192
- const flag = tileInfo?.flags.get(key)
193
- if (flag && flag == value) {
194
- array.push({
195
- tileInfo,
196
- x,
197
- y
198
- })
199
- }
200
- })
201
- return array
202
- }
203
-
204
- isTileBase(tileInfo: TileInfo): boolean {
205
- return !!this.tilesBase.find(tile => tile?.id == tileInfo.id)
206
- }
207
- }