significant optimzations
This commit is contained in:
parent
3ce6ded308
commit
37b516faee
5 changed files with 71 additions and 20 deletions
|
@ -137,9 +137,7 @@ class Game extends GameBasic {
|
|||
sync() {
|
||||
let { player } = this;
|
||||
|
||||
let { vel, dir, you, ticks, isMenu, r, playing } = player;
|
||||
|
||||
this.ws.send(JSON.stringify({ vel, dir, you, ticks, isMenu, r, playing }));
|
||||
this.ws.send(JSON.stringify(player.legalProps.map(prop => player[prop])));
|
||||
}
|
||||
recv({ data }) {
|
||||
let { player } = this;
|
||||
|
@ -148,10 +146,19 @@ class Game extends GameBasic {
|
|||
let that = this;
|
||||
|
||||
let entList = JSON.parse(data);
|
||||
entList = entList.map(x => {
|
||||
let type = (Object.keys(legalTypes).indexOf(x.type) == -1) ? Player : legalTypes[x.type];
|
||||
entList = entList.map(y => {
|
||||
let type = (Object.keys(legalTypes).indexOf(y[0]) == -1) ? Player : legalTypes[y[0]];
|
||||
|
||||
let props = new type().serverProps;
|
||||
|
||||
let x = {};
|
||||
|
||||
for (let i in props) {
|
||||
x[props[i]] = y[i];
|
||||
}
|
||||
|
||||
x.handleTick = type.prototype.handleTick;
|
||||
if (x.r != 1) {
|
||||
if (x.r != 1 && type == 'Player') {
|
||||
let a = new Audio(`assets/${emojis[x.r]}.wav`);
|
||||
a.addEventListener('ended', () => {
|
||||
if (x.you == you) {
|
||||
|
@ -170,6 +177,8 @@ class Game extends GameBasic {
|
|||
|
||||
let matchingPlayer = entList.filter(x => x.you == you)
|
||||
|
||||
if (matchingPlayer.length == 0) matchingPlayer = entList.filter(x => x.type == 'Player');
|
||||
|
||||
this.player = Object.assign(this.player || new Player(false, false), matchingPlayer[0]);
|
||||
|
||||
if (this.player.r != 1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue