From 1af386d9f5380d1bc9ce15c965e6f2532fd3e3c8 Mon Sep 17 00:00:00 2001 From: Asraelite Date: Mon, 28 Mar 2016 15:10:20 +0100 Subject: [PATCH] add setname client command --- public/static/js/wingbase/command.js | 14 ++++++++++++++ public/static/js/wingbase/gui/chat.js | 9 ++++++--- public/static/js/wingbase/main.js | 5 +++++ public/static/js/wingbase/render/effect.js | 2 +- public/static/js/wingbase/world/ship.js | 1 + server/game/net/connection.js | 2 +- server/game/room/world/body/ship.js | 4 ++-- server/game/room/world/body/turret/blaster.js | 2 ++ server/game/room/world/body/turret/fixture.js | 18 +++++++++++++++--- server/game/room/world/body/turret/mount.js | 4 +++- 10 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 public/static/js/wingbase/command.js diff --git a/public/static/js/wingbase/command.js b/public/static/js/wingbase/command.js new file mode 100644 index 0000000..8ca582c --- /dev/null +++ b/public/static/js/wingbase/command.js @@ -0,0 +1,14 @@ +class CommandProcessor { + constructor() { + + } + + run(command, arg) { + if (command == 'setname') this.setName(arg); + } + + setName(name) { + game.net.send('chat', { msg: ' is now known as ' + name }); + game.net.send('setName', name); + } +} diff --git a/public/static/js/wingbase/gui/chat.js b/public/static/js/wingbase/gui/chat.js index 4229a3b..6be3b81 100644 --- a/public/static/js/wingbase/gui/chat.js +++ b/public/static/js/wingbase/gui/chat.js @@ -14,7 +14,6 @@ GUI.prototype.Chat = class { } addMessage(messageData) { - console.log(messageData); let message = { type: messageData.type, team: messageData.team || 'c', @@ -50,14 +49,18 @@ GUI.prototype.Chat = class { if (game.input.keys.pressed[13]) { let message = this.inputElement.value; this.inputElement.value = ''; - game.net.send('chat', { msg: message }); + if (message[0] == '/') { + let args = message.split(' '); + game.command(args[0].slice(1), args.splice(1).join(' ')); + } else { + game.net.send('chat', { msg: message }); + } } this.typing = false; this.inputElement.blur(); this.inputElement.disabled = true; game.input.locked = false; } else { - console.log(game.input.locked); this.typing = true; this.inputElement.disabled = false; this.inputElement.focus(); diff --git a/public/static/js/wingbase/main.js b/public/static/js/wingbase/main.js index 2f2205b..80794bb 100644 --- a/public/static/js/wingbase/main.js +++ b/public/static/js/wingbase/main.js @@ -20,6 +20,7 @@ class Game { this.pingMode = 'fast'; this.input = new Input(); + this.commandProcessor = new CommandProcessor(); this.gui = new GUI(); this.net = new Net(); this.world = new World(); @@ -29,6 +30,10 @@ class Game { this.state = 'connecting'; } + command(a, b) { + this.commandProcessor.run(a, b); + } + tick() { this.renderer.render(this.state); diff --git a/public/static/js/wingbase/render/effect.js b/public/static/js/wingbase/render/effect.js index b1d68d6..9b8612b 100644 --- a/public/static/js/wingbase/render/effect.js +++ b/public/static/js/wingbase/render/effect.js @@ -77,7 +77,7 @@ class Effect { createExplosion() { let num = this.size * this.size; - let colors = ['#f52', '#ff7']; + let colors = ['#f52', '#ff7', '#fff']; let b = 'sizzle'; this.generateParticles(0, 0, 1, num, colors, [1, 2], b, 50, 3); } diff --git a/public/static/js/wingbase/world/ship.js b/public/static/js/wingbase/world/ship.js index 3600073..a3bc7e2 100644 --- a/public/static/js/wingbase/world/ship.js +++ b/public/static/js/wingbase/world/ship.js @@ -1,5 +1,6 @@ class Ship extends Body { constructor(data) { + console.log(data); super(data); this.player = new Player(data.name, data.team, this); this.team = data.team; diff --git a/server/game/net/connection.js b/server/game/net/connection.js index f36d04d..8b7f831 100644 --- a/server/game/net/connection.js +++ b/server/game/net/connection.js @@ -19,7 +19,7 @@ class Connection { }); socket.on('setName', data => { - this.player.name = data.name.slice(0, 20) || 'Fish'; + this.player.name = ('' + data).slice(0, 20) || 'Fish'; }); socket.on('inputs', data => { diff --git a/server/game/room/world/body/ship.js b/server/game/room/world/body/ship.js index e15fd73..2688dab 100644 --- a/server/game/room/world/body/ship.js +++ b/server/game/room/world/body/ship.js @@ -35,7 +35,7 @@ class Ship extends Body { this.mounts.push(mount); }); - this.turrets = []; + this.turrets = build.turrets || []; this.thrust = { forward: 0, @@ -113,7 +113,7 @@ class Ship extends Body { frame: this.frame, power: this.power, mounts: this.mounts.map(m => m.packFull()), - turrets: this.turrets, + turrets: this.turrets.map(t => t.packFull()), size: this.size, delta: this.packDelta() }; diff --git a/server/game/room/world/body/turret/blaster.js b/server/game/room/world/body/turret/blaster.js index 925daef..7f80302 100644 --- a/server/game/room/world/body/turret/blaster.js +++ b/server/game/room/world/body/turret/blaster.js @@ -6,6 +6,8 @@ const Laser = require('./shot/laser.js'); class Blaster extends Fixture { constructor(hardpoint, data) { super(hardpoint, data); + + console.log(data); } fire() { diff --git a/server/game/room/world/body/turret/fixture.js b/server/game/room/world/body/turret/fixture.js index 5e3f0fa..dc3be5b 100644 --- a/server/game/room/world/body/turret/fixture.js +++ b/server/game/room/world/body/turret/fixture.js @@ -3,8 +3,8 @@ const traits = require('../../traits/turrets.json'); class Fixture { - constructor(hardpoint, data) { - this.hardpoint = hardpoint; + constructor(mount, data) { + this.mount = mount; this.projectiles = new WeakSet(); @@ -12,7 +12,8 @@ class Fixture { this.rof = turretTraits.rateOfFire; - this.traversal = this.hardpoint.traversal || false; + this.traversal = this.mount.traversal || false; + this.fired = false; this._angle = this.traversal ? this.traversal.cw : 0; } @@ -20,6 +21,17 @@ class Fixture { this.projectiles.forEach(p => p.world.removeBody(p)); } + packFull() { + return { + + traversal: this.traversal + } + } + + packDelta() { + return [this.traversal]; + } + get angle() { return this._angle; } diff --git a/server/game/room/world/body/turret/mount.js b/server/game/room/world/body/turret/mount.js index a35b29b..27ebf53 100644 --- a/server/game/room/world/body/turret/mount.js +++ b/server/game/room/world/body/turret/mount.js @@ -8,6 +8,7 @@ class Mount { this.type = data.type || 'turret'; this.fixture = false; + this.size = data.size || 0; this.position = { x: data.pos[0], y: data.pos[1] @@ -26,7 +27,8 @@ class Mount { packFull() { return { - + x: this.position.x, + y: this.position.y } } }