canvasengine 1.0.8 → 2.0.0-beta.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 (80) hide show
  1. package/.cursorrules +0 -0
  2. package/README.md +71 -0
  3. package/dist/compiler/vite.js +119 -0
  4. package/dist/compiler/vite.js.map +1 -0
  5. package/dist/index.d.ts +846 -0
  6. package/dist/index.js +3340 -0
  7. package/dist/index.js.map +1 -0
  8. package/logo.png +0 -0
  9. package/package.json +88 -15
  10. package/src/compiler/grammar.pegjs +180 -0
  11. package/src/compiler/vite.ts +166 -0
  12. package/src/components/Canvas.ts +134 -0
  13. package/src/components/Container.ts +46 -0
  14. package/src/components/DisplayObject.ts +458 -0
  15. package/src/components/DrawMap/index.ts +65 -0
  16. package/src/components/Graphic.ts +147 -0
  17. package/src/components/NineSliceSprite.ts +46 -0
  18. package/src/components/ParticleEmitter.ts +39 -0
  19. package/src/components/Scene.ts +6 -0
  20. package/src/components/Sprite.ts +493 -0
  21. package/src/components/Text.ts +145 -0
  22. package/src/components/Tilemap/Tile.ts +79 -0
  23. package/src/components/Tilemap/TileGroup.ts +207 -0
  24. package/src/components/Tilemap/TileLayer.ts +163 -0
  25. package/src/components/Tilemap/TileSet.ts +41 -0
  26. package/src/components/Tilemap/index.ts +80 -0
  27. package/src/components/TilingSprite.ts +39 -0
  28. package/src/components/Viewport.ts +159 -0
  29. package/src/components/index.ts +12 -0
  30. package/src/components/types/DisplayObject.ts +68 -0
  31. package/src/components/types/MouseEvent.ts +3 -0
  32. package/src/components/types/Spritesheet.ts +389 -0
  33. package/src/components/types/index.ts +4 -0
  34. package/src/directives/Drag.ts +84 -0
  35. package/src/directives/KeyboardControls.ts +922 -0
  36. package/src/directives/Scheduler.ts +112 -0
  37. package/src/directives/Sound.ts +91 -0
  38. package/src/directives/Transition.ts +45 -0
  39. package/src/directives/ViewportCull.ts +40 -0
  40. package/src/directives/ViewportFollow.ts +26 -0
  41. package/src/directives/index.ts +7 -0
  42. package/src/engine/animation.ts +113 -0
  43. package/src/engine/bootstrap.ts +19 -0
  44. package/src/engine/directive.ts +23 -0
  45. package/src/engine/reactive.ts +379 -0
  46. package/src/engine/signal.ts +138 -0
  47. package/src/engine/trigger.ts +40 -0
  48. package/src/engine/utils.ts +135 -0
  49. package/src/hooks/addContext.ts +6 -0
  50. package/src/hooks/useProps.ts +155 -0
  51. package/src/hooks/useRef.ts +21 -0
  52. package/src/index.ts +14 -0
  53. package/src/presets/Bar.ts +89 -0
  54. package/src/presets/Button.ts +0 -0
  55. package/src/presets/Joystick.ts +286 -0
  56. package/src/presets/NightAmbiant.ts +122 -0
  57. package/src/presets/Particle.ts +53 -0
  58. package/src/utils/Ease.ts +33 -0
  59. package/src/utils/RadialGradient.ts +86 -0
  60. package/starter/assets/logo.png +0 -0
  61. package/starter/components/app.ce +18 -0
  62. package/starter/components/hello.ce +34 -0
  63. package/starter/index.html +21 -0
  64. package/starter/main.ts +4 -0
  65. package/starter/package.json +16 -0
  66. package/starter/vite.config.ts +12 -0
  67. package/tsconfig.json +32 -0
  68. package/tsconfig.node.json +10 -0
  69. package/tsup.config.ts +28 -0
  70. package/vitest.config.ts +12 -0
  71. package/core/ModelServer.js +0 -251
  72. package/core/engine-common.js +0 -534
  73. package/examples/server/client.html +0 -31
  74. package/examples/server/server.js +0 -11
  75. package/extends/Gleed2d.js +0 -248
  76. package/extends/Marshal.js +0 -662
  77. package/extends/Tiled.js +0 -293
  78. package/index.js +0 -15
  79. package/license.txt +0 -19
  80. package/readme.md +0 -69
