Ver código fonte

done with hider code?

tags/v0.3.0
big bad waffle 6 anos atrás
pai
commit
a4f83121f2
7 arquivos alterados com 143 adições e 141 exclusões
  1. +8
    -8
      src/client/js/components/explosion.js
  2. +1
    -0
      src/client/js/components/light.js
  3. +6
    -5
      src/client/js/components/particles.js
  4. +8
    -13
      src/client/js/objects/objBase.js
  5. +37
    -4
      src/client/js/objects/objects.js
  6. +16
    -10
      src/client/js/rendering/particles.js
  7. +67
    -101
      src/client/js/rendering/renderer.js

+ 8
- 8
src/client/js/components/explosion.js Ver arquivo

@@ -1,6 +1,6 @@
define([
'js/rendering/effects'
], function(
], function (
effects
) {
return {
@@ -11,7 +11,7 @@ define([
blueprint: null,
particles: null,

init: function(blueprint) {
init: function (blueprint) {
this.blueprint = {
new: true,
blueprint: $.extend(true, {
@@ -39,14 +39,14 @@ define([
max: 18
}
},
particlesPerWave: 14,
particleSpacing: 0,
particleSpacing: 0,
lifetime: {
min: 1,
max: 3
},
randomColor: true,
randomColor: true,
randomScale: true,
randomSpeed: true,
frequency: 1
@@ -65,14 +65,14 @@ define([
}
}
})
};
};
},

explode: function(blueprint) {
explode: function (blueprint) {
this.particles = this.obj.addComponent('particles', this.blueprint);

this.particles.emitter.update(0.2);
this.particles.emitter.emit = false;
}
};
});
});

+ 1
- 0
src/client/js/components/light.js Ver arquivo

@@ -33,6 +33,7 @@ define([
var maxAlpha = (1 + ((halfRange * 2) - (Math.abs(halfRange - i) + Math.abs(halfRange - j)))) * 0.1;

this.emitters[n] = renderer.buildEmitter({
obj: this.obj,
pos: {
x: ((x + i - halfRange) * scale) + (scale / 2),
y: ((y + j - halfRange) * scale) + (scale / 2)


+ 6
- 5
src/client/js/components/particles.js Ver arquivo

@@ -1,6 +1,6 @@
define([
'js/rendering/renderer'
], function(
], function (
renderer
) {
var scale = 40;
@@ -9,18 +9,19 @@ define([
type: 'particles',
emitter: null,

init: function(blueprint) {
init: function (blueprint) {
this.blueprint = this.blueprint || {};
this.blueprint.pos = {
x: (this.obj.x * scale) + (scale / 2),
y: (this.obj.y * scale) + (scale / 2)
};
this.ttl = blueprint.ttl;
this.blueprint.obj = this.obj;

this.emitter = renderer.buildEmitter(this.blueprint);
},

update: function() {
update: function () {
if (this.ttl != null) {
this.ttl--;
if (this.ttl <= 0) {
@@ -39,8 +40,8 @@ define([
this.emitter.spawnPos.y = (this.obj.y * scale) + (scale / 2);
},

destroy: function() {
destroy: function () {
renderer.destroyEmitter(this.emitter);
}
};
});
});

+ 8
- 13
src/client/js/objects/objBase.js Ver arquivo

@@ -1,11 +1,13 @@
define([
'js/components/components',
'js/rendering/renderer',
'js/system/events'
'js/system/events',
'js/config'
], function (
components,
renderer,
events
events,
config
) {
var scale = 40;
var scaleMult = 5;
@@ -123,25 +125,18 @@ define([

if (this.stats)
this.stats.updateHpSprite();

this.setVisible(renderer.sprites[this.x][this.y].length > 0);
},

setVisible: function (visible) {
this.sprite.visible = (renderer.sprites[this.x][this.y].length > 0);

['nameSprite', 'chatSprite'].forEach(function (s, i) {
var sprite = this[s];
if (!sprite)
return;

sprite.visible = visible;
}, this);
this.sprite.visible = visible;

this.components.forEach(function (c) {
if (c.setVisible)
c.setVisible(visible);
});

if (this.nameSprite)
this.nameSprite.visible = ((visible) && (config.showNames));
},

destroy: function () {


+ 37
- 4
src/client/js/objects/objects.js Ver arquivo

@@ -2,12 +2,14 @@ define([
'js/objects/objBase',
'js/system/events',
'js/rendering/renderer',
'js/sound/sound'
'js/sound/sound',
'js/config'
], function (
objBase,
events,
renderer,
sound
sound,
config
) {
var scale = 40;

@@ -22,10 +24,12 @@ define([
events.on('onGetObject', this.onGetObject.bind(this));
events.on('onRezone', this.onRezone.bind(this));
events.on('onChangeHoverTile', this.getLocation.bind(this));
events.on('onTilesVisible', this.onTilesVisible.bind(this));

//Get saved value for showNames, or use the value set above
var showNames = window.localStorage.getItem('iwd_opt_shownames');
this.showNames = showNames ? (showNames == 'true') : this.showNames;
config.showNames = this.showNames;
},

getLocation: function (x, y) {
@@ -127,6 +131,7 @@ define([
else
this.updateObject(exists, obj);
},

buildObject: function (template) {
var obj = $.extend(true, {}, objBase);

@@ -166,7 +171,8 @@ define([

if (obj.sheetName) {
obj.sprite = renderer.buildObject(obj);
obj.setVisible(renderer.sprites[obj.x][obj.y].length > 0);
var isVisible = ((obj.self) || (renderer.sprites[obj.x][obj.y].length > 0));
obj.setVisible(isVisible, this.showNames);
if (template.hidden) {
obj.sprite.visible = false;
if (obj.nameSprite)
@@ -199,11 +205,13 @@ define([
x: (obj.x * scale) + (scale / 2),
y: (obj.y * scale) + scale
});
obj.nameSprite.visible = this.showNames;
var isVisible = ((obj.self) || (renderer.sprites[obj.x][obj.y].length > 0));
obj.nameSprite.visible = ((this.showNames) && (isVisible));
}

return obj;
},

updateObject: function (obj, template) {
var components = template.components || [];

@@ -300,8 +308,14 @@ define([
obj.nameSprite.visible = this.showNames;
}

if (obj.sprite) {
var isVisible = ((!!obj.player) || (renderer.sprites[obj.x][obj.y].length > 0));
obj.setVisible(isVisible);
}

obj.setSpritePosition();
},

update: function () {
var objects = this.objects;
var len = objects.length;
@@ -329,6 +343,7 @@ define([

//Set new value in localStorage for showNames
window.localStorage.setItem('iwd_opt_shownames', this.showNames);
config.showNames = this.showNames;

var showNames = this.showNames;

@@ -343,6 +358,24 @@ define([
ns.visible = showNames;
}
}
},

onTilesVisible: function (tiles, visible) {
var objects = this.objects;
var oLen = objects.length;
for (var i = 0; i < oLen; i++) {
var o = objects[i];
if (!o.sprite)
continue;

var onPos = tiles.some(function (t) {
return ((t.x == o.x) && (t.y == o.y));
});
if (!onPos)
continue;

o.setVisible(visible);
}
}
};
});

+ 16
- 10
src/client/js/rendering/particles.js Ver arquivo

@@ -2,7 +2,7 @@ define([
'particles',
'js/rendering/particleDefaults',
'js/rendering/shaders/outline'
], function(
], function (
pixiParticles,
particleDefaults,
shaderOutline
@@ -15,17 +15,20 @@ define([

lastTick: null,

init: function(options) {
init: function (options) {
this.r = options.r;
this.renderer = options.renderer;
this.stage = options.stage;
this.lastTick = Date.now();
},

buildEmitter: function(config) {
buildEmitter: function (config) {
var obj = config.obj;
delete config.obj;
var options = $.extend(true, {}, particleDefaults, config);

var emitter = new PIXI.particles.Emitter(this.r.layers.particles, ['images/particles.png'], options);
emitter.obj = obj;
emitter.emit = true;

this.emitters.push(emitter);
@@ -33,11 +36,11 @@ define([
return emitter;
},

destroyEmitter: function(emitter) {
destroyEmitter: function (emitter) {
emitter.emit = false;
},

update: function() {
update: function () {
var renderer = this.r;
var now = Date.now();

@@ -47,11 +50,14 @@ define([
var e = emitters[i];

var visible = null;
var destroy = !e.emit;
var destroy = (
(!e.emit) &&
(e.obj.destroyed)
);
if (destroy) {
if (e.particleCount > 0) {
visible = renderer.isVisible(e.spawnPos.x, e.spawnPos.y);
if (visible)
if (visible)
destroy = false;
}
}
@@ -64,7 +70,7 @@ define([
i--;
eLen--;
continue;
}
}

if (visible === null)
visible = renderer.isVisible(e.spawnPos.x, e.spawnPos.y);
@@ -72,7 +78,7 @@ define([
continue;

var r = e.update((now - this.lastTick) * 0.001);
r.forEach(function(rr) {
r.forEach(function (rr) {
if (e.blendMode == 'overlay')
rr.pluginName = 'picture';
}, this);
@@ -81,4 +87,4 @@ define([
this.lastTick = now;
}
};
});
});

+ 67
- 101
src/client/js/rendering/renderer.js Ver arquivo

@@ -393,7 +393,7 @@ define([
this.stage.filters = [new PIXI.filters.VoidFilter()];
this.stage.filterArea = new PIXI.Rectangle(0, 0, w * scale, h * scale);

this.buildHiddenRooms(msg);
this.hiddenRooms = msg.hiddenRooms;

this.sprites = _.get2dArray(w, h, 'array');

@@ -416,108 +416,36 @@ define([
}, this);
},

buildHiddenRooms: function (msg) {
var hiddenWalls = msg.hiddenWalls;
var hiddenTiles = msg.hiddenTiles;

this.hiddenRooms = msg.hiddenRooms;
return;
this.hiddenRooms.forEach(function (h) {
h.container = new pixi.Container();
this.layers.hiders.addChild(h.container);
for (var i = h.x; i < h.x + h.width; i++) {
for (var j = h.y; j < h.y + h.height; j++) {
if (!physics.isInPolygon(i, j, h.area))
continue;
setPosition: function (pos, instant) {
pos.x += 16;
pos.y += 16;

this.buildRectangle({
x: i * scale,
y: j * scale,
w: scale,
h: scale,
color: 0x2d2136,
alpha: (h.fog == 1) ? 0.8 : 1,
parent: h.container
});

[hiddenTiles, hiddenWalls].forEach(function (k) {
var cell = k[i][j];
if (cell == 0)
return;

var tile = this.buildTile(cell - 1, i, j);
tile.width = scale;
tile.height = scale;
h.container.addChild(tile);
}, this);
}
}
}, this);
},
hideHiders: function () {
return;
var player = window.player;
if (!player)
return;

var x = player.x;
var y = player.y;

var hiddenRooms = this.hiddenRooms;
var hLen = hiddenRooms.length;
for (var i = 0; i < hLen; i++) {
var hi = hiddenRooms[i];
var visible = (
(x < hi.x) ||
(x >= hi.x + hi.width) ||
(y < hi.y) ||
(y >= hi.y + hi.height)
);

if (!visible)
visible = !physics.isInPolygon(x, y, hi.area);
if (player) {
var px = player.x;
var py = player.y;

var hiddenRooms = this.hiddenRooms;
var hLen = hiddenRooms.length;
for (var i = 0; i < hLen; i++) {
var h = hiddenRooms[i];
if (!h.discoverable)
continue;

if (visible) {
for (var j = 0; j < i; j++) {
var hj = hiddenRooms[j];
if (hj.visible)
continue;
if (
(
(px < h.x) ||
(px >= h.x + h.width) ||
(py < h.y) ||
(py >= h.y + h.height)
) ||
(!physics.isInPolygon(px, py, h.area))
)
continue;

if (
(!(
(hi.x + hi.width <= hj.x) ||
(hi.x >= hj.x + hj.width) ||
(hi.y + hi.height <= hj.y) ||
(hi.y >= hj.y + hj.height)
)) &&
(
(physics.isInPolygon(x, y, hj.area)) ||
(physics.isInPolygon(x, y, hi.area))
)
) {
visible = false;
console.log('f', i, visible);
break;
}
}
h.discovered = true;
}

console.log(i, visible);

if ((!visible) && (hi.discoverable))
this.layers.hiders.removeChild(hi.container);
else
hi.container.visible = visible;

hi.visible = visible;
}
},

setPosition: function (pos, instant) {
pos.x += 16;
pos.y += 16;

this.hideHiders();

if (instant) {
this.moveTo = null;
@@ -570,6 +498,9 @@ define([
if (!inHider)
continue;

if (h.discovered)
return false;

outsideHider = (
(px < h.x) ||
(px >= h.x + h.width) ||
@@ -626,6 +557,9 @@ define([

var isHidden = this.isHidden.bind(this);

var newVisible = [];
var newHidden = [];

for (var i = lowX; i < highX; i++) {
var mapRow = map[i];
var spriteRow = sprites[i];
@@ -633,12 +567,40 @@ define([
cell = mapRow[j];
if (!cell)
continue;
var cLen = cell.length;
if (!cLen)
return;

var rendered = spriteRow[j];
if ((rendered.length > 0) || (isHidden(i, j)))
var isHidden = this.isHidden(i, j);
if (rendered.length > 0) {
if (!isHidden)
continue;
else {
newHidden.push({
x: i,
y: j
});

var rLen = rendered.length;
for (var k = 0; k < rLen; k++) {
var sprite = rendered[k];
sprite.visible = false;
spritePool.store(sprite);
}
spriteRow[j] = [];

continue;
}
} else if (isHidden)
continue;

for (var k = 0; k < cell.length; k++) {
newVisible.push({
x: i,
y: j
});

for (var k = 0; k < cLen; k++) {
var c = cell[k];
if (c == 0)
continue;
@@ -696,7 +658,9 @@ define([
}
}

//Reorder
events.emit('onTilesVisible', newVisible, true);
events.emit('onTilesVisible', newHidden, false);

if (addedSprite) {
container.children.sort(function (a, b) {
return (a.z - b.z);
@@ -876,7 +840,9 @@ define([
},

buildEmitter: function (config) {
return particles.buildEmitter(config);
var emitter = particles.buildEmitter(config);

return emitter;
},

destroyEmitter: function (emitter) {


Carregando…
Cancelar
Salvar