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) {
|
||||
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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue