canvasengine 1.3.0 → 2.0.0-beta.2

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 (96) hide show
  1. package/package.json +51 -17
  2. package/src/components/Canvas.ts +134 -0
  3. package/src/components/Container.ts +46 -0
  4. package/src/components/DisplayObject.ts +458 -0
  5. package/src/components/DrawMap/index.ts +65 -0
  6. package/src/components/Graphic.ts +147 -0
  7. package/src/components/NineSliceSprite.ts +46 -0
  8. package/src/components/ParticleEmitter.ts +39 -0
  9. package/src/components/Scene.ts +6 -0
  10. package/src/components/Sprite.ts +493 -0
  11. package/src/components/Text.ts +145 -0
  12. package/src/components/Tilemap/Tile.ts +79 -0
  13. package/src/components/Tilemap/TileGroup.ts +207 -0
  14. package/src/components/Tilemap/TileLayer.ts +163 -0
  15. package/src/components/Tilemap/TileSet.ts +41 -0
  16. package/src/components/Tilemap/index.ts +80 -0
  17. package/src/components/TilingSprite.ts +39 -0
  18. package/src/components/Viewport.ts +159 -0
  19. package/src/components/index.ts +13 -0
  20. package/src/components/types/DisplayObject.ts +69 -0
  21. package/src/components/types/MouseEvent.ts +3 -0
  22. package/src/components/types/Spritesheet.ts +389 -0
  23. package/src/components/types/index.ts +4 -0
  24. package/src/directives/Drag.ts +84 -0
  25. package/src/directives/KeyboardControls.ts +922 -0
  26. package/src/directives/Scheduler.ts +101 -0
  27. package/src/directives/Sound.ts +91 -0
  28. package/src/directives/Transition.ts +45 -0
  29. package/src/directives/ViewportCull.ts +40 -0
  30. package/src/directives/ViewportFollow.ts +26 -0
  31. package/src/directives/index.ts +7 -0
  32. package/src/engine/animation.ts +113 -0
  33. package/src/engine/bootstrap.ts +19 -0
  34. package/src/engine/directive.ts +23 -0
  35. package/src/engine/reactive.ts +379 -0
  36. package/src/engine/signal.ts +138 -0
  37. package/src/engine/trigger.ts +40 -0
  38. package/src/engine/utils.ts +135 -0
  39. package/src/hooks/addContext.ts +6 -0
  40. package/src/hooks/useProps.ts +155 -0
  41. package/src/hooks/useRef.ts +21 -0
  42. package/src/index.ts +13 -0
  43. package/src/utils/Ease.ts +33 -0
  44. package/src/utils/RadialGradient.ts +86 -0
  45. package/.gitattributes +0 -22
  46. package/.npmignore +0 -163
  47. package/canvasengine-1.3.0.all.min.js +0 -21
  48. package/canvasengine.js +0 -5802
  49. package/core/DB.js +0 -24
  50. package/core/ModelServer.js +0 -348
  51. package/core/Users.js +0 -190
  52. package/core/engine-common.js +0 -952
  53. package/doc/cocoonjs.md +0 -36
  54. package/doc/doc-lang.yml +0 -43
  55. package/doc/doc-router.yml +0 -14
  56. package/doc/doc-tuto.yml +0 -9
  57. package/doc/doc.yml +0 -39
  58. package/doc/element.md +0 -37
  59. package/doc/entity.md +0 -90
  60. package/doc/extend.md +0 -47
  61. package/doc/get_started.md +0 -19
  62. package/doc/images/entity.png +0 -0
  63. package/doc/multitouch.md +0 -58
  64. package/doc/nodejs.md +0 -142
  65. package/doc/scene.md +0 -44
  66. package/doc/text.md +0 -156
  67. package/examples/server/client.html +0 -31
  68. package/examples/server/server.js +0 -16
  69. package/examples/tiled_server/client.html +0 -52
  70. package/examples/tiled_server/images/tiles_spritesheet.png +0 -0
  71. package/examples/tiled_server/server/map.json +0 -50
  72. package/examples/tiled_server/server/map.tmx +0 -16
  73. package/examples/tiled_server/server/server.js +0 -16
  74. package/extends/Animation.js +0 -910
  75. package/extends/Effect.js +0 -252
  76. package/extends/Gleed2d.js +0 -252
  77. package/extends/Hit.js +0 -1509
  78. package/extends/Input.js +0 -699
  79. package/extends/Marshal.js +0 -716
  80. package/extends/Scrolling.js +0 -388
  81. package/extends/Soundmanager2.js +0 -5466
  82. package/extends/Spritesheet.js +0 -196
  83. package/extends/Text.js +0 -366
  84. package/extends/Tiled.js +0 -403
  85. package/extends/Window.js +0 -575
  86. package/extends/gamepad.js +0 -397
  87. package/extends/socket.io.min.js +0 -2
  88. package/extends/swf/soundmanager2.swf +0 -0
  89. package/extends/swf/soundmanager2_debug.swf +0 -0
  90. package/extends/swf/soundmanager2_flash9.swf +0 -0
  91. package/extends/swf/soundmanager2_flash9_debug.swf +0 -0
  92. package/extends/swf/soundmanager2_flash_xdomain.zip +0 -0
  93. package/extends/workers/transition.js +0 -43
  94. package/index.js +0 -46
  95. package/license.txt +0 -19
  96. package/readme.md +0 -483
