You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
// Moves card positions down/up for the old/new element for player in room
|
|
function setCardPosition(roomId, player, card, newPosition, newElement, oldPosition, oldElement){
|
|
|
|
// Move anything in the old boardElement after the old listPosition down by one
|
|
moveElementPositions(roomId, player, 0, oldElement, oldPosition);
|
|
|
|
// Move anything in the new boardElement after (including) the new listPosition up by one
|
|
moveElementPositions(roomId, player, 1, newElement, newPosition);
|
|
|
|
// Then fit the card into the new gap that's opened up
|
|
listPosition[card] = newPosition;
|
|
|
|
// Remove from oldElement
|
|
delete oldElement[card]
|
|
// Add to newElement
|
|
newElement[card] = newPosition;
|
|
|
|
}
|
|
|
|
// direction 0 up, 1 down
|
|
function moveElementPositions(roomId, player, direction, element, position){
|
|
|
|
position = position;
|
|
listPosition = global.roomData[roomId].itemData.component.listPosition;
|
|
|
|
for (const [key, value] of Object.entries(element)) {
|
|
|
|
if(global.roomData[roomId].itemData.component.player[key] != player){
|
|
continue;
|
|
}
|
|
|
|
|
|
// Move down from (not including) the position passed
|
|
if(direction == 0 && listPosition[key] > position){
|
|
listPosition[key]--;
|
|
}
|
|
|
|
// Move everything from (including) the new position up
|
|
if(direction == 1 && listPosition[key] >= position){
|
|
console.log('hit');
|
|
console.log(listPosition[key]);
|
|
console.log(position);
|
|
listPosition[key]++;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
setCardPosition
|
|
};
|
|
|