mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
101 lines
No EOL
3.2 KiB
JavaScript
Executable file
101 lines
No EOL
3.2 KiB
JavaScript
Executable file
define([
|
|
"Game/Core/Loader/Level",
|
|
"Game/Config/Settings",
|
|
"Lib/Utilities/NotificationCenter",
|
|
"Lib/Vendor/Pixi",
|
|
"Game/Client/View/Abstract/Layer"
|
|
],
|
|
|
|
function (Parent, Settings, Nc, PIXI, AbstractLayer) {
|
|
|
|
function Level (uid, engine, gameObjects) {
|
|
Parent.call(this, uid, engine, gameObjects);
|
|
}
|
|
|
|
Level.prototype = Object.create(Parent.prototype);
|
|
|
|
Level.prototype.loadLevelDataFromPath = function (path, callback) {
|
|
var self = this;
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.onreadystatechange = function() {
|
|
if(xhr.readyState == 4) {
|
|
if(xhr.status == 200) {
|
|
self.loadAssets(JSON.parse(xhr.responseText), callback);
|
|
} else {
|
|
console.error("Ajax error: " + xhr.status + " " + xhr.statusText)
|
|
}
|
|
}
|
|
}
|
|
xhr.open("GET", path, true);
|
|
xhr.send(null);
|
|
}
|
|
|
|
Level.prototype.loadAssets = function(levelData, callback) {
|
|
|
|
var paths = this.getAssetPaths(levelData);
|
|
|
|
var count = 0;
|
|
var numPaths = paths.length;
|
|
var loader = new PIXI.AssetLoader(paths);
|
|
loader.onComplete = function() { callback(levelData); };
|
|
loader.onProgress = function() {
|
|
var progress = parseInt(100 / numPaths * ++count, 10) + 1;
|
|
Nc.trigger(Nc.ns.client.view.preloadBar.update, progress);
|
|
}
|
|
loader.load();
|
|
};
|
|
|
|
Level.prototype.getAssetPaths = function(levelData) {
|
|
|
|
var paths = [];
|
|
|
|
// Get chuck
|
|
var padF = function(n) {
|
|
if(n<10) return "00" + n;
|
|
if(n<100) return "0" + n;
|
|
return n;
|
|
}
|
|
|
|
var characterNames = ["Chuck"];
|
|
var animationSets = ["WithArms", "WithoutArms"];
|
|
var addition = "";
|
|
for (var i = 0; i < characterNames.length; i++) {
|
|
var characterName = characterNames[i];
|
|
for (var j = 1; j <= 126; j++) {
|
|
for (var k = 0; k < animationSets.length; k++) {
|
|
var animationSet = animationSets[k];
|
|
paths.push(
|
|
Settings.GRAPHICS_PATH
|
|
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
|
+ characterName
|
|
+ "/Animation/"
|
|
+ animationSet
|
|
+ "/ChuckAnimations0"
|
|
+ padF(j)
|
|
+ ".png"
|
|
);
|
|
};
|
|
};
|
|
};
|
|
|
|
paths.push(
|
|
Settings.GRAPHICS_PATH
|
|
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
|
+ characterName
|
|
+ "/head.png"
|
|
);
|
|
|
|
return paths;
|
|
};
|
|
|
|
Level.prototype.setupLayer = function(options, behind, referenceId) {
|
|
Parent.prototype.setupLayer.call(this, options, behind, referenceId);
|
|
var parallaxSpeed = 0.0;
|
|
if (options.properties && options.properties.parallaxSpeed) {
|
|
parallaxSpeed = parseFloat(options.properties.parallaxSpeed);
|
|
}
|
|
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, parallaxSpeed, behind, referenceId);
|
|
};
|
|
|
|
return Level;
|
|
}); |