store bg color

This commit is contained in:
Zutatensuppe 2020-12-03 21:24:59 +01:00
parent 3d1a9ca9c7
commit 4ac995f1e1
2 changed files with 9 additions and 10 deletions

View file

@ -25,6 +25,7 @@ function addPlayer(gameId, playerId) {
d: 0, // mouse down d: 0, // mouse down
name: 'anon', name: 'anon',
color: '#ffffff', color: '#ffffff',
bgcolor: '#222222',
points: 0, points: 0,
ts, ts,
} }
@ -323,7 +324,11 @@ function handleInput(gameId, playerId, input) {
const ts = Util.timestamp() const ts = Util.timestamp()
const type = input[0] const type = input[0]
if (type === 'player_color') { if (type === 'bg_color') {
const bgcolor = input[1]
changePlayer(gameId, playerId, { bgcolor, ts })
_playerChange()
} else if (type === 'player_color') {
const color = input[1] const color = input[1]
changePlayer(gameId, playerId, { color, ts }) changePlayer(gameId, playerId, { color, ts })
_playerChange() _playerChange()

View file

@ -285,8 +285,6 @@ async function main() {
const puzzle = game.puzzle const puzzle = game.puzzle
const players = game.players const players = game.players
let bgColor = '#222222'
const changePlayer = (change) => { const changePlayer = (change) => {
for (let k of Object.keys(change)) { for (let k of Object.keys(change)) {
players[CLIENT_ID][k] = change[k] players[CLIENT_ID][k] = change[k]
@ -311,7 +309,7 @@ async function main() {
const evts = new EventAdapter(canvas, viewport) const evts = new EventAdapter(canvas, viewport)
bgColorPickerEl.value = bgColor bgColorPickerEl.value = players[CLIENT_ID].bgcolor
bgColorPickerEl.addEventListener('change', () => { bgColorPickerEl.addEventListener('change', () => {
evts.addEvent(['bg_color', bgColorPickerEl.value]) evts.addEvent(['bg_color', bgColorPickerEl.value])
}) })
@ -361,11 +359,7 @@ async function main() {
// LOCAL ONLY CHANGES // LOCAL ONLY CHANGES
// ------------------------------------------------------------- // -------------------------------------------------------------
const type = evt[0] const type = evt[0]
if (type === 'bg_color') { if (type === 'move') {
const color = evt[1]
bgColor = color
RERENDER = true
} else if (type === 'move') {
const pos = { x: evt[1], y: evt[2] } const pos = { x: evt[1], y: evt[2] }
RERENDER = true RERENDER = true
changePlayer(pos) changePlayer(pos)
@ -420,7 +414,7 @@ async function main() {
// CLEAR CTX // CLEAR CTX
// --------------------------------------------------------------- // ---------------------------------------------------------------
ctx.fillStyle = bgColor ctx.fillStyle = players[CLIENT_ID].bgcolor || '#222222'
ctx.fillRect(0, 0, canvas.width, canvas.height) ctx.fillRect(0, 0, canvas.width, canvas.height)
if (DEBUG) Debug.checkpoint('clear done') if (DEBUG) Debug.checkpoint('clear done')
// --------------------------------------------------------------- // ---------------------------------------------------------------