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.
- package/.cursorrules +0 -0
- package/README.md +71 -0
- package/dist/compiler/vite.js +119 -0
- package/dist/compiler/vite.js.map +1 -0
- package/dist/index.d.ts +846 -0
- package/dist/index.js +3340 -0
- package/dist/index.js.map +1 -0
- package/logo.png +0 -0
- package/package.json +88 -15
- package/src/compiler/grammar.pegjs +180 -0
- package/src/compiler/vite.ts +166 -0
- package/src/components/Canvas.ts +134 -0
- package/src/components/Container.ts +46 -0
- package/src/components/DisplayObject.ts +458 -0
- package/src/components/DrawMap/index.ts +65 -0
- package/src/components/Graphic.ts +147 -0
- package/src/components/NineSliceSprite.ts +46 -0
- package/src/components/ParticleEmitter.ts +39 -0
- package/src/components/Scene.ts +6 -0
- package/src/components/Sprite.ts +493 -0
- package/src/components/Text.ts +145 -0
- package/src/components/Tilemap/Tile.ts +79 -0
- package/src/components/Tilemap/TileGroup.ts +207 -0
- package/src/components/Tilemap/TileLayer.ts +163 -0
- package/src/components/Tilemap/TileSet.ts +41 -0
- package/src/components/Tilemap/index.ts +80 -0
- package/src/components/TilingSprite.ts +39 -0
- package/src/components/Viewport.ts +159 -0
- package/src/components/index.ts +12 -0
- package/src/components/types/DisplayObject.ts +68 -0
- package/src/components/types/MouseEvent.ts +3 -0
- package/src/components/types/Spritesheet.ts +389 -0
- package/src/components/types/index.ts +4 -0
- package/src/directives/Drag.ts +84 -0
- package/src/directives/KeyboardControls.ts +922 -0
- package/src/directives/Scheduler.ts +112 -0
- package/src/directives/Sound.ts +91 -0
- package/src/directives/Transition.ts +45 -0
- package/src/directives/ViewportCull.ts +40 -0
- package/src/directives/ViewportFollow.ts +26 -0
- package/src/directives/index.ts +7 -0
- package/src/engine/animation.ts +113 -0
- package/src/engine/bootstrap.ts +19 -0
- package/src/engine/directive.ts +23 -0
- package/src/engine/reactive.ts +379 -0
- package/src/engine/signal.ts +138 -0
- package/src/engine/trigger.ts +40 -0
- package/src/engine/utils.ts +135 -0
- package/src/hooks/addContext.ts +6 -0
- package/src/hooks/useProps.ts +155 -0
- package/src/hooks/useRef.ts +21 -0
- package/src/index.ts +14 -0
- package/src/presets/Bar.ts +89 -0
- package/src/presets/Button.ts +0 -0
- package/src/presets/Joystick.ts +286 -0
- package/src/presets/NightAmbiant.ts +122 -0
- package/src/presets/Particle.ts +53 -0
- package/src/utils/Ease.ts +33 -0
- package/src/utils/RadialGradient.ts +86 -0
- package/starter/assets/logo.png +0 -0
- package/starter/components/app.ce +18 -0
- package/starter/components/hello.ce +34 -0
- package/starter/index.html +21 -0
- package/starter/main.ts +4 -0
- package/starter/package.json +16 -0
- package/starter/vite.config.ts +12 -0
- package/tsconfig.json +32 -0
- package/tsconfig.node.json +10 -0
- package/tsup.config.ts +28 -0
- package/vitest.config.ts +12 -0
- package/core/ModelServer.js +0 -251
- package/core/engine-common.js +0 -534
- package/examples/server/client.html +0 -31
- package/examples/server/server.js +0 -11
- package/extends/Gleed2d.js +0 -248
- package/extends/Marshal.js +0 -662
- package/extends/Tiled.js +0 -293
- package/index.js +0 -15
- package/license.txt +0 -19
- package/readme.md +0 -69
package/core/engine-common.js
DELETED
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
var fs;
|
|
2
|
-
if (typeof(require) !== "undefined") {
|
|
3
|
-
fs = require('fs');
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function Kernel(class_method, name) {
|
|
7
|
-
this.class_method = class_method;
|
|
8
|
-
this.class_name = name;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Kernel._extend = function(self, object, clone) {
|
|
12
|
-
clone = clone === undefined ? true : clone;
|
|
13
|
-
if (typeof object == "string") {
|
|
14
|
-
if (Class.__class_config[object]) {
|
|
15
|
-
object = Class.__class_config[object].methods;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return self;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (clone) object = CanvasEngine.clone(object);
|
|
23
|
-
|
|
24
|
-
for (var key in object) {
|
|
25
|
-
self[key] = object[key];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return self;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
Kernel.prototype = {
|
|
32
|
-
New: function() { return this["new"].apply(this, arguments) },
|
|
33
|
-
"new": function() {
|
|
34
|
-
this._class = new Class();
|
|
35
|
-
Class.__class[this.class_name] = this._class;
|
|
36
|
-
this._construct();
|
|
37
|
-
return this._class;
|
|
38
|
-
},
|
|
39
|
-
_construct: function() {
|
|
40
|
-
this._class.extend(this.class_method);
|
|
41
|
-
},
|
|
42
|
-
_attr_accessor: function(attrs, reader, writer) {
|
|
43
|
-
var self = this;
|
|
44
|
-
for (var i=0 ; i < attrs.length ; i++) {
|
|
45
|
-
this.class_method["_" + attrs[i]] = null;
|
|
46
|
-
this.class_method[attrs[i]] = {};
|
|
47
|
-
if (reader) {
|
|
48
|
-
this.class_method[attrs[i]].set = function(value) {
|
|
49
|
-
self.class_method["_" + attrs[i]] = value;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (writer) {
|
|
53
|
-
this.class_method[attrs[i]].get = function() {
|
|
54
|
-
return self.class_method["_" + attrs[i]];
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return this;
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
@doc class/
|
|
62
|
-
@method attr_accessor Defines the properties that can be read and modified
|
|
63
|
-
@params {Array} Properties names in an array
|
|
64
|
-
@example
|
|
65
|
-
<code>
|
|
66
|
-
Class.create("Foo", {
|
|
67
|
-
|
|
68
|
-
mymethod: function() {
|
|
69
|
-
this.bar.set(5);
|
|
70
|
-
console.log(this.bar.get()); // Value of property "bar" is 5
|
|
71
|
-
console.log(this._bar); // ditto
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}).attr_accessor(["bar"]);
|
|
75
|
-
</code>
|
|
76
|
-
<jsfiddle>WebCreative5/HzCSm/1</jsfiddle>
|
|
77
|
-
@return {Object}
|
|
78
|
-
*/
|
|
79
|
-
attr_accessor: function(attrs) {
|
|
80
|
-
return this._attr_accessor(attrs, true, true);
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
@doc class/
|
|
84
|
-
@method attr_reader Defines the properties that can be only read
|
|
85
|
-
@params {Array} Properties names in an array
|
|
86
|
-
@example
|
|
87
|
-
<code>
|
|
88
|
-
Class.create("Foo", {
|
|
89
|
-
|
|
90
|
-
mymethod: function() {
|
|
91
|
-
console.log(this.bar.get());
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
}).attr_reader(["bar"]);
|
|
95
|
-
</code>
|
|
96
|
-
@return {Object}
|
|
97
|
-
*/
|
|
98
|
-
attr_reader: function(attrs) {
|
|
99
|
-
return this._attr_accessor(attrs, true, false);
|
|
100
|
-
},
|
|
101
|
-
/**
|
|
102
|
-
@doc class/
|
|
103
|
-
@method attr_writer Defines the properties that can be only modified
|
|
104
|
-
@params {Array} Properties names in an array
|
|
105
|
-
@example
|
|
106
|
-
<code>
|
|
107
|
-
Class.create("Foo", {
|
|
108
|
-
|
|
109
|
-
mymethod: function() {
|
|
110
|
-
this.bar.set(5);
|
|
111
|
-
console.log(this._bar);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
}).attr_writer(["bar"]);
|
|
115
|
-
</code>
|
|
116
|
-
@return {Object}
|
|
117
|
-
*/
|
|
118
|
-
attr_writer: function(attrs) {
|
|
119
|
-
return this._attr_accessor(attrs, false, true);
|
|
120
|
-
},
|
|
121
|
-
/**
|
|
122
|
-
@doc class/
|
|
123
|
-
@method extend add object in this class
|
|
124
|
-
@params {Object} object
|
|
125
|
-
@params {Boolean} clone (optional) Makes a clone of the object (false by default)
|
|
126
|
-
@example
|
|
127
|
-
<code>
|
|
128
|
-
Class.create("Foo", {
|
|
129
|
-
|
|
130
|
-
mymethod: function() {
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
}).extend({
|
|
135
|
-
othermethod: function() {
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
</code>
|
|
140
|
-
@return {Object}
|
|
141
|
-
*/
|
|
142
|
-
extend: function(object, clone) {
|
|
143
|
-
Kernel._extend(this.class_method, object, clone);
|
|
144
|
-
return this;
|
|
145
|
-
},
|
|
146
|
-
// TODO
|
|
147
|
-
addIn: function(name) {
|
|
148
|
-
if (!Class.__class[name]) {
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
Class.__class[name][this.name] = this;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function Class() {
|
|
158
|
-
this.name = null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
Class.__class = {};
|
|
162
|
-
Class.__class_config = {};
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
@doc class/
|
|
166
|
-
@method get By retrieve the class name
|
|
167
|
-
@static
|
|
168
|
-
@params {String} name Class name
|
|
169
|
-
@return {Kernel} Core class
|
|
170
|
-
*/
|
|
171
|
-
Class.get = function(name) {
|
|
172
|
-
return Class.__class[name];
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
@doc class/
|
|
177
|
-
@method create Creating a class. the constructor is the method "initialize"
|
|
178
|
-
@static
|
|
179
|
-
@params {String} name Class name
|
|
180
|
-
@params {Object} methods Methods and properties of the class
|
|
181
|
-
@example
|
|
182
|
-
<code>
|
|
183
|
-
Class.create("Foo", {
|
|
184
|
-
bar: null,
|
|
185
|
-
initialize: function(bar) {
|
|
186
|
-
this.bar = bar;
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
var foo = Class.new("Foo", ["Hello World"]);
|
|
190
|
-
</code>
|
|
191
|
-
<jsfiddle>WebCreative5/cbtFk</jsfiddle>
|
|
192
|
-
@return {Kernel} Core class
|
|
193
|
-
*/
|
|
194
|
-
Class.create = function(name, methods, _static) {
|
|
195
|
-
var p, _class, _tmp_class;
|
|
196
|
-
|
|
197
|
-
/*if (typeof(window) === 'undefined') {
|
|
198
|
-
var window = {};
|
|
199
|
-
}*/
|
|
200
|
-
Class.__class_config[name] = {};
|
|
201
|
-
Class.__class[name] = {};
|
|
202
|
-
/* Class.__class[name] = function(params) {
|
|
203
|
-
// this.__parent = Class;
|
|
204
|
-
// this.__parent();
|
|
205
|
-
if (this.initialize) {
|
|
206
|
-
this.initialize.apply(this, params);
|
|
207
|
-
}
|
|
208
|
-
};*/
|
|
209
|
-
|
|
210
|
-
if (_static) {
|
|
211
|
-
p = window[name];
|
|
212
|
-
tmp_class = new Class();
|
|
213
|
-
for (var key in tmp_class) {
|
|
214
|
-
p[key] = tmp_class[key];
|
|
215
|
-
}
|
|
216
|
-
for (var key in methods) {
|
|
217
|
-
p[key] = methods[key];
|
|
218
|
-
}
|
|
219
|
-
_class = p;
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
//p = Class.__class[name].prototype = methods;
|
|
223
|
-
Class.__class_config[name].methods = methods;
|
|
224
|
-
var kernel = Class.__class_config[name].kernel = new Kernel(Class.__class_config[name].methods, name);
|
|
225
|
-
//p.extend(methods);
|
|
226
|
-
}
|
|
227
|
-
return kernel;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
@doc class/
|
|
232
|
-
@method new new class.
|
|
233
|
-
@static
|
|
234
|
-
@params {String} name Class name
|
|
235
|
-
@params {Array} params Parameters for the constructor
|
|
236
|
-
@return {Class}
|
|
237
|
-
*/
|
|
238
|
-
Class.New = function() { return Class["new"].apply(this, arguments) };
|
|
239
|
-
Class["new"] = function(name, params) {
|
|
240
|
-
var _class;
|
|
241
|
-
params = params || [];
|
|
242
|
-
if (!Class.__class_config[name]) {
|
|
243
|
-
throw name + " class does not exist. Use method \"create\" for build the structure of this class";
|
|
244
|
-
}
|
|
245
|
-
_class = Class.__class_config[name].kernel["new"]();
|
|
246
|
-
if (_class.initialize) {
|
|
247
|
-
_class.initialize.apply(_class, params);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
_class.__name__ = name;
|
|
251
|
-
return _class;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
Class.prototype = {
|
|
255
|
-
/**
|
|
256
|
-
@method extend add object in this class
|
|
257
|
-
@params {Object} object
|
|
258
|
-
@parmas {Boolean} clone (optional) Makes a clone of the object (false by default)
|
|
259
|
-
@example
|
|
260
|
-
<code>
|
|
261
|
-
Class.create("Foo", {
|
|
262
|
-
|
|
263
|
-
mymethod: function() {
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
});
|
|
268
|
-
Class.new("Foo").extend({
|
|
269
|
-
othermethod: function() {
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
</code>
|
|
274
|
-
@return {Object}
|
|
275
|
-
*/
|
|
276
|
-
extend: function(object, clone) {
|
|
277
|
-
return Kernel._extend(this, object, clone);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
var CanvasEngine = {};
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
@doc utilities/
|
|
285
|
-
@method uniqid Generating a unique identifier by date
|
|
286
|
-
@static
|
|
287
|
-
@return {String}
|
|
288
|
-
*/
|
|
289
|
-
CanvasEngine.uniqid = function() {
|
|
290
|
-
// return new Date().getTime();
|
|
291
|
-
return Math.random();
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
@doc utilities/
|
|
296
|
-
@method arraySplice Removes an element in an array by value
|
|
297
|
-
@static
|
|
298
|
-
@params {Object} val
|
|
299
|
-
@params {Array} array
|
|
300
|
-
*/
|
|
301
|
-
CanvasEngine.arraySplice = function(val, array) {
|
|
302
|
-
var i;
|
|
303
|
-
for (i=0 ; i < array.length ; ++i) {
|
|
304
|
-
if (val == array[i]) {
|
|
305
|
-
array.splice(i, 1);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
@doc ajax/
|
|
313
|
-
@method ajax Perform an asynchronous HTTP (Ajax) request. System uses wire on Node.js
|
|
314
|
-
@static
|
|
315
|
-
@params {Object} options
|
|
316
|
-
- url {String} File Path
|
|
317
|
-
- type {String} (optional) "GET" (default) or "POST"
|
|
318
|
-
- data {Object} (optional) Data key/value
|
|
319
|
-
- dataType {String} (optional) "text" (default), "json" or "xml"
|
|
320
|
-
- success {Function} (optional) Callback if the request was successful
|
|
321
|
-
*/
|
|
322
|
-
CanvasEngine.ajax = function(options) {
|
|
323
|
-
|
|
324
|
-
if (!options) options = {};
|
|
325
|
-
options.url = options.url || "./";
|
|
326
|
-
options.type = options.type || "GET";
|
|
327
|
-
options.data = options.data ? JSON.stringify(options.data) : null;
|
|
328
|
-
|
|
329
|
-
if (fs) {
|
|
330
|
-
fs.readFile('./' + options.url, 'ascii', function (err, ret) {
|
|
331
|
-
if (err) throw err;
|
|
332
|
-
ret = ret.toString('ascii');
|
|
333
|
-
if (options.dataType == 'json') {
|
|
334
|
-
ret = CanvasEngine.parseJSON(ret);
|
|
335
|
-
}
|
|
336
|
-
options.success(ret);
|
|
337
|
-
});
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
var xhr;
|
|
342
|
-
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
|
|
343
|
-
catch (e)
|
|
344
|
-
{
|
|
345
|
-
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
|
|
346
|
-
catch (e2)
|
|
347
|
-
{
|
|
348
|
-
try { xhr = new XMLHttpRequest(); }
|
|
349
|
-
catch (e3) { xhr = false; }
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
xhr.onreadystatechange = function() {
|
|
354
|
-
var ret;
|
|
355
|
-
if(xhr.readyState == 4) {
|
|
356
|
-
if(xhr.status == 200) {
|
|
357
|
-
if (options.success) {
|
|
358
|
-
ret = xhr.responseText;
|
|
359
|
-
if (options.dataType == 'json') {
|
|
360
|
-
ret = CanvasEngine.parseJSON(ret);
|
|
361
|
-
}
|
|
362
|
-
else if (options.dataType == 'xml') {
|
|
363
|
-
ret = xhr.responseXML;
|
|
364
|
-
}
|
|
365
|
-
options.success(ret);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
xhr.open(options.type, options.url, true);
|
|
372
|
-
xhr.send(options.data);
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
@doc ajax/
|
|
378
|
-
@method getJSON Load JSON-encoded data from the server using a GET HTTP request.
|
|
379
|
-
@static
|
|
380
|
-
@params {String} url File Path
|
|
381
|
-
@params {String} (optional) data Data key/value
|
|
382
|
-
@params {Function} (optional) callback Callback if the request was successful
|
|
383
|
-
*/
|
|
384
|
-
CanvasEngine.getJSON = function(url, data, callback) {
|
|
385
|
-
if (typeof data == "function") {
|
|
386
|
-
callback = data;
|
|
387
|
-
data = null;
|
|
388
|
-
}
|
|
389
|
-
CanvasEngine.ajax({
|
|
390
|
-
url: url,
|
|
391
|
-
dataType: 'json',
|
|
392
|
-
data: data,
|
|
393
|
-
success: callback
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
@doc utilities/
|
|
399
|
-
@method parseJSON Takes a well-formed JSON string and returns the resulting JavaScript object.
|
|
400
|
-
@static
|
|
401
|
-
@params {String} json JSON format
|
|
402
|
-
@return {Object}
|
|
403
|
-
*/
|
|
404
|
-
CanvasEngine.parseJSON = function(json) {
|
|
405
|
-
return JSON.parse(json);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
@doc utilities/
|
|
410
|
-
@method each The array is read and sent to a callback function
|
|
411
|
-
@static
|
|
412
|
-
@params {Array|Integer} array If the value is an integer, it returns to perform a number of loop iteration
|
|
413
|
-
@params {Function} callback two parameters :
|
|
414
|
-
- index
|
|
415
|
-
- value
|
|
416
|
-
@example
|
|
417
|
-
<code>
|
|
418
|
-
var foo = ["bar", "test"];
|
|
419
|
-
CE.each(foo, function(i, val) {
|
|
420
|
-
console.log(val);
|
|
421
|
-
});
|
|
422
|
-
</code>
|
|
423
|
-
<code>
|
|
424
|
-
var foo = ["bar", "test"];
|
|
425
|
-
CE.each(2, function(i) {
|
|
426
|
-
console.log(foo[i]);
|
|
427
|
-
});
|
|
428
|
-
</code>
|
|
429
|
-
*/
|
|
430
|
-
CanvasEngine.each = function(array, callback) {
|
|
431
|
-
var i, l;
|
|
432
|
-
if (array instanceof Array) {
|
|
433
|
-
l = array.length;
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
l = array;
|
|
437
|
-
array = [];
|
|
438
|
-
}
|
|
439
|
-
for (i=0 ; i < l ; ++i) {
|
|
440
|
-
callback.call(array, i, array[i]);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
@doc utilities/
|
|
446
|
-
@method inArray The CE.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, CE.inArray() returns 0.
|
|
447
|
-
|
|
448
|
-
Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), if we're checking for the presence of value within array, we need to check if it's not equal to (or greater than) -1.
|
|
449
|
-
@static
|
|
450
|
-
@params {String} val The value to search for.
|
|
451
|
-
@params {Array} array An array through which to search.
|
|
452
|
-
@return {Integer}
|
|
453
|
-
*/
|
|
454
|
-
CanvasEngine.inArray = function(val, array) {
|
|
455
|
-
var i;
|
|
456
|
-
for (i=0 ; i < array.length ; ++i) {
|
|
457
|
-
if (val == array[i]) {
|
|
458
|
-
return i;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return -1;
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
@doc engine/
|
|
466
|
-
@method clone Clone an object
|
|
467
|
-
@static
|
|
468
|
-
@params {Object} instance
|
|
469
|
-
@return {Object}
|
|
470
|
-
*/
|
|
471
|
-
CanvasEngine.clone = function(srcInstance) {
|
|
472
|
-
var i;
|
|
473
|
-
if(typeof(srcInstance) != 'object' || srcInstance == null) {
|
|
474
|
-
return srcInstance;
|
|
475
|
-
}
|
|
476
|
-
var newInstance = srcInstance.constructor();
|
|
477
|
-
if (newInstance === undefined) {
|
|
478
|
-
return srcInstance;
|
|
479
|
-
}
|
|
480
|
-
for(i in srcInstance){
|
|
481
|
-
newInstance[i] = CanvasEngine.clone(srcInstance[i]);
|
|
482
|
-
}
|
|
483
|
-
return newInstance;
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
@doc utilities/
|
|
488
|
-
@method hexaToRGB Converts the hexadecimal value of a color in RGB. Returns an array with 3 colors : [r, g, b]
|
|
489
|
-
@static
|
|
490
|
-
@params {String} hexa Hexadecimal with or without #
|
|
491
|
-
@return {Array}
|
|
492
|
-
*/
|
|
493
|
-
CanvasEngine.hexaToRGB = function(hexa) {
|
|
494
|
-
var r, g, b;
|
|
495
|
-
|
|
496
|
-
function cutHex(h) {
|
|
497
|
-
return (h.charAt(0) == "#") ? h.substring(1,7) : h;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
r = parseInt((cutHex(hexa)).substring(0,2),16);
|
|
501
|
-
g = parseInt((cutHex(hexa)).substring(2,4),16);
|
|
502
|
-
b = parseInt((cutHex(hexa)).substring(4,6),16);
|
|
503
|
-
|
|
504
|
-
return [r, g, b];
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
@doc utilities/
|
|
509
|
-
@method rgbToHex Converts the RGB value of a color in Hexadecimal.
|
|
510
|
-
@static
|
|
511
|
-
@params {String} r Red value (0-255)
|
|
512
|
-
@params {String} g Green value (0-255)
|
|
513
|
-
@params {String} b Blue value (0-255)
|
|
514
|
-
@return {String}
|
|
515
|
-
*/
|
|
516
|
-
CanvasEngine.rgbToHex = function(r, g, b) {
|
|
517
|
-
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
// Private
|
|
521
|
-
CanvasEngine._getRandomColorKey = function() {
|
|
522
|
-
var r = Math.round(Math.random() * 255),
|
|
523
|
-
g = Math.round(Math.random() * 255),
|
|
524
|
-
b = Math.round(Math.random() * 255);
|
|
525
|
-
return CanvasEngine.rgbToHex(r, g, b);
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
var _CanvasEngine = CanvasEngine;
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (typeof(exports) !== "undefined") {
|
|
532
|
-
exports.Class = Class;
|
|
533
|
-
exports.CanvasEngine = CanvasEngine;
|
|
534
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<script src="http://canvasengine.net/cdn/canvasengine-latest.all.min.js"></script>
|
|
5
|
-
<script>
|
|
6
|
-
var Model = io.connect('http://127.0.0.1:8333');
|
|
7
|
-
|
|
8
|
-
var canvas = CE.defines("canvas").
|
|
9
|
-
ready(function() {
|
|
10
|
-
canvas.Scene.call("MyScene");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
canvas.Scene.new({
|
|
14
|
-
name: "MyScene",
|
|
15
|
-
model: Model,
|
|
16
|
-
events: ["load"],
|
|
17
|
-
ready: function(stage) {
|
|
18
|
-
this.model.emit("start");
|
|
19
|
-
},
|
|
20
|
-
load: function(text) {
|
|
21
|
-
console.log(text);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
</script>
|
|
26
|
-
</head>
|
|
27
|
-
<body>
|
|
28
|
-
<canvas id="canvas" width="675px" height="506px"></canvas>
|
|
29
|
-
</body>
|
|
30
|
-
</html>
|
|
31
|
-
|