fixes #147, fixes #136, is related to but doesnt entirely complete #144

This commit is contained in:
logsol 2016-08-28 22:40:25 +02:00
parent 502cf72a7e
commit c87997c774
13 changed files with 134 additions and 27 deletions

View file

@ -9,7 +9,7 @@ function (PIXI, Nc, Settings, ColorConverter) {
"use strict";
function GameStats(gameContainer) {
function GameStats(view) {
this.style = {
borderWidth: 3,
@ -27,7 +27,7 @@ function (PIXI, Nc, Settings, ColorConverter) {
fontSize: 12
};
this.gameContainer = gameContainer;
this.view = view;
this.container = new PIXI.DisplayObjectContainer();
@ -77,11 +77,12 @@ function (PIXI, Nc, Settings, ColorConverter) {
this.redraw();
// show stats with filters
this.container.visible = true;
this.gameContainer.filters = this.filters;
this.view.addFilters(this.filters);
this.filters.forEach(function(filter) { filter.dirty = true; });
} else {
this.container.visible = false;
this.gameContainer.filters = null;
this.view.removeFilters(this.filters);
}
}

View file

@ -174,6 +174,11 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter, Nc) {
Layer.prototype.addFilter = function(mesh, filterName, options) {
// use game container if mesh null
if(mesh === null) {
}
if (!this.getAvailableMeshFilters().hasOwnProperty(filterName)) {
throw new Exception('Filter ' + filterName + ' is not available');
}
@ -228,6 +233,8 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter, Nc) {
return;
}
// FIXME this should throw an error i think since "options" is not defined here
// maybe we never actually call this method?
var MeshFilter = this.getAvailableMeshFilters()[options.filter];
filters = filters.filter(function(filter){

View file

@ -82,7 +82,7 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
this.initPointerLockView();
// Tab Overlay (not using layer manager, cause of filters)
this.gameStats = new GameStats(this.container);
this.gameStats = new GameStats(this);
this.stage.addChild(this.gameStats.getInfoContainer());
this.ghostLayer = new Ghost();
@ -143,7 +143,8 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
if (!Settings.ENABLE_POINTER_LOCK_FILTER) return;
if(isLocked) {
this.container.filters = null;
this.removeFilters(this.pointerLockFilters);
this.clickToEnable.visible = false;
this.onZoomReset();
} else {
@ -159,7 +160,7 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
strokeThickness: 6 * this.currentZoom
});
this.container.filters = this.pointerLockFilters;
this.addFilters(this.pointerLockFilters);
this.pointerLockFilters.forEach(function(filter) { filter.dirty = true; });
this.clickToEnable.position = new PIXI.Point(Settings.STAGE_WIDTH / 2 - this.clickToEnable.width / 2, Settings.STAGE_HEIGHT / 2 - this.clickToEnable.height / 2)
@ -170,6 +171,46 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
}
};
PixiView.prototype.removeFilters = function(filters) {
if(this.container && this.container.filters && this.container.filters.length) {
for (var i = this.container.filters.length - 1; i >= 0; i--) {
for (var j = filters.length - 1; j >= 0; j--) {
if (filters[j] === this.container.filters[i]) {
this.container.filters.splice(i, 1);
}
}
}
// weird bug, filters.length cant be 0, must be set to null
if(this.container.filters.length < 1) {
this.container.filters = null;
}
}
};
PixiView.prototype.addFilters = function(filters) {
if (filters.length < 1) return;
if (!this.container) {
return;
}
if (!this.container.filters) {
/*
* slice does a copy, which is important here -
* otherwise this.pointerLockFilters will be manipulated too on remove.
*/
this.container.filters = filters.slice();
return;
}
for (var i = 0; i < filters.length; i++) {
this.container.filters.push(filters[i]);
}
};
PixiView.prototype.calculateCenterPosition = function() {
var target = this.me.getHeadPosition();