From ae21ba05a6d1d878ff35deb20fc22cfda187e400 Mon Sep 17 00:00:00 2001 From: cha0s Date: Wed, 5 Jun 2019 21:19:42 -0500 Subject: [PATCH] refactor: don't early out client/server --- common/traits/tool.trait.js | 105 ++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/common/traits/tool.trait.js b/common/traits/tool.trait.js index 532bdd7..962c1d8 100644 --- a/common/traits/tool.trait.js +++ b/common/traits/tool.trait.js @@ -113,21 +113,20 @@ export class Tool extends decorate(Trait) { onWielderActiveSlotIndexChanged() { this.calculateTargets(); - if (AVOCADO_SERVER) { - return; - } - const wielder = this.entity.wielder; - if (!wielder) { - return; - } - if (!wielder.is('visible')) { - return; - } - if (this.entity === wielder.itemInActiveSlot()) { - wielder.container.addChild(this.guidePrimitives); - } - else { - wielder.container.removeChild(this.guidePrimitives); + if (AVOCADO_CLIENT) { + const wielder = this.entity.wielder; + if (!wielder) { + return; + } + if (!wielder.is('visible')) { + return; + } + if (this.entity === wielder.itemInActiveSlot()) { + wielder.container.addChild(this.guidePrimitives); + } + else { + wielder.container.removeChild(this.guidePrimitives); + } } } @@ -142,50 +141,48 @@ export class Tool extends decorate(Trait) { } renderPrimitives() { - if (AVOCADO_SERVER) { - return; - } - this.guidePrimitives.clear(); - const wielder = this.entity.wielder; - if (!wielder) { - return; - } - if (!wielder.is('layered')) { - return; - } - const layer = wielder.layer; - if (!layer) { - return; - } - const tile = Vector.floor(wielder.tile); - const tileset = layer.tileset; - if (!tileset) { - return; - } - const tileSize = tileset.tileSize; - for (let i = 0; i < this.targets.length; ++i) { - const target = this.targets[i]; - const relativeTarget = Vector.sub(target, tile); - const scaledRelativeTarget = Vector.mul(relativeTarget, tileSize); - this.guidePrimitives.drawRectangle( - Rectangle.compose(scaledRelativeTarget, tileSize), - Primitives.lineStyle(new Color(255, 255, 255), 1), - ); + if (AVOCADO_CLIENT) { + this.guidePrimitives.clear(); + const wielder = this.entity.wielder; + if (!wielder) { + return; + } + if (!wielder.is('layered')) { + return; + } + const layer = wielder.layer; + if (!layer) { + return; + } + const tile = Vector.floor(wielder.tile); + const tileset = layer.tileset; + if (!tileset) { + return; + } + const tileSize = tileset.tileSize; + for (let i = 0; i < this.targets.length; ++i) { + const target = this.targets[i]; + const relativeTarget = Vector.sub(target, tile); + const scaledRelativeTarget = Vector.mul(relativeTarget, tileSize); + this.guidePrimitives.drawRectangle( + Rectangle.compose(scaledRelativeTarget, tileSize), + Primitives.lineStyle(new Color(255, 255, 255), 1), + ); + } } } repositionPrimitives() { - if (AVOCADO_SERVER) { - return; + if (AVOCADO_CLIENT) { + const wielder = this.entity.wielder; + if (!wielder) { + return; + } + if (!wielder.is('layered')) { + return; + } + this.guidePrimitives.position = Vector.scale(wielder.tileOffset, -1); } - const wielder = this.entity.wielder; - if (!wielder) { - return; - } - if (!wielder.is('layered')) { - return; - } - this.guidePrimitives.position = Vector.scale(wielder.tileOffset, -1); } listeners() {