add setname client command

This commit is contained in:
Asraelite 2016-03-28 15:10:20 +01:00
parent 52e1673e3e
commit 1af386d9f5
10 changed files with 50 additions and 11 deletions

View file

@ -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);
}
}

View file

@ -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();

View file

@ -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);

View file

@ -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);
}

View file

@ -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;

View file

@ -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 => {

View file

@ -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()
};

View file

@ -6,6 +6,8 @@ const Laser = require('./shot/laser.js');
class Blaster extends Fixture {
constructor(hardpoint, data) {
super(hardpoint, data);
console.log(data);
}
fire() {

View file

@ -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;
}

View file

@ -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
}
}
}