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
package/extends/Tiled.js DELETED
@@ -1,293 +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("Tiled", {
24
- el: null,
25
- url: "",
26
- tile_w: 0,
27
- tile_h: 0,
28
- tilesets: [],
29
- width: 0,
30
- height: 0,
31
- layers: [],
32
- objects: [],
33
- scene: null,
34
- _ready: null,
35
- initialize: function() {
36
- },
37
- /**
38
- @doc tiled/
39
- @method ready Calls the function when the layers are drawn
40
- @param {Function} callback
41
- */
42
- ready: function(callback) {
43
- this._ready = callback;
44
- },
45
- /**
46
- @doc tiled/
47
- @method load Load JSON file and draw layers in the element of the scene. View Tiled class description for more informations (http://canvasengine.net/doc/?p=editor.tiled)
48
- @param {CanvasEngine.Scene} scene
49
- @param {CanvasEngine.Element} el The element containing layers of Tiled
50
- @param {String} url Path to JSON file of Tiled Map Editor
51
- */
52
- load: function(scene, el, url) {
53
- var self = this;
54
- this.el = el;
55
- this.url = url;
56
- this.scene = scene;
57
- CanvasEngine.getJSON(this.url, function(data) {
58
- self.tile_h = data.tileheight;
59
- self.tile_w = data.tilewidth;
60
- self.width = data.width;
61
- self.height = data.height;
62
- self.tilesets = data.tilesets;
63
- self.layers = data.layers;
64
- self.tilesetsIndexed = [];
65
- for (var i=0 ; i < self.tilesets.length ; i++) {
66
- var props = self.tilesets[i].tileproperties,
67
- new_props = {};
68
- if (props) {
69
- for (var key in props) {
70
- new_props[+key+1] = props[key];
71
- }
72
- self.tilesets[i].tileproperties = new_props;
73
- }
74
- self.tilesetsIndexed[self.tilesets[i].firstgid] = self.tilesets[i];
75
- }
76
- var _id, length = self.tilesetsIndexed.length + (Math.round(self.tilesets[self.tilesets.length-1].imagewidth / self.tile_h) * (Math.round(self.tilesets[self.tilesets.length-1].imagewidth / self.tile_w)));
77
- for (var m=1; m < length; m++) {
78
- _id = self.tilesetsIndexed[m] ? m : _id;
79
- self.tilesetsIndexed[m] = self.tilesetsIndexed[_id];
80
- }
81
- self._draw();
82
- });
83
- },
84
- _draw: function() {
85
- this.map = this.scene.createElement();
86
- this.el_layers = [];
87
- var x, y, tileset;
88
- var id, _tile, _id;
89
- for (var i=0 ; i < this.layers.length ; i++) {
90
- id = 0;
91
- this.el_layers[i] = this.scene.createElement();
92
- if (this.layers[i].data) {
93
- for (var k=0 ; k < this.layers[i].height ; k++) {
94
- for (var j=0 ; j < this.layers[i].width ; j++) {
95
- _tile = this.scene.createElement();
96
- _id = this.layers[i].data[id];
97
- if (_id != 0) {
98
- tileset = this.tilesetsIndexed[_id];
99
- _id -= tileset.firstgid;
100
- y = this.tile_h * Math.floor(_id / (Math.round(tileset.imagewidth / this.tile_h)));
101
- x = this.tile_w * (_id % Math.round(tileset.imagewidth / this.tile_w));
102
-
103
- _tile.drawImage(tileset.name, x, y, this.tile_w, this.tile_h, j * this.tile_w, k * this.tile_h, this.tile_w, this.tile_h);
104
- this.el_layers[i].append(_tile);
105
- }
106
- id++;
107
- }
108
- }
109
- }
110
- else {
111
- this.objects.push(this.el_layers[i]);
112
- }
113
- this.map.append(this.el_layers[i]);
114
- }
115
- this.el.append(this.map);
116
- if (this._ready) this._ready.call(this);
117
- },
118
- /**
119
- @doc tiled/
120
- @method getLayerObject Retrieves the object layer.
121
- @param {Integer} pos (optional) Returns the layer depending on its position in the superposition (0 = very top). 0 by default
122
- @return {CanvasEngine.Element}
123
- */
124
- getLayerObject: function(pos) {
125
- if (!pos) pos = 0;
126
- return this.objects[pos];
127
- },
128
- /**
129
- @doc tiled/
130
- @method getLayer Retrieves the layer by its identifier.
131
- @param {String} id Layer name in Tiled Map Editor
132
- @return {CanvasEngine.Element}
133
- */
134
- getLayer: function(id) {
135
- return this.el_layers[id];
136
- },
137
- /**
138
- @doc tiled/
139
- @method getMap Returns the element containing all the layers
140
- @return {CanvasEngine.Element}
141
- */
142
- getMap: function() {
143
- return this.map;
144
- },
145
- /**
146
- @doc tiled/
147
- @method getTileWidth Returns the width of the map in tiles
148
- @return {Integer}
149
- */
150
- getTileWidth: function() {
151
- return this.tile_w;
152
- },
153
- /**
154
- @doc tiled/
155
- @method getTileWidth Returns the height of the map in tiles
156
- @return {Integer}
157
- */
158
- getTileHeight: function() {
159
- return this.tile_h;
160
- },
161
- /**
162
- @method getTileWidth Returns the width of the map in pixels
163
- @return {Integer}
164
- */
165
- getWidthPixel: function() {
166
- return this.width * this.getTileWidth();
167
- },
168
- /**
169
- @doc tiled/
170
- @method getTileWidth Returns the height of the map in pixels
171
- @return {Integer}
172
- */
173
- getHeightPixel: function() {
174
- return this.height * this.getTileHeight();
175
- },
176
- /**
177
- @doc tiled/
178
- @method getDataLayers Returns the data for each map
179
- @return {Array}
180
- */
181
- getDataLayers: function() {
182
- var layer = [];
183
- for (var i=0 ; i < this.layers.length ; i++) {
184
- if (this.layers[i].data) layer.push(this.layers[i].data);
185
- }
186
- return layer;
187
- },
188
- /**
189
- @doc tiled/
190
- @method getTileInMap Retrieves the position of a tile to the Tileset according positions X and Y
191
- @params {Integer} x Position X
192
- @params {Integer} y Position Y
193
- @return {Array}
194
- */
195
- getTileInMap: function(x, y) {
196
- return this.width * y + x;
197
- },
198
- /**
199
- @doc tiled/
200
- @method getTileProperties Gets the properties of a tile depending on its identifier
201
- @params {Integer} tile Id of tile
202
- @params {String} (optional) layer Layer name
203
- @return {Object}
204
- */
205
- /**
206
- @doc tiled/
207
- @method getTileProperties Gets the properties of a tile depending on its positions
208
- @params {Integer} tile Id of tile. Put "null"
209
- @params {Integer} x Positon X
210
- @params {Integer} y Positon Y
211
- @return {Object}
212
- */
213
- getTileProperties: function(tile, layerOrX, y) {
214
- var self = this;
215
- var tileset = this.tilesets[0];
216
- function _getTileLayers(tile) {
217
- var _layers = [];
218
- for (var i=0 ; i < self.layers.length ; i++) {
219
- if (self.layers[i].data) _layers.push(tileset.tileproperties[self.layers[i].data[tile]]);
220
- }
221
- return _layers;
222
- }
223
-
224
- if (layerOrX === undefined) {
225
- return _getTileLayers(tile);
226
- }
227
- else if (y !== undefined) {
228
- var new_tile = this.getTileInMap(layerOrX, y);
229
- return _getTileLayers(new_tile);
230
- }
231
- return tileset.tileproperties[this.layers[layerOrX].data[tile]];
232
- }
233
- });
234
-
235
- /**
236
- @doc tiled
237
- @class Tiled Tiled is a general purpose tile map editor. It's built to be easy to use, yet flexible enough to work with varying game engines, whether your game is an RPG, platformer or Breakout clone. Tiled is free software and written in C++, using the Qt application framework.
238
-
239
- http://www.mapeditor.org
240
-
241
- <p>Consider adding inserting Tiled.js</p>
242
- <code>
243
- <script src="extends/Tiled.js"></script>
244
- <script>
245
- var canvas = CE.defines("canvas_id").
246
- extend(Tiled).
247
- ready(function() {
248
-
249
- });
250
- </script>
251
- </code>
252
-
253
- @param {CanvasEngine.Scene} scene
254
- @param {CanvasEngine.Element} el The layers are displayed on this element
255
- @param {String} url Path to the JSON file of Tiled Map Editor
256
- @example
257
- <code>
258
- var canvas = CE.defines("canvas_id").
259
- extend(Tiled).
260
- ready(function() {
261
- canvas.Scene.call("MyScene");
262
- });
263
-
264
- canvas.Scene.new({
265
- name: "MyScene",
266
- materials: {
267
- images: {
268
- mytileset: "path/to/tileset.png"
269
- }
270
- },
271
- ready: function(stage) {
272
- var el = this.createElement();
273
- var tiled = canvas.Tiled.new();
274
- tiled.load(this, el, "map/map.json");
275
- tiled.ready(function() {
276
- var tile_w = this.getTileWidth(),
277
- tile_h = this.getTileHeight(),
278
- layer_object = this.getLayerObject();
279
- stage.append(el);
280
- });
281
-
282
- }
283
- });
284
- </code>
285
- */
286
- var Tiled = {
287
- Tiled: {
288
- "new": function(scene, el, url) {
289
- return Class["new"]("Tiled", [scene, el, url]);
290
- }
291
- }
292
- };
293
-
package/index.js DELETED
@@ -1,15 +0,0 @@
1
- var app = require('http').createServer(),
2
- io = require('socket.io').listen(app),
3
- obj = require('./core/engine-common');
4
-
5
- obj.CanvasEngine.io = io;
6
- obj.CanvasEngine.app = app;
7
-
8
- exports.listen = function(port) {
9
- app.listen(port);
10
- return {
11
- Class: obj.Class,
12
- Core: obj.CanvasEngine,
13
- Model: require('./core/ModelServer').Class(obj.Class, obj.CanvasEngine)
14
- };
15
- };
package/license.txt DELETED
@@ -1,19 +0,0 @@
1
- Copyright (C) 2012 by WebCreative5 - Samuel Ronce
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
package/readme.md DELETED
@@ -1,69 +0,0 @@
1
- # Multiplayer
2
-
3
- CanvasEngine implements a multiplayer game using NodeJS and Socket.io
4
-
5
- 1. Install [Node.js](http://nodejs.org) and [NPM](https://npmjs.org/)
6
- 2. Open the Shell :
7
-
8
- npm install canvasengine
9
-
10
- 3. Create a. Js file in your project for the server
11
-
12
- ---
13
-
14
- Here is an example of a client code :
15
-
16
- <!DOCTYPE html>
17
- <html>
18
- <head>
19
- <script src="canvasengine-X.Y.Z.all.min.js"></script>
20
- <script src="extends/Socket.js"></script>
21
-
22
- <script>
23
- var Model = io.connect('http://127.0.0.1:8333');
24
-
25
- var canvas = CE.defines("canvas").
26
- ready(function() {
27
- canvas.Scene.call("MyScene");
28
- });
29
-
30
- canvas.Scene.new({
31
- name: "MyScene",
32
- model: Model,
33
- events: ["load"],
34
- ready: function(stage) {
35
- this.model.emit("start");
36
- },
37
- load: function(text) {
38
- console.log(text);
39
- }
40
- });
41
-
42
- </script>
43
- </head>
44
- <body>
45
- <canvas id="canvas" width="675px" height="506px"></canvas>
46
- </body>
47
- </html>
48
-
49
- And server code :
50
-
51
-
52
- var CE = require("canvasengine").listen(8333);
53
- CE.Model.init("Main", ["start"], {
54
-
55
- initialize: function() {
56
-
57
- },
58
- start: function() {
59
- this.scene.emit("load", "Hello");
60
- }
61
-
62
- });
63
-
64
- 1. The client sends data to the server with the `emit` method `model` property
65
- 2. The method defined in the array is performed (method name sent by the client)
66
- 3. Conversely, data is sent to the scene with the `emit` method `scene` property
67
- 4. Here, the `load` method is executed and defined in the `events` property
68
-
69
- > The methods are the same as Socket.io