package/core/DB.js DELETED
@@ -1,24 +0,0 @@
1
- /*var mongoose = require('mongoose'),
2
- uuid = require('node-uuid');
3
-
4
- mongoose.connect('mongodb://localhost/canvasengine', function(err) {
5
- if (err) { throw err; }
6
- });
7
-
8
- var dataShema = new mongoose.Schema({
9
- username : { type: String, required: true, index: { unique: true } },
10
- password : { type: String, required: true },
11
- group: { type: String, required: true, default: "user" },
12
- salt: { type: String, required: true, default: uuid.v1 },
13
- data : { type : String, default : "{}" }
14
- });
15
-
16
- var UserDB = mongoose.model('user', dataShema);
17
-
18
- exports.Class = {
19
- user: UserDB
20
- };*/
21
-
22
- exports.Class = {
23
- user: {}
24
- };
@@ -1,348 +0,0 @@
1
- /**
2
- @doc server/
3
- @method requireExtend `(>= 1.3.0)` Load a class
4
- @static
5
- @return {Class}
6
- @examples
7
-
8
- var CE = require("canvasengine").listen(8333),
9
- Tiled = CE.Core.requireExtend("Tiled").Class,
10
- Class = CE.Class;
11
-
12
- */
13
-
14
- /**
15
- @doc server/
16
- @method io `(>= 1.3.0)` Reference Socket.io. To call an event on a stage, you must prefix the name of the event by the name of the scene
17
- @static
18
- @return {Socket.io}
19
- @examples
20
-
21
- var CE = require("canvasengine").listen(8333),
22
- Class = CE.Class;
23
-
24
- CE.Model.init("Main", {
25
-
26
- initialize: function(socket) {
27
- CE.Core.io.emit("MyScene.load", {foo: bar});
28
- }
29
- });
30
-
31
- */
32
-
33
-
34
-
35
- exports.Class = function(Class, CE, Users) {
36
- var io = CE.io;
37
- /**
38
- @doc server
39
- @class ModelServer Model used for the server. Socket.io resumes with a notion of class
40
-
41
- 1. Import CanvasEngine
42
- 2. Listen a port
43
- 3. Initialize the model with a main class
44
-
45
- var CE = require("canvasengine").listen(8336);
46
-
47
- CE.Model.init("Main", {
48
-
49
- initialize: function(socket) {
50
- // Code
51
- }
52
- });
53
-
54
- */
55
- Class.create("ModelServer", {
56
- _models: {},
57
- _socket: null,
58
- /**
59
- @doc server/
60
- @method init Initializes the connection and call the class
61
- @params {String} name Class name
62
- @params {Array} name (optional) Name of the methods that can be called by the client
63
- @params {Object} model (optional) Properties and methods of this class
64
-
65
- * the "initialize" method is called automatically when the connection with socket parameter
66
- * the "disconnect" method is called when the user logs out
67
-
68
- @example
69
-
70
- var CE = require("canvasengine").listen(8336);
71
-
72
- CE.Model.init("Main", {
73
-
74
- initialize: function(so�cket) {
75
- // Code
76
- }
77
- });
78
-
79
- @return {ModelServer}
80
- */
81
- init: function(name, events, model) {
82
- if (!(events instanceof Array)) {
83
- model = events;
84
- events = false;
85
- }
86
- if (!events) {
87
- events = [];
88
- }
89
- var self = this;
90
- events.push("disconnect");
91
- this.create(name, events, model);
92
-
93
- io.sockets.on('connection', function (socket) {
94
- var _class;
95
- self._socket = socket;
96
- Users.add(socket);
97
- Users._Model = _class = self.new(name, [socket], socket);
98
- _class.socket = socket;
99
- });
100
-
101
- return this;
102
- },
103
- /**
104
- @doc server/
105
- @method create Create a model
106
- @params {String} name Class name
107
- @params {Array} name (optional) Name of the methods that can be called by the client
108
- @params {Object} model (optional) Properties and methods of this class
109
- @example
110
-
111
- Module in "/mods/myclass.js" :
112
-
113
- var CE = require("canvasengine").listen(),
114
- Class = CE.Class;
115
-
116
- CE.Model.create("Player", ["start"], {
117
-
118
- initialize: function(user_id, username) {
119
-
120
- },
121
-
122
- start: function() {
123
-
124
- }
125
-
126
- });
127
-
128
- exports.New = function(socket, user_id, username) {
129
- return CE.Model.new("Player", [user_id, username], socket);
130
- };
131
-
132
- In main JS file :
133
-
134
- var CE = require("canvasengine").listen(8333),
135
- Class = CE.Class;
136
-
137
- CE.Model.init("Main", {
138
-
139
- initialize: function(socket) {
140
- var player = require("./player").New(1, "Foo", socket);
141
- }
142
-
143
- });
144
-
145
- @return {Class}
146
- */
147
- create: function(name, events, model) {
148
- if (!(events instanceof Array)) {
149
- model = events;
150
- events = false;
151
- }
152
- var self = this;
153
- this._models[name] = events;
154
- return Class.create(name, model).extend({
155
- /**
156
- CanvasEngine < 1.3.0
157
-
158
- @property scene Sends data to the scene
159
- @type Object
160
- @example
161
-
162
- Server :
163
-
164
- var CE = require("canvasengine").listen(8336);
165
- CE.Model.init("Main", {
166
- initialize: function() {
167
- this.scene.emit("foo", "Hello");
168
- }
169
- });
170
-
171
-
172
- Client :
173
- var Model = io.connect('http://127.0.0.1:8333');
174
-
175
- var canvas = CE.defines("canvas").
176
- ready(function() {
177
- canvas.Scene.call("MyScene");
178
- });
179
-
180
- canvas.Scene.new({
181
- name: "MyScene",
182
- model: Model,
183
- events: ["foo"],
184
- ready: function(stage) {
185
-
186
- },
187
- foo: function(text) {
188
- console.log(text);
189
- }
190
- });
191
- */
192
- scene: {
193
- /**
194
- @method scene.emit (View Socket.io)
195
- */
196
- emit: function(name, value) {
197
- self._socket.emit(name, value);
198
- },
199
- /**
200
- @method scene.broadcast.emit (View Socket.io)
201
- */
202
- /**
203
- @method scene.broadcast.to (View Socket.io)
204
- */
205
- broadcast: {
206
- emit: function(name, value) {
207
- self._socket.broadcast.emit(name, value);
208
- },
209
- to: function(room, name, value) {
210
- self._socket.broadcast.to(room).emit(name, value);
211
- }
212
- },
213
- /**
214
- @method scene.join (View Socket.io)
215
- */
216
- join: function(room) {
217
- self._socket.join(room);
218
- },
219
- /**
220
-
221
- @method scene.leave (View Socket.io)
222
- */
223
- leave: function(room) {
224
- self._socket.leave(room);
225
- },
226
- /**
227
- @method scene.disconnect (View Socket.io)
228
- */
229
- disconnect: function(data) {
230
- io.sockets.emit(data);
231
- }
232
- }
233
- });
234
-
235
- },
236
- /**
237
- @doc server/
238
- @method new (alias `New`) Instantiating a model
239
- @params {String} name Class name
240
- @params {Array} params Class params
241
- @params {Boolean|Null|Object} socket (optional) Assign events of a class to a user
242
-
243
- - `false` : The class takes the socket from a **single user** connected (by default)
244
- - `null` : does not assign events
245
- - an object : The socket assigned to the class to load events
246
-
247
- @example
248
-
249
- Module in "/mods/myclass.js" :
250
-
251
- var CE = require("canvasengine").listen(),
252
- Class = CE.Class;
253
-
254
- CE.Model.create("Player", ["start"], {
255
-
256
- initialize: function(user_id, username) {
257
-
258
- },
259
-
260
- start: function() {
261
-
262
- }
263
-
264
- });
265
-
266
- exports.New = function(socket, user_id, username) {
267
- return CE.Model.new("Player", [user_id, username], socket);
268
- };
269
-
270
- In main JS file :
271
-
272
- var CE = require("canvasengine").listen(8333),
273
- Class = CE.Class;
274
-
275
- CE.Model.init("Main", {
276
-
277
- initialize: function(socket) {
278
- var player = require("./player").New(1, "Foo", socket);
279
- }
280
-
281
- });
282
-
283
- @return {Class}
284
- */
285
- New: function() { return this["new"].apply(this, arguments); },
286
- new: function(name, params, socket) {
287
-
288
- socket = socket == null ? false : this._socket;
289
-
290
- var _class = Class.new(name, params);
291
- _class._events_ = this._models[name];
292
- if (socket) this.assignEvents(_class, [socket]);
293
- return _class;
294
- },
295
-
296
- /**
297
- @doc server/
298
- @method assignEvents (>= 1.3.0) Assign events of a class to a user
299
- @params {String} name Class name
300
- @params {Object} socket Socket
301
- @example
302
-
303
- var Map = require("./map").New(null); // socket is null. It indicates that not assign an event to sockets
304
-
305
- CE.Model.init("Main", {
306
-
307
- enterMap: function() {
308
- CE.Model.assignEvents(Map, this.socket);
309
- }
310
-
311
- });
312
-
313
- @return {Class}
314
- */
315
- assignEvents: function(_class, clients) {
316
-
317
- var self = this, socket;
318
- var events = _class._events_;
319
- var setEvent = function (method) {
320
- obj = _class[method];
321
- if (obj) {
322
- if (!(clients instanceof Array)) {
323
- clients = [clients];
324
- }
325
- for (var i=0 ; i < clients.length ; i++) {
326
- socket = clients[i];
327
- socket.on(method, function(data) {
328
- if (!data) {
329
- data = {};
330
- }
331
- obj = _class[method];
332
- if (obj) obj.call(_class, data, this);
333
- });
334
- }
335
- }
336
-
337
- }
338
-
339
- if (events) {
340
- for (var key in events) {
341
- setEvent.call(this, events[key]);
342
- }
343
- }
344
- return this;
345
- }
346
- });
347
- return Class.new("ModelServer");
348
- }
package/core/Users.js DELETED
@@ -1,190 +0,0 @@
1
- var crypto = require('crypto');
2
-
3
- exports.Class = function(Class, CE, DB) {
4
-
5
- var UserDB = DB.user;
6
-
7
- var Users, Groups;
8
-
9
- function hash(password, salt) {
10
- return crypto.createHmac('sha256', salt).update(password).digest('hex');
11
- }
12
-
13
- Class.create("Group", {
14
-
15
- name: "",
16
- users: {},
17
-
18
- initialize: function(name) {
19
- this.name = name;
20
- },
21
-
22
- userExist: function(id) {
23
- if (id instanceof Class) {
24
- id = id.id;
25
- }
26
- return this.users[id];
27
- },
28
-
29
- addUser: function(user) {
30
- if (!this.userExist(user)) {
31
- this.users[user.id] = user;
32
- user.socket.join('group_' + this.name);
33
- }
34
- },
35
-
36
- removeUser: function(user) {
37
- delete this.users[user.id];
38
- user.socket.leave('group_' + this.name);
39
- },
40
-
41
- emit: function(event_name, data) {
42
- CE.io.sockets.in('group_' + this.name).emit(event_name, data);
43
- }
44
-
45
- });
46
-
47
- Class.create("User", {
48
-
49
- id: 0,
50
- socket: null,
51
- model: null,
52
- data: {},
53
-
54
- initialize: function(socket) {
55
- var self = this;
56
- this.id = CE.uniqid();
57
- this.socket = socket;
58
- this.socket.on('_authentication', function(params) {
59
- self.authenticate(params.username, params.password);
60
- });
61
- this.socket.on('_register', function(params) {
62
- self.register(params.username, params.password, params.data);
63
- });
64
-
65
- Groups.get("anonymous").addUser(this);
66
- },
67
-
68
- authenticate: function(username, password) {
69
- var self = this;
70
- UserDB.findOne({ username: username }, function(err, user) {
71
- var ret = "";
72
-
73
- if (user) {
74
- if (user.password == hash(password, user.salt)) {
75
- Groups.get("anonymous").removeUser(self);
76
- self.id = user._id;
77
- Groups.get(user.group).addUser(self);
78
- ret = "success";
79
- self.model = user;
80
- if (Users._Model.authentication) Users._Model.authentication.call(Users._Model, self);
81
- }
82
- else {
83
- ret = "failed";
84
- err = {msg: "Wrong password"}
85
- }
86
- }
87
- else {
88
- ret = "failed";
89
- }
90
-
91
- self.socket.emit('_authentication', {ret: ret, err: err});
92
- });
93
-
94
- },
95
-
96
- register: function(username, password, data) {
97
- var self = this;
98
- data = data || {};
99
-
100
- function createUserDB() {
101
- var ret = "",
102
- user = new UserDB({
103
- username: username,
104
- data: data
105
- });
106
- user.password = hash(password, user.salt),
107
- user.save(function (err) {
108
- if (!err) {
109
- ret = "success";
110
- }
111
- else {
112
- ret = "failed";
113
- }
114
- self.socket.emit('_register', {ret: ret, err: err});
115
- });
116
- self.model = user;
117
- }
118
-
119
- UserDB.findOne({ username: username }, function(err, user) {
120
- if (!user) {
121
- createUserDB();
122
- }
123
- else {
124
- self.socket.emit('_register', {ret: "Username exist", err: err});
125
- }
126
- });
127
-
128
- },
129
-
130
- getGroups: function() {
131
- var groups = Groups.get(),
132
- ret = [];
133
- for (var id in groups) {
134
- if (groups[id].userExist(this)) {
135
- ret.push(groups[id]);
136
- }
137
- }
138
- return ret;
139
- }
140
-
141
- });
142
-
143
- Groups = {
144
-
145
- _list: [],
146
-
147
- init: function() {
148
-
149
- var groups = {
150
- "anonymous": {},
151
- "user": {},
152
- "admin": {}
153
- };
154
-
155
- for (var name in groups) {
156
- this._list[name] = Class.new("Group", [name, groups[name]]);
157
- }
158
- },
159
-
160
- get: function(group_id) {
161
- if (!group_id) {
162
- return this._list;
163
- }
164
- return this._list[group_id];
165
- }
166
- };
167
-
168
- Users = {
169
-
170
- _list: [],
171
- _Model: null,
172
-
173
- get: function() {
174
- return this._list;
175
- },
176
-
177
- add: function(socket) {
178
- var user = Class.new("User", [socket]);
179
- this._list.push(user);
180
- return user;
181
- }
182
-
183
-
184
-
185
- };
186
-
187
- Groups.init();
188
-
189
- return Users;
190
- }