|
|
@ -21,6 +21,8 @@ Engine = (function() {
|
|
|
|
this.createSound = __bind(this.createSound, this);
|
|
|
|
this.createSound = __bind(this.createSound, this);
|
|
|
|
this.createObject = __bind(this.createObject, this);
|
|
|
|
this.createObject = __bind(this.createObject, this);
|
|
|
|
this.createScene = __bind(this.createScene, this);
|
|
|
|
this.createScene = __bind(this.createScene, this);
|
|
|
|
|
|
|
|
this.switchInitialScene = __bind(this.switchInitialScene, this);
|
|
|
|
|
|
|
|
this.switchPreloadScene = __bind(this.switchPreloadScene, this);
|
|
|
|
this.setPreloadScene = __bind(this.setPreloadScene, this);
|
|
|
|
this.setPreloadScene = __bind(this.setPreloadScene, this);
|
|
|
|
this.setInitialScene = __bind(this.setInitialScene, this);
|
|
|
|
this.setInitialScene = __bind(this.setInitialScene, this);
|
|
|
|
this.skipTimers = __bind(this.skipTimers, this);
|
|
|
|
this.skipTimers = __bind(this.skipTimers, this);
|
|
|
@ -46,6 +48,8 @@ Engine = (function() {
|
|
|
|
this.named_timers = {};
|
|
|
|
this.named_timers = {};
|
|
|
|
this.unnamed_timers = [];
|
|
|
|
this.unnamed_timers = [];
|
|
|
|
this.ease.engine = this;
|
|
|
|
this.ease.engine = this;
|
|
|
|
|
|
|
|
this.draw.engine = this;
|
|
|
|
|
|
|
|
this.resource_manager.engine = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Engine.prototype.addCanvas = function(canvas, label) {
|
|
|
|
Engine.prototype.addCanvas = function(canvas, label) {
|
|
|
@ -78,7 +82,6 @@ Engine = (function() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Engine.prototype.start = function() {
|
|
|
|
Engine.prototype.start = function() {
|
|
|
|
this.initial_scene.addTargetSurface(this.canvases[""]);
|
|
|
|
|
|
|
|
return this.loop();
|
|
|
|
return this.loop();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -178,6 +181,18 @@ Engine = (function() {
|
|
|
|
return this.preload_scene = scene;
|
|
|
|
return this.preload_scene = scene;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Engine.prototype.switchPreloadScene = function() {
|
|
|
|
|
|
|
|
return this.preload_scene.addTargetSurface(this.canvases[""]);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Engine.prototype.switchInitialScene = function() {
|
|
|
|
|
|
|
|
var _ref;
|
|
|
|
|
|
|
|
if ((_ref = this.preload_scene) != null) {
|
|
|
|
|
|
|
|
_ref.removeTargetSurface(this.canvases[""]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.initial_scene.addTargetSurface(this.canvases[""]);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Engine.prototype.createScene = function(name) {
|
|
|
|
Engine.prototype.createScene = function(name) {
|
|
|
|
var scene;
|
|
|
|
var scene;
|
|
|
|
scene = new Scene(this, name);
|
|
|
|
scene = new Scene(this, name);
|
|
|
@ -258,18 +273,15 @@ Engine = (function() {
|
|
|
|
})();
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
Engine.prototype.draw = {
|
|
|
|
Engine.prototype.draw = {
|
|
|
|
_startPath: (function(_this) {
|
|
|
|
_startPath: function(surface, options) {
|
|
|
|
return function(surface, options) {
|
|
|
|
|
|
|
|
var _ref;
|
|
|
|
var _ref;
|
|
|
|
surface = _this.getSurface(surface);
|
|
|
|
surface = this.engine.getSurface(surface);
|
|
|
|
if ((_ref = !options._is_text) != null ? _ref : false) {
|
|
|
|
if ((_ref = !options._is_text) != null ? _ref : false) {
|
|
|
|
surface.beginPath();
|
|
|
|
surface.beginPath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return surface;
|
|
|
|
return surface;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
_finishPath: function(surface, options) {
|
|
|
|
_finishPath: (function(_this) {
|
|
|
|
|
|
|
|
return function(surface, options) {
|
|
|
|
|
|
|
|
var _ref, _ref1, _ref10, _ref11, _ref12, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
|
|
|
|
var _ref, _ref1, _ref10, _ref11, _ref12, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
|
|
|
|
if ((_ref = options.stroke) != null ? _ref : true) {
|
|
|
|
if ((_ref = options.stroke) != null ? _ref : true) {
|
|
|
|
surface.lineWidth = (_ref1 = (_ref2 = options.lineWidth) != null ? _ref2 : (_ref3 = options.pen) != null ? _ref3.lineWidth : void 0) != null ? _ref1 : 1;
|
|
|
|
surface.lineWidth = (_ref1 = (_ref2 = options.lineWidth) != null ? _ref2 : (_ref3 = options.pen) != null ? _ref3.lineWidth : void 0) != null ? _ref1 : 1;
|
|
|
@ -288,19 +300,15 @@ Engine.prototype.draw = {
|
|
|
|
return surface.fill();
|
|
|
|
return surface.fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
_getTextWidth: function(surface, text, options) {
|
|
|
|
_getTextWidth: (function(_this) {
|
|
|
|
|
|
|
|
return function(surface, text, options) {
|
|
|
|
|
|
|
|
var width;
|
|
|
|
var width;
|
|
|
|
_this._applyTextContext(surface, options);
|
|
|
|
this._applyTextContext(surface, options);
|
|
|
|
width = surface.measureText(text).width;
|
|
|
|
width = surface.measureText(text).width;
|
|
|
|
surface.restore();
|
|
|
|
surface.restore();
|
|
|
|
return width;
|
|
|
|
return width;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
_applyTextContext: function(surface, options) {
|
|
|
|
_applyTextContext: (function(_this) {
|
|
|
|
|
|
|
|
return function(surface, options) {
|
|
|
|
|
|
|
|
var font_family, font_size, font_style, font_weight, scale, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
|
|
var font_family, font_size, font_style, font_weight, scale, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
|
|
font_family = (_ref = options.font) != null ? _ref : "sans-serif";
|
|
|
|
font_family = (_ref = options.font) != null ? _ref : "sans-serif";
|
|
|
|
font_size = (_ref1 = options.size) != null ? _ref1 : 16;
|
|
|
|
font_size = (_ref1 = options.size) != null ? _ref1 : 16;
|
|
|
@ -311,37 +319,31 @@ Engine.prototype.draw = {
|
|
|
|
surface.font = "" + font_weight + " " + font_style + " " + font_size + "px '" + font_family + "'";
|
|
|
|
surface.font = "" + font_weight + " " + font_style + " " + font_size + "px '" + font_family + "'";
|
|
|
|
surface.globalAlpha = (_ref5 = options.alpha) != null ? _ref5 : 1;
|
|
|
|
surface.globalAlpha = (_ref5 = options.alpha) != null ? _ref5 : 1;
|
|
|
|
return surface.scale(scale, scale);
|
|
|
|
return surface.scale(scale, scale);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
line: function(x1, y1, x2, y2, options, surface) {
|
|
|
|
line: (function(_this) {
|
|
|
|
|
|
|
|
return function(x1, y1, x2, y2, options, surface) {
|
|
|
|
|
|
|
|
if (options == null) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (surface == null) {
|
|
|
|
if (surface == null) {
|
|
|
|
surface = "";
|
|
|
|
surface = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
surface = _this._startPath(surface, options);
|
|
|
|
surface = this._startPath(surface, options);
|
|
|
|
surface.moveTo(x1, y1);
|
|
|
|
surface.moveTo(x1, y1);
|
|
|
|
surface.lineTo(x2, y2);
|
|
|
|
surface.lineTo(x2, y2);
|
|
|
|
return _this._finishPath(surface, options);
|
|
|
|
return this._finishPath(surface, options);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
rectangle: function(x1, y1, x2, y2, options, surface) {
|
|
|
|
rectangle: (function(_this) {
|
|
|
|
|
|
|
|
return function(x1, y1, x2, y2, options, surface) {
|
|
|
|
|
|
|
|
if (options == null) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (surface == null) {
|
|
|
|
if (surface == null) {
|
|
|
|
surface = "";
|
|
|
|
surface = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
surface = _this._startPath(surface, options);
|
|
|
|
surface = this._startPath(surface, options);
|
|
|
|
surface.rect(x1, y1, x2 - x1, y2 - y1);
|
|
|
|
surface.rect(x1, y1, x2 - x1, y2 - y1);
|
|
|
|
return _this._finishPath(surface, options);
|
|
|
|
return this._finishPath(surface, options);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
boxEllipse: function(x1, y1, x2, y2, options, surface) {
|
|
|
|
boxEllipse: (function(_this) {
|
|
|
|
|
|
|
|
return function(x1, y1, x2, y2, options, surface) {
|
|
|
|
|
|
|
|
var rx, ry, x, y;
|
|
|
|
var rx, ry, x, y;
|
|
|
|
if (options == null) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
options = {};
|
|
|
@ -353,11 +355,9 @@ Engine.prototype.draw = {
|
|
|
|
y = (y1 + y2) / 2;
|
|
|
|
y = (y1 + y2) / 2;
|
|
|
|
rx = (x2 - x1) / 2;
|
|
|
|
rx = (x2 - x1) / 2;
|
|
|
|
ry = (y2 - y1) / 2;
|
|
|
|
ry = (y2 - y1) / 2;
|
|
|
|
return _this.radiusEllipse(x, y, rx, ry, options, surface);
|
|
|
|
return this.radiusEllipse(x, y, rx, ry, options, surface);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
radiusEllipse: function(x, y, rx, ry, options, surface) {
|
|
|
|
radiusEllipse: (function(_this) {
|
|
|
|
|
|
|
|
return function(x, y, rx, ry, options, surface) {
|
|
|
|
|
|
|
|
var i, step, _i, _ref, _ref1;
|
|
|
|
var i, step, _i, _ref, _ref1;
|
|
|
|
if (options == null) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
options = {};
|
|
|
@ -365,7 +365,7 @@ Engine.prototype.draw = {
|
|
|
|
if (surface == null) {
|
|
|
|
if (surface == null) {
|
|
|
|
surface = "";
|
|
|
|
surface = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
surface = _this._startPath(surface, options);
|
|
|
|
surface = this._startPath(surface, options);
|
|
|
|
step = (_ref = options.step) != null ? _ref : 0.1;
|
|
|
|
step = (_ref = options.step) != null ? _ref : 0.1;
|
|
|
|
if (rx === ry) {
|
|
|
|
if (rx === ry) {
|
|
|
|
surface.arc(x, y, rx, 0, 2 * Math.PI, false);
|
|
|
|
surface.arc(x, y, rx, 0, 2 * Math.PI, false);
|
|
|
@ -375,11 +375,9 @@ Engine.prototype.draw = {
|
|
|
|
surface.lineTo(x + (Math.cos(i) * rx), y + (Math.sin(i) * ry));
|
|
|
|
surface.lineTo(x + (Math.cos(i) * rx), y + (Math.sin(i) * ry));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _this._finishPath(surface, options);
|
|
|
|
return this._finishPath(surface, options);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
boxPolygon: function(x1, y1, x2, y2, sides, options, surface) {
|
|
|
|
boxPolygon: (function(_this) {
|
|
|
|
|
|
|
|
return function(x1, y1, x2, y2, sides, options, surface) {
|
|
|
|
|
|
|
|
if (options == null) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -387,10 +385,8 @@ Engine.prototype.draw = {
|
|
|
|
surface = "";
|
|
|
|
surface = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pass;
|
|
|
|
return pass;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
radiusPolygon: function(x, y, r, sides, options, surface) {
|
|
|
|
radiusPolygon: (function(_this) {
|
|
|
|
|
|
|
|
return function(x, y, r, sides, options, surface) {
|
|
|
|
|
|
|
|
if (options == null) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -398,10 +394,8 @@ Engine.prototype.draw = {
|
|
|
|
surface = "";
|
|
|
|
surface = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pass;
|
|
|
|
return pass;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})(this),
|
|
|
|
text: function(x, y, text, options, surface) {
|
|
|
|
text: (function(_this) {
|
|
|
|
|
|
|
|
return function(x, y, text, options, surface) {
|
|
|
|
|
|
|
|
var text_width;
|
|
|
|
var text_width;
|
|
|
|
if (options == null) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
options = {};
|
|
|
@ -430,18 +424,17 @@ Engine.prototype.draw = {
|
|
|
|
if (alignment === "left") {
|
|
|
|
if (alignment === "left") {
|
|
|
|
options.x = x;
|
|
|
|
options.x = x;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
text_width = _this._getTextWidth(text, options);
|
|
|
|
text_width = this._getTextWidth(text, options);
|
|
|
|
if (alignment === "center") {
|
|
|
|
if (alignment === "center") {
|
|
|
|
options.x = x - ((text_width / 2) * scale * scale);
|
|
|
|
options.x = x - ((text_width / 2) * scale * scale);
|
|
|
|
} else if (alignment === "right") {
|
|
|
|
} else if (alignment === "right") {
|
|
|
|
options.x = x - text_width;
|
|
|
|
options.x = x - text_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_this._startPath(surface, options);
|
|
|
|
this._startPath(surface, options);
|
|
|
|
_this._finishPath(surface, options);
|
|
|
|
this._finishPath(surface, options);
|
|
|
|
return surface.restore();
|
|
|
|
return surface.restore();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})(this)
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var Ease,
|
|
|
|
var Ease,
|
|
|
@ -1335,6 +1328,7 @@ ResourceManager = (function() {
|
|
|
|
this.load = __bind(this.load, this);
|
|
|
|
this.load = __bind(this.load, this);
|
|
|
|
this.prepare = __bind(this.prepare, this);
|
|
|
|
this.prepare = __bind(this.prepare, this);
|
|
|
|
this.doPreload = __bind(this.doPreload, this);
|
|
|
|
this.doPreload = __bind(this.doPreload, this);
|
|
|
|
|
|
|
|
this.handleComplete = __bind(this.handleComplete, this);
|
|
|
|
this.handleFinishedFile = __bind(this.handleFinishedFile, this);
|
|
|
|
this.handleFinishedFile = __bind(this.handleFinishedFile, this);
|
|
|
|
this.updateProgress = __bind(this.updateProgress, this);
|
|
|
|
this.updateProgress = __bind(this.updateProgress, this);
|
|
|
|
this.getImage = __bind(this.getImage, this);
|
|
|
|
this.getImage = __bind(this.getImage, this);
|
|
|
@ -1479,7 +1473,8 @@ ResourceManager = (function() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ResourceManager.prototype.updateProgress = function(event) {
|
|
|
|
ResourceManager.prototype.updateProgress = function(event) {
|
|
|
|
return this.file_progress = event.progress;
|
|
|
|
console.log(event);
|
|
|
|
|
|
|
|
return this.file_progress = event.loaded / event.total;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ResourceManager.prototype.handleFinishedFile = function(event) {
|
|
|
|
ResourceManager.prototype.handleFinishedFile = function(event) {
|
|
|
@ -1502,7 +1497,18 @@ ResourceManager = (function() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ResourceManager.prototype.doPreload = function(stage, progress_callback, finished_callback) {
|
|
|
|
ResourceManager.prototype.handleComplete = function(event) {
|
|
|
|
|
|
|
|
var stage, _ref, _ref1;
|
|
|
|
|
|
|
|
stage = this.current_stage;
|
|
|
|
|
|
|
|
this.finished_callback();
|
|
|
|
|
|
|
|
if (stage === 1) {
|
|
|
|
|
|
|
|
return (_ref = this.engine) != null ? _ref.switchPreloadScene() : void 0;
|
|
|
|
|
|
|
|
} else if (stage === 2) {
|
|
|
|
|
|
|
|
return (_ref1 = this.engine) != null ? _ref1.switchInitialScene() : void 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResourceManager.prototype.doPreload = function(stage, progress_callback) {
|
|
|
|
var data_file, data_files, image, images, script, scripts, sound, sounds, _i, _j, _k, _l, _len, _len1, _len2, _len3;
|
|
|
|
var data_file, data_files, image, images, script, scripts, sound, sounds, _i, _j, _k, _l, _len, _len1, _len2, _len3;
|
|
|
|
this.current_stage = stage;
|
|
|
|
this.current_stage = stage;
|
|
|
|
if (stage === 1) {
|
|
|
|
if (stage === 1) {
|
|
|
@ -1549,9 +1555,9 @@ ResourceManager = (function() {
|
|
|
|
type: createjs.LoadQueue.JSON
|
|
|
|
type: createjs.LoadQueue.JSON
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.queue.on("progress", progress_callback);
|
|
|
|
this.queue.on("fileprogress", progress_callback);
|
|
|
|
this.queue.on("fileload", this.handleFinishedFile);
|
|
|
|
this.queue.on("fileload", this.handleFinishedFile);
|
|
|
|
this.queue.on("complete", finished_callback);
|
|
|
|
this.queue.on("complete", this.handleComplete);
|
|
|
|
return this.queue.load();
|
|
|
|
return this.queue.load();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -1559,14 +1565,16 @@ ResourceManager = (function() {
|
|
|
|
if (finished_callback == null) {
|
|
|
|
if (finished_callback == null) {
|
|
|
|
finished_callback = (function() {});
|
|
|
|
finished_callback = (function() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.doPreload(1, (function() {}), finished_callback.bind(this));
|
|
|
|
this.finished_callback = finished_callback.bind(this);
|
|
|
|
|
|
|
|
return this.doPreload(1, (function() {}));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ResourceManager.prototype.load = function(finished_callback) {
|
|
|
|
ResourceManager.prototype.load = function(finished_callback) {
|
|
|
|
if (finished_callback == null) {
|
|
|
|
if (finished_callback == null) {
|
|
|
|
finished_callback = (function() {});
|
|
|
|
finished_callback = (function() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.doPreload(2, this.updateProgress, finished_callback.bind(this));
|
|
|
|
this.finished_callback = finished_callback.bind(this);
|
|
|
|
|
|
|
|
return this.doPreload(2, this.updateProgress);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return ResourceManager;
|
|
|
|
return ResourceManager;
|
|
|
@ -1590,6 +1598,7 @@ Scene = (function() {
|
|
|
|
this.removeTargetSurface = __bind(this.removeTargetSurface, this);
|
|
|
|
this.removeTargetSurface = __bind(this.removeTargetSurface, this);
|
|
|
|
this.handleClick = __bind(this.handleClick, this);
|
|
|
|
this.handleClick = __bind(this.handleClick, this);
|
|
|
|
this.addTargetSurface = __bind(this.addTargetSurface, this);
|
|
|
|
this.addTargetSurface = __bind(this.addTargetSurface, this);
|
|
|
|
|
|
|
|
this.callEvent = __bind(this.callEvent, this);
|
|
|
|
this.reset = __bind(this.reset, this);
|
|
|
|
this.reset = __bind(this.reset, this);
|
|
|
|
this.reset();
|
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|