From 578344f784e50d92705f4a6e6fb8b908759d6b02 Mon Sep 17 00:00:00 2001 From: alterdekim Date: Fri, 15 Mar 2024 19:24:30 +0300 Subject: [PATCH] chip --- src/main/resources/static/javascript/game.js | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/resources/static/javascript/game.js b/src/main/resources/static/javascript/game.js index 81d240a..6cff622 100644 --- a/src/main/resources/static/javascript/game.js +++ b/src/main/resources/static/javascript/game.js @@ -132,7 +132,7 @@ function chipMove(body) { if( nc == undefined ) return; nc.x = body.x; nc.y = body.y; - refreshChips(); + moveChip(nc); } const corners = [ @@ -176,15 +176,22 @@ function includes(pos) { return false; } -function refreshChips() { +function moveChip(chip) { + $(chip.dom).css("background-color", chip.color); + let offsetY = (Math.max(chip.y-1, 0) * 55) + (chip.y * 2) + (clamp(chip.y, 0, 1) * 100) + 18; + let offsetX = (Math.max(chip.x-1, 0) * 55) + (chip.x * 2) + (clamp(chip.x, 0, 1) * 100); + $(chip.dom).animate({marginTop: offsetY, marginLeft: offsetX}, 1000); +} + +function moveChips() { for(let i = 0; i < board.chips.length; i++ ) { let chip = board.chips[i]; if( chip.uid == 0 ) continue; - $(chip.dom).css("background-color", chip.color); - let offsetY = (Math.max(chip.y-1, 0) * 55) + (chip.y * 2) + (clamp(chip.y, 0, 1) * 100) + 18; - let offsetX = (Math.max(chip.x-1, 0) * 55) + (chip.x * 2) + (clamp(chip.x, 0, 1) * 100); - $(chip.dom).animate({marginTop: offsetY, marginLeft: offsetX}, 1000); + moveChip(chip); } +} + +function refreshChips() { let positions = distinct(board.chips.filter((c) => c.uid != 0).map(({ x, y }) => ({ x, y }))); for( let i = 0; i < positions.length; i++ ) { let a = board.chips.filter((c) => c.x == positions[i].x && c.y == positions[i].y && c.uid != 0); @@ -238,7 +245,7 @@ function assignChip(body) { nc.x = body.x; nc.y = body.y; $(nc.obj).css("display", ""); - refreshChips(); + moveChip(nc); } function changeBoardState(body) {