fix mouse shaking when moving map
This commit is contained in:
parent
1025d42ea2
commit
6cb688b4d0
1 changed files with 28 additions and 10 deletions
|
|
@ -108,12 +108,20 @@ function addPlayer(gameId, playerId, ts) {
|
||||||
} else {
|
} else {
|
||||||
changePlayer(gameId, playerId, { ts })
|
changePlayer(gameId, playerId, { ts })
|
||||||
}
|
}
|
||||||
if (!GAMES[gameId].evtInfos[playerId]) {
|
}
|
||||||
GAMES[gameId].evtInfos[playerId] = {
|
|
||||||
_last_mouse: null,
|
function getEvtInfo(gameId, playerId) {
|
||||||
_last_mouse_down: null,
|
if (playerId in GAMES[gameId].evtInfos) {
|
||||||
}
|
return GAMES[gameId].evtInfos[playerId]
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
_last_mouse: null,
|
||||||
|
_last_mouse_down: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setEvtInfo(gameId, playerId, evtInfo) {
|
||||||
|
GAMES[gameId].evtInfos[playerId] = evtInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllGames() {
|
function getAllGames() {
|
||||||
|
|
@ -424,7 +432,7 @@ const getPuzzleHeight = (gameId) => {
|
||||||
|
|
||||||
function handleInput(gameId, playerId, input, ts) {
|
function handleInput(gameId, playerId, input, ts) {
|
||||||
const puzzle = GAMES[gameId].puzzle
|
const puzzle = GAMES[gameId].puzzle
|
||||||
let evtInfo = GAMES[gameId].evtInfos[playerId]
|
let evtInfo = getEvtInfo(gameId, playerId)
|
||||||
|
|
||||||
let changes = []
|
let changes = []
|
||||||
|
|
||||||
|
|
@ -527,18 +535,27 @@ function handleInput(gameId, playerId, input, ts) {
|
||||||
const y = input[2]
|
const y = input[2]
|
||||||
const pos = {x, y}
|
const pos = {x, y}
|
||||||
|
|
||||||
changePlayer(gameId, playerId, {x, y, ts})
|
if (evtInfo._last_mouse_down === null) {
|
||||||
_playerChange()
|
// player is just moving the hand
|
||||||
|
changePlayer(gameId, playerId, {x, y, ts})
|
||||||
if (evtInfo._last_mouse_down !== null) {
|
_playerChange()
|
||||||
|
} else {
|
||||||
let tileIdx = getFirstOwnedTileIdx(gameId, playerId)
|
let tileIdx = getFirstOwnedTileIdx(gameId, playerId)
|
||||||
if (tileIdx >= 0) {
|
if (tileIdx >= 0) {
|
||||||
|
// player is moving a tile (and hand)
|
||||||
|
changePlayer(gameId, playerId, {x, y, ts})
|
||||||
|
_playerChange()
|
||||||
|
|
||||||
const diffX = x - evtInfo._last_mouse_down.x
|
const diffX = x - evtInfo._last_mouse_down.x
|
||||||
const diffY = y - evtInfo._last_mouse_down.y
|
const diffY = y - evtInfo._last_mouse_down.y
|
||||||
const diff = { x: diffX, y: diffY }
|
const diff = { x: diffX, y: diffY }
|
||||||
const tileIdxs = getGroupedTileIdxs(gameId, tileIdx)
|
const tileIdxs = getGroupedTileIdxs(gameId, tileIdx)
|
||||||
moveTilesDiff(gameId, tileIdxs, diff)
|
moveTilesDiff(gameId, tileIdxs, diff)
|
||||||
_tileChanges(tileIdxs)
|
_tileChanges(tileIdxs)
|
||||||
|
} else {
|
||||||
|
// player is just moving map, so no change in position!
|
||||||
|
changePlayer(gameId, playerId, {ts})
|
||||||
|
_playerChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
evtInfo._last_mouse_down = pos
|
evtInfo._last_mouse_down = pos
|
||||||
|
|
@ -624,6 +641,7 @@ function handleInput(gameId, playerId, input, ts) {
|
||||||
_playerChange()
|
_playerChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setEvtInfo(gameId, playerId, evtInfo)
|
||||||
return changes
|
return changes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue