add setname client command
This commit is contained in:
parent
52e1673e3e
commit
1af386d9f5
10 changed files with 50 additions and 11 deletions
14
public/static/js/wingbase/command.js
Normal file
14
public/static/js/wingbase/command.js
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,6 @@ GUI.prototype.Chat = class {
|
||||||
}
|
}
|
||||||
|
|
||||||
addMessage(messageData) {
|
addMessage(messageData) {
|
||||||
console.log(messageData);
|
|
||||||
let message = {
|
let message = {
|
||||||
type: messageData.type,
|
type: messageData.type,
|
||||||
team: messageData.team || 'c',
|
team: messageData.team || 'c',
|
||||||
|
@ -50,14 +49,18 @@ GUI.prototype.Chat = class {
|
||||||
if (game.input.keys.pressed[13]) {
|
if (game.input.keys.pressed[13]) {
|
||||||
let message = this.inputElement.value;
|
let message = this.inputElement.value;
|
||||||
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.typing = false;
|
||||||
this.inputElement.blur();
|
this.inputElement.blur();
|
||||||
this.inputElement.disabled = true;
|
this.inputElement.disabled = true;
|
||||||
game.input.locked = false;
|
game.input.locked = false;
|
||||||
} else {
|
} else {
|
||||||
console.log(game.input.locked);
|
|
||||||
this.typing = true;
|
this.typing = true;
|
||||||
this.inputElement.disabled = false;
|
this.inputElement.disabled = false;
|
||||||
this.inputElement.focus();
|
this.inputElement.focus();
|
||||||
|
|
|
@ -20,6 +20,7 @@ class Game {
|
||||||
this.pingMode = 'fast';
|
this.pingMode = 'fast';
|
||||||
|
|
||||||
this.input = new Input();
|
this.input = new Input();
|
||||||
|
this.commandProcessor = new CommandProcessor();
|
||||||
this.gui = new GUI();
|
this.gui = new GUI();
|
||||||
this.net = new Net();
|
this.net = new Net();
|
||||||
this.world = new World();
|
this.world = new World();
|
||||||
|
@ -29,6 +30,10 @@ class Game {
|
||||||
this.state = 'connecting';
|
this.state = 'connecting';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command(a, b) {
|
||||||
|
this.commandProcessor.run(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
this.renderer.render(this.state);
|
this.renderer.render(this.state);
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Effect {
|
||||||
|
|
||||||
createExplosion() {
|
createExplosion() {
|
||||||
let num = this.size * this.size;
|
let num = this.size * this.size;
|
||||||
let colors = ['#f52', '#ff7'];
|
let colors = ['#f52', '#ff7', '#fff'];
|
||||||
let b = 'sizzle';
|
let b = 'sizzle';
|
||||||
this.generateParticles(0, 0, 1, num, colors, [1, 2], b, 50, 3);
|
this.generateParticles(0, 0, 1, num, colors, [1, 2], b, 50, 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Ship extends Body {
|
class Ship extends Body {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
|
console.log(data);
|
||||||
super(data);
|
super(data);
|
||||||
this.player = new Player(data.name, data.team, this);
|
this.player = new Player(data.name, data.team, this);
|
||||||
this.team = data.team;
|
this.team = data.team;
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Connection {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('setName', data => {
|
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 => {
|
socket.on('inputs', data => {
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Ship extends Body {
|
||||||
this.mounts.push(mount);
|
this.mounts.push(mount);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.turrets = [];
|
this.turrets = build.turrets || [];
|
||||||
|
|
||||||
this.thrust = {
|
this.thrust = {
|
||||||
forward: 0,
|
forward: 0,
|
||||||
|
@ -113,7 +113,7 @@ class Ship extends Body {
|
||||||
frame: this.frame,
|
frame: this.frame,
|
||||||
power: this.power,
|
power: this.power,
|
||||||
mounts: this.mounts.map(m => m.packFull()),
|
mounts: this.mounts.map(m => m.packFull()),
|
||||||
turrets: this.turrets,
|
turrets: this.turrets.map(t => t.packFull()),
|
||||||
size: this.size,
|
size: this.size,
|
||||||
delta: this.packDelta()
|
delta: this.packDelta()
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,8 @@ const Laser = require('./shot/laser.js');
|
||||||
class Blaster extends Fixture {
|
class Blaster extends Fixture {
|
||||||
constructor(hardpoint, data) {
|
constructor(hardpoint, data) {
|
||||||
super(hardpoint, data);
|
super(hardpoint, data);
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
fire() {
|
fire() {
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
const traits = require('../../traits/turrets.json');
|
const traits = require('../../traits/turrets.json');
|
||||||
|
|
||||||
class Fixture {
|
class Fixture {
|
||||||
constructor(hardpoint, data) {
|
constructor(mount, data) {
|
||||||
this.hardpoint = hardpoint;
|
this.mount = mount;
|
||||||
|
|
||||||
this.projectiles = new WeakSet();
|
this.projectiles = new WeakSet();
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ class Fixture {
|
||||||
|
|
||||||
this.rof = turretTraits.rateOfFire;
|
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;
|
this._angle = this.traversal ? this.traversal.cw : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +21,17 @@ class Fixture {
|
||||||
this.projectiles.forEach(p => p.world.removeBody(p));
|
this.projectiles.forEach(p => p.world.removeBody(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packFull() {
|
||||||
|
return {
|
||||||
|
|
||||||
|
traversal: this.traversal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
packDelta() {
|
||||||
|
return [this.traversal];
|
||||||
|
}
|
||||||
|
|
||||||
get angle() {
|
get angle() {
|
||||||
return this._angle;
|
return this._angle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Mount {
|
||||||
|
|
||||||
this.type = data.type || 'turret';
|
this.type = data.type || 'turret';
|
||||||
this.fixture = false;
|
this.fixture = false;
|
||||||
|
this.size = data.size || 0;
|
||||||
this.position = {
|
this.position = {
|
||||||
x: data.pos[0],
|
x: data.pos[0],
|
||||||
y: data.pos[1]
|
y: data.pos[1]
|
||||||
|
@ -26,7 +27,8 @@ class Mount {
|
||||||
|
|
||||||
packFull() {
|
packFull() {
|
||||||
return {
|
return {
|
||||||
|
x: this.position.x,
|
||||||
|
y: this.position.y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue