Permalink
Browse files

CanvasEngine folder content

  • Loading branch information...
1 parent da1d5aa commit 3533cade6d2cdb613b6a924ba2867dd5c190b0dd @kelvan kelvan committed Dec 15, 2012
Showing with 16,275 additions and 0 deletions.
  1. +11 −0 CanvasEngine/canvasengine-1.0.7.all.min.js
  2. +2,300 −0 CanvasEngine/canvasengine.js
  3. +251 −0 CanvasEngine/core/ModelServer.js
  4. +534 −0 CanvasEngine/core/engine-common.js
  5. +36 −0 CanvasEngine/doc/cocoonjs.md
  6. +32 −0 CanvasEngine/doc/doc-lang.yml
  7. +10 −0 CanvasEngine/doc/doc-router.yml
  8. +6 −0 CanvasEngine/doc/doc-tuto.yml
  9. +30 −0 CanvasEngine/doc/doc.yml
  10. +37 −0 CanvasEngine/doc/element.md
  11. +47 −0 CanvasEngine/doc/extend.md
  12. +19 −0 CanvasEngine/doc/get_started.md
  13. +69 −0 CanvasEngine/doc/nodejs.md
  14. +44 −0 CanvasEngine/doc/scene.md
  15. +31 −0 CanvasEngine/examples/server/client.html
  16. +11 −0 CanvasEngine/examples/server/server.js
  17. +734 −0 CanvasEngine/extends/Animation.js
  18. +248 −0 CanvasEngine/extends/Gleed2d.js
  19. +661 −0 CanvasEngine/extends/Input.js
  20. +662 −0 CanvasEngine/extends/Marshal.js
  21. +290 −0 CanvasEngine/extends/Scrolling.js
  22. +3,708 −0 CanvasEngine/extends/Socket.js
  23. +5,466 −0 CanvasEngine/extends/Soundmanager2.js
  24. +182 −0 CanvasEngine/extends/Spritesheet.js
  25. +285 −0 CanvasEngine/extends/Tiled.js
  26. +394 −0 CanvasEngine/extends/gamepad.js
  27. BIN CanvasEngine/extends/swf/soundmanager2.swf
  28. BIN CanvasEngine/extends/swf/soundmanager2_debug.swf
  29. BIN CanvasEngine/extends/swf/soundmanager2_flash9.swf
  30. BIN CanvasEngine/extends/swf/soundmanager2_flash9_debug.swf
  31. +15 −0 CanvasEngine/index.js
  32. +19 −0 CanvasEngine/license.txt
  33. +18 −0 CanvasEngine/package.json
  34. +125 −0 CanvasEngine/readme.md

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,251 @@
+exports.Class = function(Class, CE) {
+ var io = CE.io;
+ /**
+ @doc server
+ @class ModelServer Model used for the server. Socket.io resumes with a notion of class
+ 1. Import CanvasEngine
+ 2. Listen a port
+ 3. Initialize the model with a main class
+ <code>
+ var CE = require("canvasengine").listen(8336);
+
+ CE.Model.init("Main", {
+
+ initialize: function() {
+ // Code
+ }
+ });
+ </code>
+ */
+ Class.create("ModelServer", {
+ /**
+ @doc server/
+ @property socket The socket user (socket.io)
+ @type Object
+ @default null
+ */
+ socket: null,
+ _models: {},
+ /**
+ @doc server/
+ @method init Initializes the connection and call the class
+ @params {String} name Class name
+ @params {Array} name (optional) Name of the methods that can be called by the client
+ @params {Object} model (optional) Properties and methods of this class
+ - the "initialize" method is called automatically when the connection
+ - the "disconnect" method is called when the user logs out
+ @example
+ <code>
+ var CE = require("canvasengine").listen(8336);
+
+ CE.Model.init("Main", {
+
+ initialize: function() {
+ // Code
+ }
+ });
+ </code>
+ @return {ModelServer}
+ */
+ init: function(name, events, model) {
+ if (!(events instanceof Array)) {
+ model = events;
+ events = false;
+ }
+ if (!events) {
+ events = [];
+ }
+ var self = this;
+ events.push("disconnect");
+ this.create(name, events, model);
+ io.sockets.on('connection', function (socket) {
+ self.socket = socket;
+ self.new(name);
+ });
+ return this;
+ },
+ /**
+ @doc server/
+ @method create Create a model
+ @params {String} name Class name
+ @params {Array} name (optional) Name of the methods that can be called by the client
+ @params {Object} model (optional) Properties and methods of this class
+ @example
+ Module in "/mods/myclass.js" :
+ <code>
+ exports.Class = function(CE) {
+ return CE.Model.create("MyClass", {
+
+ initialize: function() {
+ // Code
+ }
+
+ });
+ }
+ </code>
+ In main JS file :
+ <code>
+ var CE = require("canvasengine").listen(8336);
+ CE.Model.init("Main", {
+
+ initialize: function() {
+ var Class = require('./mods/myclass').Class(CE),
+ myclass = Class.new("MyClass");
+ }
+ });
+ </code>
+ @return {Class}
+ */
+ create: function(name, events, model) {
+ if (!(events instanceof Array)) {
+ model = events;
+ events = false;
+ }
+ var self = this;
+ this._models[name] = events;
+ return Class.create(name, model).extend({
+ /**
+ @doc server/
+ @property scene Sends data to the scene
+ @type Object
+ @example
+ Server :
+ <code>
+ var CE = require("canvasengine").listen(8336);
+ CE.Model.init("Main", {
+ initialize: function() {
+ this.scene.emit("foo", "Hello");
+ }
+ });
+ </code>
+ Client :
+ var Model = io.connect('http://127.0.0.1:8333');
+
+ var canvas = CE.defines("canvas").
+ ready(function() {
+ canvas.Scene.call("MyScene");
+ });
+
+ canvas.Scene.new({
+ name: "MyScene",
+ model: Model,
+ events: ["foo"],
+ ready: function(stage) {
+
+ },
+ foo: function(text) {
+ console.log(text);
+ }
+ });
+ */
+ scene: {
+ /**
+ @doc server/
+ @method scene.emit (View Socket.io)
+ */
+ emit: function(name, value) {
+ self.socket.emit(name, value);
+ },
+ /**
+ @doc server/
+ @method scene.broadcast.emit (View Socket.io)
+ */
+ /**
+ @doc server/
+ @method scene.broadcast.to (View Socket.io)
+ */
+ broadcast: {
+ emit: function(name, value) {
+ self.socket.broadcast.emit(name, value);
+ },
+ to: function(room, name, value) {
+ self.socket.broadcast.to(room).emit(name, value);
+ }
+ },
+ /**
+ @doc server/
+ @method scene.join (View Socket.io)
+ */
+ join: function(room) {
+ self.socket.join(room);
+ },
+ /**
+ @doc server/
+ @method scene.leave (View Socket.io)
+ */
+ leave: function(room) {
+ self.socket.leave(room);
+ },
+ /**
+ @doc server/
+ @method scene.disconnect (View Socket.io)
+ */
+ disconnect: function(data) {
+ io.sockets.emit(data);
+ }
+ }
+ });
+
+ },
+ /**
+ @doc server/
+ @method new Instantiating a model
+ @params {String} name Class name
+ @example
+ Module in "/mods/myclass.js" :
+ <code>
+ exports.Class = function(CE) {
+ var Class = CE.Model.create("MyClass", {
+
+ initialize: function() {
+ // Code
+ },
+
+ foo: function() {
+ console.log("Hello World");
+ }
+
+ });
+ return Class.new("MyClass");
+ }
+ </code>
+ In main JS file :
+ <code>
+ var CE = require("canvasengine").listen(8336);
+ CE.Model.init("Main", {
+
+ initialize: function() {
+ var myclass = require('./mods/myclass').Class(CE);
+ myclass.foo();
+ }
+ });
+ </code>
+ @return {Class}
+ */
+ new: function(name) {
+ var self = this;
+ var _class = Class.new(name);
+ var events = this._models[name];
+ if (events) {
+ for (var key in events) {
+ obj = _class[events[key]];
+ if (obj) {
+ setEvent.call(this, _class, key, obj);
+ }
+ }
+ }
+
+ function setEvent(_class, key, obj) {
+ this.socket.on(events[key], function(data) {
+ if (!data) {
+ data = {};
+ }
+ if (obj) obj.call(_class, data);
+ });
+ }
+
+ return _class;
+ }
+ });
+ return Class.new("ModelServer");
+}
Oops, something went wrong.

0 comments on commit 3533cad

Please sign in to comment.