non working layers

This commit is contained in:
Jeena 2014-08-30 16:27:05 +02:00
parent 57135f3acc
commit 222fd09f3f
7 changed files with 58 additions and 30 deletions

View file

@ -3,12 +3,14 @@ define([
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Exception",
"Lib/Utilities/ColorConverter"
"Lib/Utilities/ColorConverter",
"Game/Client/View/Abstract/Layer",
],
function (Parent, Settings, Nc, Exception, ColorConverter) {
function (Parent, Settings, Nc, Exception, ColorConverter, Layer) {
function Doll(physicsEngine, uid, player) {
function Doll(physicsEngine, uid, player) {
this.layerId = Layer.ID.SPAWN;
this.animationDef = {
"stand": [1,1],
"walk": [2,28],
@ -46,11 +48,13 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
if(this.animatedMeshes[this.actionState]) {
Nc.trigger(
Nc.ns.client.view.mesh.update,
this.layerId,
this.animatedMeshesContainer.withArms[this.actionState],
{ visible: false }
);
Nc.trigger(
Nc.ns.client.view.mesh.update,
this.layerId,
this.animatedMeshesContainer.withoutArms[this.actionState],
{ visible: false }
);
@ -60,6 +64,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
Nc.trigger(
Nc.ns.client.view.mesh.update,
this.layerId,
this.animatedMeshes[this.actionState],
{
visible: true,
@ -73,7 +78,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
var self = this;
var setShirtColor = function (mesh) {
Nc.trigger(Nc.ns.client.view.mesh.addFilter, mesh, 'colorRangeReplace', {
Nc.trigger(Nc.ns.client.view.mesh.addFilter, self.layerId, mesh, 'colorRangeReplace', {
minColor: 0x3b4a31,
maxColor: 0x657f54,
newColor: self.primaryColor,
@ -112,12 +117,12 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
var callback = function(mesh) {
self.animatedMeshesContainer[arm][key] = mesh;
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh);
setShirtColor(mesh);
};
Nc.trigger(Nc.ns.client.view.animatedMesh.create, texturePaths, callback, {
Nc.trigger(Nc.ns.client.view.animatedMesh.create, this.layerId, texturePaths, callback, {
visible: false,
pivot: {
x: 35/2 * 4,
@ -135,9 +140,9 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
var texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/head.png";
var callback = function (mesh) {
self.headMesh = mesh;
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh);
}
Nc.trigger(Nc.ns.client.view.mesh.create, texturePath, callback, {
Nc.trigger(Nc.ns.client.view.mesh.create, this.layerId, texturePath, callback, {
pivot: {
x: 5,
y: 12
@ -151,11 +156,10 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/holdingArm.png";
var callback = function (mesh) {
self.holdingArmMesh = mesh;
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh);
setShirtColor(mesh);
}
Nc.trigger(Nc.ns.client.view.mesh.create, texturePath, callback, {
Nc.trigger(Nc.ns.client.view.mesh.create, this.layerId, texturePath, callback, {
visible: false,
pivot: {
x: 35/2 * 4,
@ -175,6 +179,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
if(oldLookDirection != this.lookDirection) {
for(var key in this.animatedMeshes) {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.animatedMeshes[key],
{
xScale: this.lookDirection
@ -183,6 +188,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
}
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.holdingArmMesh,
{
xScale: this.lookDirection
@ -193,6 +199,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
var angle = Math.atan2(this.lookAtXY.x, this.lookAtXY.y) / 2 - 0.7855 * this.lookDirection; // 0.7855 = 45°
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.headMesh,
{
xScale: this.lookDirection,
@ -205,22 +212,22 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
Parent.prototype.grab.call(this, item);
this.animatedMeshes = this.animatedMeshesContainer.withoutArms;
this.setActionState(this.actionState, true);
Nc.trigger(Nc.ns.client.view.mesh.update, this.holdingArmMesh, { visible: true });
Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: true });
};
Doll.prototype.throw = function(item, x, y) {
Parent.prototype.throw.call(this, item, x, y);
this.animatedMeshes = this.animatedMeshesContainer.withArms;
this.setActionState(this.actionState, true);
Nc.trigger(Nc.ns.client.view.mesh.update, this.holdingArmMesh, { visible: false });
Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: false });
};
Doll.prototype.destroy = function () {
for (var key in this.animatedMeshes) {
Nc.trigger(Nc.ns.client.view.mesh.remove, this.animatedMeshes[key]);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.animatedMeshes[key]);
}
Nc.trigger(Nc.ns.client.view.mesh.remove, this.headMesh);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.headMesh);
Parent.prototype.destroy.call(this);
}
@ -228,6 +235,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
Doll.prototype.render = function() {
if(this.actionState) {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.animatedMeshes[this.actionState],
{
x: this.body.GetPosition().x * Settings.RATIO,
@ -237,6 +245,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
);
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.headMesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
@ -245,6 +254,7 @@ function (Parent, Settings, Nc, Exception, ColorConverter) {
)
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.holdingArmMesh,
{
x: this.body.GetPosition().x * Settings.RATIO,

View file

@ -1,13 +1,15 @@
define([
"Game/Core/GameObjects/Item",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
"Lib/Utilities/NotificationCenter",
"Game/Client/View/Abstract/Layer"
],
function (Parent, Settings, Nc) {
function (Parent, Settings, Nc, Layer) {
function Item(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
this.layerId = Layer.ID.ITEM;
}
Item.prototype = Object.create(Parent.prototype);
@ -22,10 +24,11 @@ function (Parent, Settings, Nc) {
var callback = function(mesh) {
self.mesh = mesh;
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh);
}
Nc.trigger(Nc.ns.client.view.mesh.create,
this.layerId,
texturePath,
callback,
{
@ -40,13 +43,14 @@ function (Parent, Settings, Nc) {
};
Item.prototype.destroy = function() {
Nc.trigger(Nc.ns.client.view.mesh.remove, this.mesh);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.mesh);
Parent.prototype.destroy.call(this);
};
Item.prototype.render = function() {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
@ -63,6 +67,7 @@ function (Parent, Settings, Nc) {
if(oldFlipDirection != direction) {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.mesh,
{
xScale: direction

View file

@ -2,12 +2,14 @@ define([
"Game/Core/GameObjects/Items/RagDoll",
"Game/Core/GameObjects/Item",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
"Lib/Utilities/NotificationCenter",
"Game/Client/View/Abstract/Layer"
],
function (Parent, CoreItem, Settings, Nc) {
function (Parent, CoreItem, Settings, Nc, Layer) {
function RagDoll(physicsEngine, uid, options) {
this.layerId = Layer.ID.SPAWN;
this.limbMeshes = {};
this.baseMeshName = "chest";
this.characterName = "Chuck";
@ -36,10 +38,11 @@ function (Parent, CoreItem, Settings, Nc) {
self.limbMeshes[name] = mesh;
}
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh);
}
Nc.trigger(Nc.ns.client.view.mesh.create,
this.layerId,
texturePath + name + ".png",
callback,
{
@ -60,6 +63,7 @@ function (Parent, CoreItem, Settings, Nc) {
for(var name in this.limbMeshes) {
if(this.limbs[name]) {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.limbMeshes[name],
{
x: this.limbs[name].GetPosition().x * Settings.RATIO,
@ -80,6 +84,7 @@ function (Parent, CoreItem, Settings, Nc) {
if(oldFlipDirection != direction) {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.mesh,
{
xScale: direction
@ -88,6 +93,7 @@ function (Parent, CoreItem, Settings, Nc) {
for (var name in this.limbMeshes) {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.limbMeshes[name],
{
xScale: direction
@ -100,7 +106,7 @@ function (Parent, CoreItem, Settings, Nc) {
RagDoll.prototype.destroy = function() {
for (var name in this.limbMeshes) {
Nc.trigger(Nc.ns.client.view.mesh.remove, this.limbMeshes[name]);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.limbMeshes[name]);
};
Parent.prototype.destroy.call(this);

View file

@ -1,13 +1,15 @@
define([
"Game/Core/GameObjects/Tile",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
"Lib/Utilities/NotificationCenter",
"Game/Client/View/Abstract/Layer"
],
function (Parent, Settings, Nc) {
function (Parent, Settings, Nc, Layer) {
function Tile(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
this.layerId = Layer.ID.TILE;
}
Tile.prototype = Object.create(Parent.prototype);
@ -27,10 +29,11 @@ function (Parent, Settings, Nc) {
var callback = function(mesh) {
self.mesh = mesh;
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
Nc.trigger(Nc.ns.client.view.mesh.add, self.layerId, mesh);
}
Nc.trigger(Nc.ns.client.view.mesh.create,
this.layerId,
texturePath,
callback,
{
@ -45,13 +48,14 @@ function (Parent, Settings, Nc) {
};
Tile.prototype.destroy = function() {
Nc.trigger(Nc.ns.client.view.mesh.remove, this.mesh);
Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.mesh);
Parent.prototype.destroy.call(this);
};
Tile.prototype.render = function() {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,

View file

@ -7,6 +7,7 @@ function (Parent, Settings) {
function TiledLevel(uid, engine, gameObjects) {
Parent.call(this, uid, engine, gameObjects);
this.layerId = "background";
}
TiledLevel.prototype = Object.create(Parent.prototype);
@ -63,6 +64,7 @@ function (Parent, Settings) {
TiledLevel.prototype.addBackground = function(options) {
var texturePath = Settings.GRAPHICS_PATH + options.image;
/*
var callback = function (mesh) {
Nc.trigger(Nc.ns.client.view.mesh.add, mesh, 0); // FIXME: add at z layer -1 or so
}
@ -72,6 +74,7 @@ function (Parent, Settings) {
x: -(4000 - Settings.STAGE_WIDTH) / 2,
y: -(2959 + Settings.STAGE_HEIGHT + 700) / 2
});
*/
}
TiledLevel.prototype.getLayer = function(levelData, name) {

View file

@ -44,7 +44,6 @@ function (Nc, Exception, Layer) {
}
var layer = new Layer(id, parallaxSpeed);
var layerIndex = behind ? referenceIndex -1 : referenceIndex;
this.layers.splice(layerIndex, 0, layer);
@ -58,7 +57,7 @@ function (Nc, Exception, Layer) {
return layer;
}
};
console.warn('No such layer: ' + id);
throw new Exception('No such layer: ' + id);
};
LayerManager.prototype.delegate = function(methodName, layerId) {

View file

@ -17,7 +17,8 @@ function() {
this.message = message.join(" ");
Error.call(this, this.message);
var e = Error.call(this, this.message);
console.log(e.stack)
}
Exception.prototype = Object.create(Error.prototype);