parent
97cf2dc632
commit
ec22d54b1f
6 changed files with 150 additions and 112 deletions
@ -1,53 +1,61 @@ |
|||||||
const Controls = { |
const Controls = function(connection) { |
||||||
guessBuild: () => { |
this.connection = connection; |
||||||
const container = document.getElementById('controls-guesses'); |
console.log(this.connection) |
||||||
container.querySelectorAll('.controls-guess').forEach(el => el.parentNode.removeChild(el)); |
} |
||||||
|
|
||||||
for (let i = 1; i <= 30; i++) { |
// guessBuild: = function() {
|
||||||
const guess = document.createElement('div'); |
// const container = document.getElementById('controls-guesses');
|
||||||
guess.className = 'controls-guess'; |
// container.querySelectorAll('.controls-guess').forEach(el => el.parentNode.removeChild(el));
|
||||||
guess.innerHTML = i; |
|
||||||
guess.setAttribute('data-value', i); |
// for (let i = 1; i <= 30; i++) {
|
||||||
guess.addEventListener('click', Controls.guessClick) |
// const guess = document.createElement('div');
|
||||||
container.appendChild(guess); |
// guess.className = 'controls-guess';
|
||||||
|
// guess.innerHTML = i;
|
||||||
|
// guess.setAttribute('data-value', i);
|
||||||
|
// guess.addEventListener('click', Controls.guessClick)
|
||||||
|
// container.appendChild(guess);
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
|
||||||
|
// guessClick: (evt) => {
|
||||||
|
// alert(evt.currentTarget.dataset.value)
|
||||||
|
// },
|
||||||
|
|
||||||
|
Controls.prototype.playerAdd = function() { |
||||||
|
const rawInput = prompt("What is your name?"); |
||||||
|
this.connection.send(JSON.stringify({ head: { type: 'playerAdd' }, body: rawInput })) |
||||||
|
}; |
||||||
|
|
||||||
|
Controls.prototype.playerRemove = function(rawInput) { |
||||||
|
this.connection.send(JSON.stringify({ head: { type: 'playerRemove' }, body: rawInput })) |
||||||
|
}; |
||||||
|
|
||||||
|
Controls.prototype.playersUpdate = function(names) { |
||||||
|
const container = document.getElementById('controls-players'); |
||||||
|
const keys = Object.keys(names); |
||||||
|
|
||||||
|
if (keys.length > 0) { |
||||||
|
const nobody = document.getElementById('controls-players-nobody'); |
||||||
|
nobody.parentNode.removeChild(nobody); |
||||||
|
} |
||||||
|
|
||||||
|
keys.forEach(connectionId => { |
||||||
|
const id = `player-${connectionId}`; |
||||||
|
|
||||||
|
if (document.getElementById(id)) { |
||||||
|
return; |
||||||
} |
} |
||||||
}, |
|
||||||
|
const n = document.createElement('div'); |
||||||
guessClick: (evt) => { |
n.id = id; |
||||||
alert(evt.currentTarget.dataset.value) |
n.innerHTML = names[connectionId]; |
||||||
}, |
n.className = 'controls-player'; |
||||||
|
container.appendChild(n) |
||||||
playerAdd: () => { |
}); |
||||||
const rawInput = prompt("What is your name?"); |
|
||||||
connection.send(JSON.stringify({ head: { type: 'playerAdd' }, body: rawInput })) |
// container.querySelectorAll('.controls-player').forEach(el => {
|
||||||
}, |
// if (!names[el.id]) {
|
||||||
|
// container.removeChild(el);
|
||||||
playerRemove: (rawInput) => { |
// }
|
||||||
connection.send(JSON.stringify({ head: { type: 'playerRemove' }, body: rawInput })) |
// })
|
||||||
}, |
|
||||||
|
|
||||||
playersUpdate: (names) => { |
|
||||||
const container = document.getElementById('controls-players'); |
|
||||||
console.log(names) |
|
||||||
|
|
||||||
Object.keys(names).forEach(connectionId => { |
|
||||||
const id = `player-${connectionId}`; |
|
||||||
|
|
||||||
if (document.getElementById(id)) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
const n = document.createElement('div'); |
|
||||||
n.id = id; |
|
||||||
n.innerHTML = names[connectionId]; |
|
||||||
n.className = 'controls-player'; |
|
||||||
container.appendChild(n) |
|
||||||
}); |
|
||||||
|
|
||||||
// container.querySelectorAll('.controls-player').forEach(el => {
|
|
||||||
// if (!names[el.id]) {
|
|
||||||
// container.removeChild(el);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
}, |
|
||||||
}; |
}; |
@ -1,12 +1,10 @@ |
|||||||
// TODO dynamic sizing of squares based on available height |
|
||||||
// TODO dynamic move population |
// TODO dynamic move population |
||||||
// TODO move websocket server to /core |
// TODO move websocket server to /core |
||||||
// TODO dynamic socket server resolution |
// TODO dynamic socket server resolution |
||||||
// TODO namespace server to /ricochet |
// TODO namespace server to /ricochet |
||||||
// TODO [soap, xmpp] |
|
||||||
// TODO a message must have a head and a body |
|
||||||
// TODO your favorite games |
// TODO your favorite games |
||||||
// TODO no cancel from name prompt |
// TODO no cancel from name prompt |
||||||
// TODO limit concurrent players |
// TODO limit concurrent players |
||||||
// TODO window resize update board |
// TODO window resize update board |
||||||
// TODO donate link |
// TODO donate link |
||||||
|
// TODO tutorial |
Loading…
Reference in new issue