2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
import QtQuick
|
2022-03-23 11:40:28 +00:00
|
|
|
|
|
|
|
Item {
|
2022-04-30 07:27:56 +00:00
|
|
|
property var cards: []
|
|
|
|
property int length: 0
|
|
|
|
property var pendingInput: []
|
|
|
|
property bool checkExisting: false
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
id: root
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function add(inputs)
|
|
|
|
{
|
|
|
|
let card;
|
|
|
|
if (inputs instanceof Array) {
|
|
|
|
for (let i = 0; i < inputs.length; i++) {
|
|
|
|
card = inputs[i];
|
|
|
|
pendingInput.push(card);
|
|
|
|
cards.push(card.toData());
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (checkExisting)
|
|
|
|
length = cards.length;
|
|
|
|
else
|
|
|
|
length += inputs.length;
|
|
|
|
} else {
|
|
|
|
pendingInput.push(inputs);
|
|
|
|
cards.push(inputs.toData());
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (checkExisting)
|
|
|
|
length = cards.length;
|
|
|
|
else
|
|
|
|
length++;
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function _contains(cid)
|
|
|
|
{
|
|
|
|
if (!checkExisting)
|
|
|
|
return true;
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
for (let i = 0; i < cards.length; i++)
|
|
|
|
{
|
|
|
|
if (cards[i].cid === cid)
|
|
|
|
return true;
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function remove(outputs)
|
|
|
|
{
|
2023-06-09 09:23:02 +00:00
|
|
|
const component = Qt.createComponent("CardItem.qml");
|
2022-04-30 07:27:56 +00:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return [];
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2023-06-09 09:23:02 +00:00
|
|
|
const parentPos = roomScene.mapFromItem(root, 0, 0);
|
2022-04-30 07:27:56 +00:00
|
|
|
let card;
|
2023-06-09 09:23:02 +00:00
|
|
|
const items = [];
|
2022-04-30 07:27:56 +00:00
|
|
|
for (let i = 0; i < outputs.length; i++) {
|
|
|
|
if (_contains(outputs[i])) {
|
2023-06-09 09:23:02 +00:00
|
|
|
const state = JSON.parse(Backend.callLuaFunction("GetCardData", [outputs[i]]))
|
2022-04-30 07:27:56 +00:00
|
|
|
state.x = parentPos.x;
|
|
|
|
state.y = parentPos.y;
|
|
|
|
state.opacity = 0;
|
2022-12-18 04:52:52 +00:00
|
|
|
card = component.createObject(roomScene.dynamicCardArea, state);
|
2022-04-30 07:27:56 +00:00
|
|
|
card.x -= card.width / 2;
|
|
|
|
card.x += (i - outputs.length / 2) * 15;
|
|
|
|
card.y -= card.height / 2;
|
|
|
|
items.push(card);
|
|
|
|
if (checkExisting) {
|
2023-01-29 10:11:41 +00:00
|
|
|
for (let j = 0; j < length; j++) {
|
|
|
|
if (cards[j].cid == card.cid) {
|
|
|
|
cards.splice(j, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
if (checkExisting)
|
|
|
|
length = cards.length;
|
|
|
|
else
|
|
|
|
length -= outputs.length;
|
|
|
|
return items;
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
let i, card;
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (animated) {
|
2023-06-09 09:23:02 +00:00
|
|
|
const parentPos = roomScene.mapFromItem(root, 0, 0);
|
2022-04-30 07:27:56 +00:00
|
|
|
for (i = 0; i < pendingInput.length; i++) {
|
|
|
|
card = pendingInput[i];
|
|
|
|
card.origX = parentPos.x - card.width / 2 + ((i - pendingInput.length / 2) * 15);
|
|
|
|
card.origY = parentPos.y - card.height / 2;
|
|
|
|
card.origOpacity = 0;
|
|
|
|
card.destroyOnStop();
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
for (i = 0; i < pendingInput.length; i++)
|
|
|
|
pendingInput[i].goBack(true);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < pendingInput.length; i++) {
|
|
|
|
card = pendingInput[i];
|
|
|
|
card.x = parentPos.x - card.width / 2;
|
|
|
|
card.y = parentPos.y - card.height / 2;
|
|
|
|
card.opacity = 1;
|
|
|
|
card.destroy();
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
pendingInput = [];
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|