restart game & fixes

This commit is contained in:
2020-01-26 15:51:16 -05:00
parent c1814d883d
commit 704ef006a8
4 changed files with 97 additions and 26 deletions

View File

@@ -21,7 +21,11 @@ function initNet() {
})
SOCKET.on("end_message", msg => {
alert(msg.text)
if (msg.replay) {
createGameModal();
} else {
TEXT.text = msg.text;
}
})
SOCKET.on("game_state", msg => {
@@ -33,7 +37,10 @@ function initNet() {
"room": ROOM,
})
} else if (msg.state === "ENDED") {
SOCKET.emit("get_end_message")
SOCKET.emit("get_end_message", {
"oid": selfOid(),
"room": ROOM,
})
}
})
@@ -53,8 +60,14 @@ function initNet() {
SOCKET.on("get_card_rsp", msg => {
// Add self card
let card = new BingoCard(msg.card.oid, msg.parent);
card._self = msg.card;
Object.keys(CARDS).forEach(key => {
if (key !== "SELF") {
CARDS[key]._destroy();
}
});
CARDS = {};
CARDS[msg.card.oid] = card;
CARDS["SELF"] = card;
updateCards();
@@ -81,7 +94,10 @@ function initNet() {
"room": ROOM,
})
} else if (msg.state === "ENDED") {
SOCKET.emit("get_end_message")
SOCKET.emit("get_end_message", {
"oid": selfOid(),
"room": ROOM,
})
}
});

View File

@@ -63,7 +63,7 @@ function onCreateGameSubmit() {
"mode": gameMode,
"maximum_size": maximumSize,
"middle_free": middleFree,
"pool": pool.split(/\s+/).map(w => w.trim())
"pool": pool.split(/\n+/).map(w => w.trim())
})
return false;
}
@@ -255,6 +255,20 @@ function BingoCard(oid, parent, small = false) {
}
}
g._destroy = function () {
let toDestroy = [];
g.children.forEach(child => {
if (child !== this._text) {
toDestroy.push(child);
}
})
toDestroy.forEach(x => {
x._destroy();
})
g.destroy({texture: true, baseTexture: true, children: true});
}
return g;
}
@@ -265,8 +279,7 @@ function makeText() {
const t = new PIXI.Text("", {
fontFamily: STYLE.font,
fontSize: 38,
fill: STYLE.cell.text,
strokeThickness: 2,
fill: STYLE.message,
align: "left",
breakWords: true,
wordWrap: true,
@@ -360,6 +373,7 @@ function updateCards() {
}
window.onresize = function () {
calculateDimensions();
updateCards();
}