Browse Source

code cleanup

tags/v0.3.0
BigBadWaffle 5 years ago
parent
commit
3e9f1d058a
2 changed files with 29 additions and 92 deletions
  1. +2
    -25
      src/client/js/components/spellbook.js
  2. +27
    -67
      src/client/js/rendering/renderer.js

+ 2
- 25
src/client/js/components/spellbook.js View File

@@ -119,32 +119,9 @@ define([
events.emit('onSetTarget', this.target, null);
},

build: function (destroy) {
client.request({
cpn: 'player',
method: 'performAction',
data: {
instanceModule: 'customMap',
method: 'customize',
data: {
tile: 189,
direction: this.obj.keyboardMover.direction,
destroy: destroy
}
},
callback: renderer.onGetMapCustomization.bind(renderer)
});
},

onKeyDown: function (key) {
let handler = ({
b: this.build.bind(this),
n: this.build.bind(this, true),
tab: this.tabTarget.bind(this)
})[key];

if (handler) {
handler();
if (key === 'tab') {
this.tabTarget();
return;
} else if (isNaN(key))
return;


+ 27
- 67
src/client/js/rendering/renderer.js View File

@@ -287,44 +287,7 @@ define([
else if (b.layer === 'tiles')
return 1;
return 0;
}, this);
},

onGetMapCustomization: function (msg) {
if (!msg.collide) {
let children = this.layers.tiles.children;
let cLen = children.length;
let x = msg.x * scale;
let y = msg.y * scale;
for (let i = cLen - 1; i >= 0; i--) {
let c = children[i];
let cx = c.x;
if (c.scale.x < 0)
cx -= scale;
if ((cx === x) && (c.y === y)) {
c.parent.removeChild(c);
break;
}
}
}

let tile = new pixi.Sprite(this.getTexture('sprites', msg.tile));

tile.alpha = tileOpacity.map(msg.tile);
tile.position.x = msg.x * scale;
tile.position.y = msg.y * scale;
tile.width = scale;
tile.height = scale;

if (mRandom() < 0.5) {
tile.position.x += scale;
tile.scale.x = -scaleMult;
}

this.layers.tiles.addChild(tile);

physics.collisionMap[msg.x][msg.y] = msg.collide;
physics.graph.grid[msg.x][msg.y] = !msg.collide;
});
},

buildTile: function (c, i, j) {
@@ -339,11 +302,9 @@ define([
tile.width = scale;
tile.height = scale;

if (canFlip) {
if (mRandom() < 0.5) {
tile.position.x += scale;
tile.scale.x = -scaleMult;
}
if (canFlip && mRandom() < 0.5) {
tile.position.x += scale;
tile.scale.x = -scaleMult;
}

return tile;
@@ -358,11 +319,12 @@ define([
let h = this.h = map[0].length;

for (let i = 0; i < w; i++) {
let row = map[i];
for (let j = 0; j < h; j++) {
if (!map[i][j].split)
map[i][j] += '';
if (!row[j].split)
row[j] += '';

map[i][j] = map[i][j].split(',');
row[j] = row[j].split(',');
}
}

@@ -399,7 +361,6 @@ define([
pos.y += 16;

let player = window.player;
if (player) {
let px = player.x;
let py = player.y;
@@ -411,15 +372,14 @@ define([
if (!h.discoverable)
continue;
if (
(
(px < h.x) ||
(px >= h.x + h.width) ||
(py < h.y) ||
(py >= h.y + h.height)
) ||
(!physics.isInPolygon(px, py, h.area))
px < h.x ||
px >= h.x + h.width ||
py < h.y ||
py >= h.y + h.height ||
!physics.isInPolygon(px, py, h.area)
)
continue;

h.discovered = true;
}
}
@@ -443,7 +403,7 @@ define([
let sw = this.width;
let sh = this.height;

return (!((x < sx) || (y < sy) || (x >= sx + sw) || (y >= sy + sh)));
return (!(x < sx || y < sy || x >= sx + sw || y >= sy + sh));
},

isHidden: function (x, y) {
@@ -461,10 +421,10 @@ define([
let h = hiddenRooms[i];

let outsideHider = (
(x < h.x) ||
(x >= h.x + h.width) ||
(y < h.y) ||
(y >= h.y + h.height)
x < h.x ||
x >= h.x + h.width ||
y < h.y ||
y >= h.y + h.height
);

if (outsideHider)
@@ -479,10 +439,10 @@ define([
return false;

outsideHider = (
(px < h.x) ||
(px >= h.x + h.width) ||
(py < h.y) ||
(py >= h.y + h.height)
px < h.x ||
px >= h.x + h.width ||
py < h.y ||
py >= h.y + h.height
);

if (outsideHider) {
@@ -650,7 +610,7 @@ define([
let deltaX = this.moveTo.x - this.pos.x;
let deltaY = this.moveTo.y - this.pos.y;

if ((deltaX !== 0) || (deltaY !== 0)) {
if (deltaX !== 0 || deltaY !== 0) {
let moveSpeed = this.moveSpeed;
let distance = Math.max(Math.abs(deltaX), Math.abs(deltaY));

@@ -669,8 +629,8 @@ define([
deltaX = (deltaX / distance) * moveSpeed;
deltaY = (deltaY / distance) * moveSpeed;

this.pos.x = this.pos.x + (deltaX);
this.pos.y = this.pos.y + (deltaY);
this.pos.x = this.pos.x + deltaX;
this.pos.y = this.pos.y + deltaY;
} else {
this.moveSpeed = 0;
this.moveTo = null;
@@ -681,7 +641,7 @@ define([
stage.y = -~~this.pos.y;

let halfScale = scale / 2;
if ((Math.abs(stage.x - this.lastUpdatePos.x) > halfScale) || (Math.abs(stage.y - this.lastUpdatePos.y) > halfScale))
if (Math.abs(stage.x - this.lastUpdatePos.x) > halfScale || Math.abs(stage.y - this.lastUpdatePos.y) > halfScale)
this.updateSprites();

events.emit('onSceneMove');


Loading…
Cancel
Save