@@ -1,248 +0,0 @@
1
- /*
2
- Copyright (C) 2012 by Samuel Ronce
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- Class.create("Gleed2d", {
24
- _onReady: null,
25
- _layers: {},
26
- initialize: function() {
27
-
28
- },
29
- /**
30
- @doc gleed2d/
31
- @method load Load an XML file and builds layers of the elements. Calls the method "ready" of this clas after the construction of the elements.
32
- @param {CanvasEngine.Scene} scene Scene
33
- @param {CanvasEngine.Element} el Layers are displayed on this element
34
- @param {String} url Path to the XML file Gleed2d (without extension)
35
- */
36
- load: function(scene, el, url) {
37
- var self = this;
38
- this.el = el;
39
- this.url = url;
40
- this.scene = scene;
41
- CanvasEngine.ajax({
42
- url: url + ".xml",
43
- dataType: "xml",
44
- success: function(data) {
45
- self._draw(data);
46
- }
47
- });
48
- },
49
- /**
50
- @doc gleed2d/
51
- @method change Allows you to change the parameters of an element in the construction layers
52
- @param {Function} callback Callback function called before the introduction of an element. Returns the same object with different values ??to change the element. Two parameters :
53
- - {CanvasEngine.Element} The element is created and ready to be displayed on the layer
54
- - {Object} the parameters of the element :
55
- {
56
- id: {String} (filename),
57
- regX: {Integer},
58
- regY: {Integer},
59
- x: {Integer},
60
- y: {Integer},
61
- rotate: {Integer},
62
- scaleX: {Float},
63
- scaleY: {Float}
64
- }
65
- @example
66
- In the method "ready" of current scene :
67
- <code>
68
- var gleed = canvas.Gleed2d.new();
69
- gleed.ready(function() {
70
-
71
- });
72
- gleed.change(function(el, params) {
73
- console.log(params.x, params.y); // Change Position X and Position Y
74
- return {
75
- x: params.x + 5 // Change the position x of the element.
76
- };
77
- });
78
- gleed.load(this, element, "data");
79
- </code>
80
-
81
- Dividing the image of the element :
82
- <code>
83
- var gleed = canvas.Gleed2d.new();
84
- gleed.ready(function() {
85
-
86
- });
87
- gleed.change(function(el, params) {
88
- return {
89
- img: [0, 0, 42, 42, 0, 0, 42, 42] // == drawImage(image, 0, 0, 42, 42, 0, 0, 42, 42);
90
- };
91
- });
92
- gleed.load(this, element, "data");
93
- </code>
94
-
95
- Not allow drawing on the element
96
- <code>
97
- var gleed = canvas.Gleed2d.new();
98
- gleed.ready(function() {
99
-
100
- });
101
- gleed.change(function(el, params) {
102
- el.drawImage("other_img");
103
- return {
104
- draw: false
105
- };
106
- });
107
- gleed.load(this, element, "data");
108
- </code>
109
- */
110
- change: function(callback) {
111
- this._set = callback;
112
- },
113
- /**
114
- @doc gleed2d/
115
- @method ready Calls the callback function at the end of the construction elements (loading and layers)
116
- @param {Function} callback Callback function. "this" refers to the class Gleed2d
117
- */
118
- ready: function(callback) {
119
- this._onReady = callback;
120
- },
121
- _draw: function(data) {
122
- var scene = this.scene, match;
123
- var layers = data.getElementsByTagName('Layer');
124
- this.map = scene.createElement();
125
-
126
- function getValue(item, type, attr) {
127
- var node = item.getElementsByTagName(type)[0];
128
- if (attr) {
129
- node = node.getElementsByTagName(attr)[0];
130
- }
131
- return node.childNodes[0].nodeValue;
132
- }
133
-
134
- for (var i=0 ; i < layers.length ; i++) {
135
- var items = layers[i].getElementsByTagName('Item');
136
- var name = layers[i].getAttribute('Name');
137
- var el = scene.createElement();
138
- for (var j=0 ; j < items.length ; j++) {
139
- var item = items[j];
140
- var asset = getValue(item, "asset_name");
141
- if (match = asset.match(/\\([^\\]+$)/)) {
142
- asset = match[1];
143
- }
144
- var origin_x = getValue(item, "Origin", "X"),
145
- origin_y = getValue(item, "Origin", "Y");
146
- var el_item = scene.createElement();
147
- var params = {
148
- id: asset,
149
- draw: true,
150
- img: [],
151
- regX: origin_x,
152
- regY: origin_y,
153
- x: getValue(item, "Position", "X") - origin_x,
154
- y: getValue(item, "Position", "Y") - origin_y,
155
- rotate: getValue(item, "Rotation"),
156
- scaleX: getValue(item, "Scale", "X"),
157
- scaleY: getValue(item, "Scale", "Y")
158
- };
159
- if (this._set) {
160
- var ret = this._set.call(this, el_item, params);
161
- if (ret) {
162
- for (var p in ret) {
163
- params[p] = ret[p];
164
- }
165
- }
166
- }
167
- if (params.draw) {
168
- el_item.drawImage(params.id, params.img[0], params.img[1], params.img[2], params.img[3], params.img[4], params.img[5], params.img[6], params.img[7]);
169
- }
170
- el_item.setOriginPoint(params.regX, params.regY);
171
- el_item.x = params.x;
172
- el_item.y = params.y;
173
- el_item.rotateTo(params.rotate + "rad");
174
- el_item.scaleX = params.scaleX;
175
- el_item.scaleY = params.scaleY;
176
- el.append(el_item);
177
- }
178
- this._layers[name] = el;
179
- this.map.append(el);
180
- }
181
- this.el.append(this.map);
182
- if (this._onReady) this._onReady.call(this);
183
- },
184
- /**
185
- @doc gleed2d/
186
- @method getLayer Retrieve a layer according to its name
187
- @param {String} name Layer name
188
- @return CanvasEngine.Element
189
- */
190
- getLayer: function(name) {
191
- return this._layers[name];
192
- }
193
- });
194
-
195
-
196
- /**
197
- @doc gleed2d
198
- @class Gleed2d GLEED2D (Generic LEvel EDitor 2D) is a general purpose, non tile-based Level Editor for 2D games of any genre that allows arbitrary placement of textures and other items in 2D space. Levels are saved in XML format. Custom Properties can be added to the items in order to represent game-specific data/events/associations between items etc.
199
-
200
- http://gleed2d.codeplex.com
201
-
202
- This class reads the XML file generated by Gleed2d to insert into CanvasEngine
203
- @example
204
- <code>
205
- var canvas = CE.defines("canvas_id").
206
- extend(Gleed2d).
207
- ready(function() {
208
- canvas.Scene.call("MyScene");
209
- });
210
-
211
- canvas.Scene.new({
212
- name: "MyScene",
213
- materials: {
214
- images: {
215
- img1_id: "path/to/img1.png",
216
- img2_id: "path/to/img2.png"
217
- }
218
- },
219
- ready: function(stage) {
220
- var self = this;
221
- this.layer = null;
222
- this.element = this.createElement();
223
-
224
- // -- Gleed2d Level
225
- var gleed = canvas.Gleed2d.new();
226
- gleed.ready(function() {
227
- self.layer = this.getLayer("background");
228
- });
229
- gleed.load(this, element, "data");
230
- // --
231
-
232
- stage.append(this.element);
233
- },
234
- render: function(stage) {
235
- this.layer.x -= 2;
236
- stage.refresh();
237
- }
238
- });
239
-
240
- </code>
241
- */
242
- var Gleed2d = {
243
- Gleed2d: {
244
- "new": function() {
245
- return Class["new"]("Gleed2d");
246
- }
247
- }
248
- };