2023-04-09 13:35:35 +08:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const Card = {
|
2022-04-30 15:27:56 +08:00
|
|
|
Unknown : 0,
|
|
|
|
PlayerHand : 1,
|
|
|
|
PlayerEquip : 2,
|
|
|
|
PlayerJudge : 3,
|
|
|
|
PlayerSpecial : 4,
|
|
|
|
Processing : 5,
|
|
|
|
DrawPile : 6,
|
|
|
|
DiscardPile : 7,
|
|
|
|
Void : 8
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
2023-09-06 22:16:09 +08:00
|
|
|
function arrangeManyPhotos() {
|
|
|
|
/* Layout of photos:
|
|
|
|
* +----------------+
|
|
|
|
* | -2 ... 2 |
|
|
|
|
* | -1 1 |
|
|
|
|
* | 0 |
|
|
|
|
* +----------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
const photoBaseWidth = 175;
|
|
|
|
const photoMaxWidth = 175 * 0.75;
|
|
|
|
const verticalSpacing = 32;
|
|
|
|
// Padding is negative, because photos are scaled.
|
|
|
|
const roomAreaPadding = -16;
|
|
|
|
|
|
|
|
let horizontalSpacing = 8;
|
2024-01-25 03:23:29 +08:00
|
|
|
let photoWidth = (roomArea.width - horizontalSpacing * playerNum)
|
|
|
|
/ (playerNum - 1);
|
2023-09-06 22:16:09 +08:00
|
|
|
let photoScale = 0.75;
|
|
|
|
if (photoWidth > photoMaxWidth) {
|
|
|
|
photoWidth = photoMaxWidth;
|
2024-01-25 03:23:29 +08:00
|
|
|
horizontalSpacing = (roomArea.width - photoWidth * (playerNum - 1))
|
|
|
|
/ playerNum;
|
2023-09-06 22:16:09 +08:00
|
|
|
} else {
|
|
|
|
photoScale = photoWidth / photoBaseWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
const horizontalPadding = (photoWidth - photoBaseWidth) / 2;
|
|
|
|
const startX = horizontalPadding + horizontalSpacing;
|
|
|
|
const padding = photoWidth + horizontalSpacing;
|
|
|
|
let regions = [
|
|
|
|
{
|
|
|
|
x: startX + padding * (playerNum - 2),
|
|
|
|
y: roomScene.height - 220,
|
|
|
|
scale: photoScale
|
|
|
|
},
|
|
|
|
];
|
|
|
|
let i;
|
|
|
|
for (i = 0; i < playerNum - 1; i++) {
|
|
|
|
regions.push({
|
|
|
|
x: startX + padding * (playerNum - 2 - i),
|
|
|
|
y: roomAreaPadding,
|
|
|
|
scale: photoScale,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
regions[1].y += verticalSpacing * 3;
|
|
|
|
regions[regions.length - 1].y += verticalSpacing * 3;
|
|
|
|
regions[2].y += verticalSpacing;
|
|
|
|
regions[regions.length - 2].y += verticalSpacing;
|
|
|
|
|
|
|
|
let item, region;
|
|
|
|
|
|
|
|
for (i = 0; i < playerNum; i++) {
|
|
|
|
item = photos.itemAt(i);
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
region = regions[photoModel.get(i).index];
|
|
|
|
item.x = region.x;
|
|
|
|
item.y = region.y;
|
|
|
|
item.scale = region.scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 19:40:28 +08:00
|
|
|
function arrangePhotos() {
|
2023-09-06 22:16:09 +08:00
|
|
|
if (playerNum > 8) {
|
|
|
|
return arrangeManyPhotos();
|
|
|
|
}
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
/* Layout of photos:
|
|
|
|
* +---------------+
|
|
|
|
* | 6 5 4 3 2 |
|
|
|
|
* | 7 1 |
|
2023-04-27 14:15:08 +08:00
|
|
|
* | 0 |
|
2022-04-30 15:27:56 +08:00
|
|
|
* +---------------+
|
|
|
|
*/
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
const photoWidth = 175 * 0.75;
|
|
|
|
// Padding is negative, because photos are scaled.
|
|
|
|
const roomAreaPadding = -16;
|
|
|
|
const verticalPadding = -175 / 8;
|
|
|
|
const horizontalSpacing = 32;
|
2023-06-09 01:16:23 +08:00
|
|
|
const verticalSpacing = (roomArea.width - photoWidth * 7) / 8;
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
// Position 1-7
|
2023-06-09 01:16:23 +08:00
|
|
|
const startX = verticalPadding + verticalSpacing;
|
|
|
|
const padding = photoWidth + verticalSpacing;
|
|
|
|
const regions = [
|
2023-04-27 14:15:08 +08:00
|
|
|
{ x: startX + padding * 6, y: roomScene.height - 220 },
|
2022-09-14 13:01:10 +08:00
|
|
|
{ x: startX + padding * 6, y: roomAreaPadding + horizontalSpacing * 3 },
|
|
|
|
{ x: startX + padding * 5, y: roomAreaPadding + horizontalSpacing },
|
|
|
|
{ x: startX + padding * 4, y: roomAreaPadding },
|
|
|
|
{ x: startX + padding * 3, y: roomAreaPadding },
|
|
|
|
{ x: startX + padding * 2, y: roomAreaPadding },
|
|
|
|
{ x: startX + padding, y: roomAreaPadding + horizontalSpacing },
|
|
|
|
{ x: startX, y: roomAreaPadding + horizontalSpacing * 3 },
|
2022-04-30 15:27:56 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
const regularSeatIndex = [
|
2023-04-27 14:15:08 +08:00
|
|
|
[0, 4],
|
|
|
|
[0, 3, 5],
|
|
|
|
[0, 1, 4, 7],
|
|
|
|
[0, 1, 3, 5, 7],
|
|
|
|
[0, 1, 3, 4, 5, 7],
|
|
|
|
[0, 1, 2, 3, 5, 6, 7],
|
|
|
|
[0, 1, 2, 3, 4, 5, 6, 7],
|
2022-04-30 15:27:56 +08:00
|
|
|
];
|
2023-06-09 01:16:23 +08:00
|
|
|
const seatIndex = regularSeatIndex[playerNum - 2];
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
let item, region, i;
|
|
|
|
|
2023-04-27 14:15:08 +08:00
|
|
|
for (i = 0; i < playerNum; i++) {
|
2022-04-30 15:27:56 +08:00
|
|
|
item = photos.itemAt(i);
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
|
2023-04-27 14:15:08 +08:00
|
|
|
region = regions[seatIndex[photoModel.get(i).index]];
|
2022-04-30 15:27:56 +08:00
|
|
|
item.x = region.x;
|
|
|
|
item.y = region.y;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-03-24 21:23:42 +08:00
|
|
|
|
2022-04-02 15:11:13 +08:00
|
|
|
function doOkButton() {
|
2023-06-09 01:16:23 +08:00
|
|
|
if (roomScene.state === "playing" || roomScene.state === "responding") {
|
2024-01-25 03:23:29 +08:00
|
|
|
const reply = JSON.stringify({
|
|
|
|
card: dashboard.getSelectedCard(),
|
|
|
|
targets: selected_targets,
|
|
|
|
special_skill: roomScene.getCurrentCardUseMethod(),
|
|
|
|
interaction_data: roomScene.skillInteraction.item ?
|
|
|
|
roomScene.skillInteraction.item.answer : undefined,
|
|
|
|
});
|
2023-05-19 23:03:39 +08:00
|
|
|
replyToServer(reply);
|
2022-04-30 15:27:56 +08:00
|
|
|
return;
|
2023-02-26 16:51:29 +08:00
|
|
|
}
|
2023-05-19 07:45:21 +08:00
|
|
|
if (roomScene.extra_data.luckCard) {
|
|
|
|
okButton.enabled = false;
|
|
|
|
ClientInstance.notifyServer("PushRequest", [
|
|
|
|
"luckcard", true
|
|
|
|
].join(","));
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
if (roomScene.extra_data.time === 1) {
|
2023-05-19 07:45:21 +08:00
|
|
|
roomScene.state = "notactive";
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
replyToServer("1");
|
2022-04-02 15:11:13 +08:00
|
|
|
}
|
|
|
|
|
2023-08-24 21:37:24 +08:00
|
|
|
let _is_canceling = false;
|
2022-04-02 15:11:13 +08:00
|
|
|
function doCancelButton() {
|
2023-08-24 21:37:24 +08:00
|
|
|
if (_is_canceling) return;
|
|
|
|
_is_canceling = true;
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
if (roomScene.state === "playing") {
|
2022-09-15 11:17:13 +08:00
|
|
|
dashboard.stopPending();
|
2022-09-14 13:01:10 +08:00
|
|
|
dashboard.deactivateSkillButton();
|
|
|
|
dashboard.unSelectAll();
|
|
|
|
dashboard.enableCards();
|
2022-09-15 11:17:13 +08:00
|
|
|
dashboard.enableSkills();
|
2023-08-24 21:37:24 +08:00
|
|
|
|
|
|
|
_is_canceling = false;
|
2022-09-14 13:01:10 +08:00
|
|
|
return;
|
2023-06-09 01:16:23 +08:00
|
|
|
} else if (roomScene.state === "responding") {
|
|
|
|
const p = dashboard.pending_skill;
|
2022-09-15 11:17:13 +08:00
|
|
|
dashboard.stopPending();
|
2022-09-14 13:01:10 +08:00
|
|
|
dashboard.deactivateSkillButton();
|
|
|
|
dashboard.unSelectAll();
|
2023-04-20 00:19:48 +08:00
|
|
|
if (roomScene.autoPending || !p) {
|
|
|
|
replyToServer("__cancel");
|
|
|
|
} else {
|
|
|
|
dashboard.enableCards(roomScene.responding_card);
|
|
|
|
dashboard.enableSkills(roomScene.responding_card);
|
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
|
|
|
|
_is_canceling = false;
|
2022-09-14 13:01:10 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-02-26 16:51:29 +08:00
|
|
|
|
2023-05-19 07:45:21 +08:00
|
|
|
if (roomScene.extra_data.luckCard) {
|
|
|
|
ClientInstance.notifyServer("PushRequest", [
|
|
|
|
"luckcard", false
|
|
|
|
].join(","));
|
|
|
|
roomScene.state = "notactive";
|
2023-08-24 21:37:24 +08:00
|
|
|
|
|
|
|
_is_canceling = false;
|
2023-05-19 07:45:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
|
2022-12-18 21:19:35 +08:00
|
|
|
replyToServer("__cancel");
|
2023-08-24 21:37:24 +08:00
|
|
|
_is_canceling = false;
|
2022-04-02 15:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function replyToServer(jsonData) {
|
2022-04-30 15:27:56 +08:00
|
|
|
ClientInstance.replyToServer("", jsonData);
|
2023-04-27 14:15:08 +08:00
|
|
|
if (!mainWindow.is_pending) {
|
|
|
|
roomScene.state = "notactive";
|
|
|
|
} else {
|
|
|
|
roomScene.state = "";
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = mainWindow.fetchMessage();
|
2023-04-27 14:15:08 +08:00
|
|
|
return mainWindow.handleMessage(data.command, data.jsonData);
|
|
|
|
}
|
2022-04-02 15:11:13 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
function getPhotoModel(id) {
|
2022-04-30 15:27:56 +08:00
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = photoModel.get(i);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (item.id === id) {
|
|
|
|
return item;
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
return undefined;
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPhoto(id) {
|
2022-04-30 15:27:56 +08:00
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = photoModel.get(i);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (item.id === id) {
|
|
|
|
return photos.itemAt(i);
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
return undefined;
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPhotoOrDashboard(id) {
|
2023-04-27 14:15:08 +08:00
|
|
|
if (id === Self.id)
|
|
|
|
return dashboard;
|
|
|
|
return getPhoto(id);
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
function getAreaItem(area, id) {
|
2022-04-30 15:27:56 +08:00
|
|
|
if (area === Card.DrawPile) {
|
|
|
|
return drawPile;
|
2024-01-25 03:23:29 +08:00
|
|
|
} else if (area === Card.DiscardPile || area === Card.Processing ||
|
|
|
|
area === Card.Void) {
|
2022-04-30 15:27:56 +08:00
|
|
|
return tablePile;
|
|
|
|
} else if (area === Card.AG) {
|
|
|
|
return popupBox.item;
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const photo = getPhoto(id);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (!photo) {
|
2022-04-14 18:22:00 +08:00
|
|
|
return null;
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (area === Card.PlayerHand) {
|
2023-04-27 14:15:08 +08:00
|
|
|
return id === Self.id ? dashboard.handcardArea : photo.handcardArea;
|
2023-02-16 00:54:39 +08:00
|
|
|
} else if (area === Card.PlayerEquip) {
|
2022-04-30 15:27:56 +08:00
|
|
|
return photo.equipArea;
|
2023-02-16 00:54:39 +08:00
|
|
|
} else if (area === Card.PlayerJudge) {
|
2022-04-30 15:27:56 +08:00
|
|
|
return photo.delayedTrickArea;
|
2023-02-16 00:54:39 +08:00
|
|
|
} else if (area === Card.PlayerSpecial) {
|
2022-04-30 15:27:56 +08:00
|
|
|
return photo.specialArea;
|
2023-02-16 00:54:39 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
return null;
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function moveCards(moves) {
|
2022-04-30 15:27:56 +08:00
|
|
|
for (let i = 0; i < moves.length; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const move = moves[i];
|
|
|
|
const from = getAreaItem(move.fromArea, move.from);
|
|
|
|
const to = getAreaItem(move.toArea, move.to);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (!from || !to || from === to)
|
|
|
|
continue;
|
2023-06-09 01:16:23 +08:00
|
|
|
const items = from.remove(move.ids, move.fromSpecialName);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (items.length > 0)
|
2023-02-21 13:44:24 +08:00
|
|
|
to.add(items, move.specialName);
|
2022-04-30 15:27:56 +08:00
|
|
|
to.updateCardPosition(true);
|
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
2023-07-02 20:39:42 +08:00
|
|
|
function resortHandcards() {
|
|
|
|
if (!dashboard.handcardArea.cards.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const subtypeString2Number = {
|
|
|
|
["none"]: Card.SubtypeNone,
|
|
|
|
["delayed_trick"]: Card.SubtypeDelayedTrick,
|
|
|
|
["weapon"]: Card.SubtypeWeapon,
|
|
|
|
["armor"]: Card.SubtypeArmor,
|
|
|
|
["defensive_horse"]: Card.SubtypeDefensiveRide,
|
|
|
|
["offensive_horse"]: Card.SubtypeOffensiveRide,
|
|
|
|
["treasure"]: Card.SubtypeTreasure,
|
|
|
|
}
|
|
|
|
|
|
|
|
dashboard.handcardArea.cards.sort((prev, next) => {
|
2023-11-07 21:14:51 +08:00
|
|
|
if (prev.footnote === next.footnote) {
|
|
|
|
if (prev.type === next.type) {
|
|
|
|
const prevSubtypeNumber = subtypeString2Number[prev.subtype];
|
|
|
|
const nextSubtypeNumber = subtypeString2Number[next.subtype];
|
|
|
|
if (prevSubtypeNumber === nextSubtypeNumber) {
|
|
|
|
const splitedPrevName = prev.name.split('__');
|
|
|
|
const prevTrueName = splitedPrevName[splitedPrevName.length - 1];
|
|
|
|
|
|
|
|
const splitedNextName = next.name.split('__');
|
|
|
|
const nextTrueName = splitedNextName[splitedNextName.length - 1];
|
|
|
|
if (prevTrueName === nextTrueName) {
|
|
|
|
return prev.cid - next.cid;
|
|
|
|
} else {
|
|
|
|
return prevTrueName > nextTrueName ? -1 : 1;
|
|
|
|
}
|
2023-07-02 20:39:42 +08:00
|
|
|
} else {
|
2023-11-07 21:14:51 +08:00
|
|
|
return prevSubtypeNumber - nextSubtypeNumber;
|
2023-07-02 20:39:42 +08:00
|
|
|
}
|
|
|
|
} else {
|
2023-11-07 21:14:51 +08:00
|
|
|
return prev.type - next.type;
|
2023-07-02 20:39:42 +08:00
|
|
|
}
|
|
|
|
} else {
|
2023-11-07 21:14:51 +08:00
|
|
|
return prev.footnote > next.footnote ? 1 : -1;
|
2023-07-02 20:39:42 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dashboard.handcardArea.updateCardPosition(true);
|
|
|
|
}
|
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
function setEmotion(id, emotion, isCardId) {
|
2023-01-03 23:37:14 +08:00
|
|
|
let path;
|
|
|
|
if (OS === "Win") {
|
2023-01-07 15:20:44 +08:00
|
|
|
// Windows: file:///C:/xxx/xxxx
|
|
|
|
path = (SkinBank.PIXANIM_DIR + emotion).replace("file:///", "");
|
2023-01-03 23:37:14 +08:00
|
|
|
} else {
|
|
|
|
path = (SkinBank.PIXANIM_DIR + emotion).replace("file://", "");
|
|
|
|
}
|
|
|
|
|
2022-12-20 12:51:54 +08:00
|
|
|
if (!Backend.exists(path)) {
|
2023-02-21 13:44:24 +08:00
|
|
|
// Try absolute path again
|
|
|
|
if (OS === "Win") {
|
|
|
|
// Windows: file:///C:/xxx/xxxx
|
|
|
|
path = (AppPath + "/" + emotion).replace("file:///", "");
|
|
|
|
} else {
|
|
|
|
path = (AppPath + "/" + emotion).replace("file://", "");
|
|
|
|
}
|
|
|
|
if (!Backend.exists(path))
|
|
|
|
return;
|
2022-12-20 12:51:54 +08:00
|
|
|
}
|
|
|
|
if (!Backend.isDir(path)) {
|
|
|
|
// TODO: set picture emotion
|
|
|
|
return;
|
|
|
|
}
|
2023-06-09 01:16:23 +08:00
|
|
|
const component = Qt.createComponent("../RoomElement/PixmapAnimation.qml");
|
2022-04-30 15:27:56 +08:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return;
|
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
let photo;
|
|
|
|
if (isCardId === true) {
|
|
|
|
roomScene.tableCards.forEach((v) => {
|
|
|
|
if (v.cid === id) {
|
|
|
|
photo = v;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (!photo)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
photo = getPhoto(id);
|
|
|
|
if (!photo) {
|
2023-04-27 14:15:08 +08:00
|
|
|
return null;
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
const animation = component.createObject(photo,
|
|
|
|
{ source: (OS === "Win" ? "file:///" : "") + path });
|
2022-12-20 12:51:54 +08:00
|
|
|
animation.anchors.centerIn = photo;
|
2023-01-29 18:11:41 +08:00
|
|
|
if (isCardId) {
|
|
|
|
animation.started.connect(() => photo.busy = true);
|
|
|
|
animation.finished.connect(() => {
|
|
|
|
photo.busy = false;
|
|
|
|
animation.destroy()
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
animation.finished.connect(() => animation.destroy());
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
animation.start();
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
2023-06-10 02:18:51 +08:00
|
|
|
function setCardFootnote(id, footnote) {
|
|
|
|
let card;
|
|
|
|
roomScene.tableCards.forEach((v) => {
|
|
|
|
if (v.cid === id) {
|
|
|
|
card = v;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!card) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
card.footnote = footnote;
|
|
|
|
card.footnoteVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["SetCardFootnote"] = (j) => {
|
|
|
|
const data = JSON.parse(j);
|
|
|
|
const id = data[0];
|
|
|
|
const note = data[1];
|
|
|
|
setCardFootnote(id, note);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCardVirtName(id, name) {
|
|
|
|
let card;
|
|
|
|
roomScene.tableCards.forEach((v) => {
|
|
|
|
if (v.cid === id) {
|
|
|
|
card = v;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!card) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
card.virt_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["SetCardVirtName"] = (j) => {
|
|
|
|
const data = JSON.parse(j);
|
|
|
|
const ids = data[0];
|
|
|
|
const note = data[1];
|
|
|
|
ids.forEach(id => setCardVirtName(id, note));
|
|
|
|
}
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
function changeHp(id, delta, losthp) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const photo = getPhoto(id);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (!photo) {
|
2023-04-27 14:15:08 +08:00
|
|
|
return null;
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
if (delta < 0) {
|
|
|
|
if (!losthp) {
|
|
|
|
setEmotion(id, "damage")
|
|
|
|
photo.tremble()
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function doIndicate(from, tos) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const component = Qt.createComponent("../RoomElement/IndicatorLine.qml");
|
2022-04-30 15:27:56 +08:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return;
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const fromItem = getPhotoOrDashboard(from);
|
2024-01-25 03:23:29 +08:00
|
|
|
const fromPos = mapFromItem(fromItem, fromItem.width / 2,
|
|
|
|
fromItem.height / 2);
|
2022-04-30 15:27:56 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const end = [];
|
2022-04-30 15:27:56 +08:00
|
|
|
for (let i = 0; i < tos.length; i++) {
|
|
|
|
if (from === tos[i])
|
|
|
|
continue;
|
2023-06-09 17:23:02 +08:00
|
|
|
const toItem = getPhotoOrDashboard(tos[i]);
|
|
|
|
const toPos = mapFromItem(toItem, toItem.width / 2, toItem.height / 2);
|
2022-04-30 15:27:56 +08:00
|
|
|
end.push(toPos);
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const color = "#96943D";
|
2024-01-25 03:23:29 +08:00
|
|
|
const line = component.createObject(roomScene, {
|
|
|
|
start: fromPos,
|
|
|
|
end: end,
|
|
|
|
color: color
|
|
|
|
});
|
2022-04-30 15:27:56 +08:00
|
|
|
line.finished.connect(() => line.destroy());
|
|
|
|
line.running = true;
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
2024-01-26 14:02:55 +08:00
|
|
|
function processPrompt(prompt) {
|
|
|
|
const data = prompt.split(":");
|
|
|
|
let raw = luatr(data[0]);
|
|
|
|
const src = parseInt(data[1]);
|
|
|
|
const dest = parseInt(data[2]);
|
|
|
|
if (raw.match("%src"))
|
|
|
|
raw = raw.replace(/%src/g, luatr(getPhoto(src).general));
|
|
|
|
if (raw.match("%dest"))
|
|
|
|
raw = raw.replace(/%dest/g, luatr(getPhoto(dest).general));
|
|
|
|
if (raw.match("%arg2"))
|
|
|
|
raw = raw.replace(/%arg2/g, luatr(data[4]));
|
|
|
|
if (raw.match("%arg"))
|
|
|
|
raw = raw.replace(/%arg/g, luatr(data[3]));
|
|
|
|
return raw;
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["MaxCard"] = (jsonData) => {
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const id = data.id;
|
|
|
|
const cardMax = data.pcardMax;
|
|
|
|
const photo = getPhoto(id);
|
2023-05-28 18:45:37 +08:00
|
|
|
if (photo) {
|
|
|
|
photo.maxCard = cardMax;
|
2023-05-28 17:59:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:15:08 +08:00
|
|
|
function changeSelf(id) {
|
2024-01-25 03:23:29 +08:00
|
|
|
lcall("ChangeSelf", id);
|
2023-04-27 14:15:08 +08:00
|
|
|
|
|
|
|
// move new selfPhoto to dashboard
|
|
|
|
let order = new Array(photoModel.count);
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 17:23:02 +08:00
|
|
|
const item = photoModel.get(i);
|
2023-04-27 14:15:08 +08:00
|
|
|
order[item.seatNumber - 1] = item.id;
|
|
|
|
if (item.id === Self.id) {
|
|
|
|
dashboard.self = photos.itemAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callbacks["ArrangeSeats"](JSON.stringify(order));
|
|
|
|
|
|
|
|
// update dashboard
|
|
|
|
dashboard.update();
|
|
|
|
|
|
|
|
// handle pending messages
|
|
|
|
if (mainWindow.is_pending) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = mainWindow.fetchMessage();
|
2023-04-27 14:15:08 +08:00
|
|
|
return mainWindow.handleMessage(data.command, data.jsonData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AddPlayer"] = (jsonData) => {
|
2023-06-04 19:31:44 +08:00
|
|
|
// jsonData: int id, string screenName, string avatar, bool ready
|
2022-04-30 15:27:56 +08:00
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = photoModel.get(i);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (item.id === -1) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const uid = data[0];
|
|
|
|
const name = data[1];
|
|
|
|
const avatar = data[2];
|
|
|
|
const ready = data[3];
|
2023-06-04 19:31:44 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
item.id = uid;
|
|
|
|
item.screenName = name;
|
|
|
|
item.general = avatar;
|
2023-06-04 19:31:44 +08:00
|
|
|
item.avatar = avatar;
|
|
|
|
item.ready = ready;
|
|
|
|
|
|
|
|
checkAllReady();
|
|
|
|
|
|
|
|
if (getPhoto(-1)) {
|
|
|
|
roomScene.isFull = false;
|
|
|
|
} else {
|
|
|
|
roomScene.isFull = true;
|
|
|
|
}
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
return;
|
2022-03-24 21:23:42 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-03-24 21:23:42 +08:00
|
|
|
}
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
// card: int | { skill: string, subcards: int[] }
|
|
|
|
function enableTargets(card) {
|
2022-12-18 21:19:35 +08:00
|
|
|
if (roomScene.respond_play) {
|
2024-01-25 03:23:29 +08:00
|
|
|
const candidate = (!isNaN(card) && card !== -1)
|
|
|
|
|| typeof(card) === "string";
|
2023-01-29 18:11:41 +08:00
|
|
|
if (candidate) {
|
2024-01-25 03:23:29 +08:00
|
|
|
okButton.enabled =
|
|
|
|
lcall("CardFitPattern", card, roomScene.responding_card) &&
|
|
|
|
!lcall("CardProhibitedResponse", card);
|
2023-01-29 18:11:41 +08:00
|
|
|
} else {
|
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
2022-12-18 21:19:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
let i = 0;
|
2023-06-09 01:16:23 +08:00
|
|
|
const candidate = (!isNaN(card) && card !== -1) || typeof(card) === "string";
|
|
|
|
const all_photos = [];
|
2023-04-27 14:15:08 +08:00
|
|
|
for (i = 0; i < playerNum; i++) {
|
2022-04-30 15:27:56 +08:00
|
|
|
all_photos.push(photos.itemAt(i))
|
|
|
|
}
|
|
|
|
selected_targets = [];
|
|
|
|
for (i = 0; i < playerNum; i++) {
|
|
|
|
all_photos[i].selected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (candidate) {
|
2023-06-09 17:23:02 +08:00
|
|
|
const data = {
|
2022-04-30 15:27:56 +08:00
|
|
|
ok_enabled: false,
|
|
|
|
enabled_targets: []
|
2022-03-24 21:23:42 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
photo.state = "candidate";
|
2023-06-09 01:16:23 +08:00
|
|
|
const id = photo.playerid;
|
2024-01-25 03:23:29 +08:00
|
|
|
const ret = lcall("CanUseCardToTarget", card, id, selected_targets,
|
|
|
|
JSON.stringify(roomScene.extra_data));
|
2022-04-30 15:27:56 +08:00
|
|
|
photo.selectable = ret;
|
2023-07-08 01:05:54 +08:00
|
|
|
if (roomScene.extra_data instanceof Object) {
|
2023-12-06 21:08:56 +08:00
|
|
|
const must = roomScene.extra_data.must_targets;
|
|
|
|
const included = roomScene.extra_data.include_targets;
|
2023-12-09 21:57:47 +08:00
|
|
|
const exclusive = roomScene.extra_data.exclusive_targets;
|
|
|
|
if (exclusive instanceof Array) {
|
|
|
|
if (exclusive.indexOf(id) === -1) photo.selectable = false;
|
2023-07-08 01:05:54 +08:00
|
|
|
}
|
2023-12-06 21:08:56 +08:00
|
|
|
if (must instanceof Array) {
|
|
|
|
if (must.filter((val) => {
|
|
|
|
return selected_targets.indexOf(val) === -1;
|
|
|
|
}).length !== 0 && must.indexOf(id) === -1) photo.selectable = false;
|
|
|
|
}
|
|
|
|
if (included instanceof Array) {
|
|
|
|
if (included.filter((val) => {
|
|
|
|
return selected_targets.indexOf(val) !== -1;
|
2024-01-25 03:23:29 +08:00
|
|
|
}).length === 0 && included.indexOf(id) === -1)
|
|
|
|
photo.selectable = false;
|
2023-12-06 21:08:56 +08:00
|
|
|
}
|
2023-07-08 01:05:54 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
})
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
okButton.enabled = lcall("CardFeasible", card, selected_targets);
|
2023-01-29 18:11:41 +08:00
|
|
|
if (okButton.enabled && roomScene.state === "responding") {
|
2024-01-25 03:23:29 +08:00
|
|
|
okButton.enabled =
|
|
|
|
lcall("CardFitPattern", card, roomScene.responding_card) &&
|
|
|
|
(roomScene.autoPending || !lcall("CardProhibitedUse", card));
|
2023-06-09 01:16:23 +08:00
|
|
|
} else if (okButton.enabled && roomScene.state === "playing") {
|
2024-01-25 03:23:29 +08:00
|
|
|
okButton.enabled = lcall("CanUseCard", card, Self.id,
|
|
|
|
JSON.stringify(roomScene.extra_data));
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
2023-01-16 19:13:07 +08:00
|
|
|
if (okButton.enabled) {
|
|
|
|
if (roomScene.extra_data instanceof Object) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const must = roomScene.extra_data.must_targets;
|
2023-12-06 21:08:56 +08:00
|
|
|
const included = roomScene.extra_data.include_targets;
|
2023-01-16 19:13:07 +08:00
|
|
|
if (must instanceof Array) {
|
2023-12-06 21:08:56 +08:00
|
|
|
if(must.length === 0) okButton.enabled = false;
|
|
|
|
}
|
|
|
|
if (included instanceof Array) {
|
|
|
|
if (included.length === 0) okButton.enabled = false;
|
2023-01-16 19:13:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
} else {
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
photo.state = "normal";
|
|
|
|
photo.selected = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateSelectedTargets(playerid, selected) {
|
|
|
|
let i = 0;
|
2023-06-09 01:16:23 +08:00
|
|
|
const card = dashboard.getSelectedCard();
|
|
|
|
const candidate = (!isNaN(card) && card !== -1) || typeof(card) === "string";
|
|
|
|
const all_photos = [];
|
2023-04-27 14:15:08 +08:00
|
|
|
for (i = 0; i < playerNum; i++) {
|
2022-04-30 15:27:56 +08:00
|
|
|
all_photos.push(photos.itemAt(i))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
selected_targets.push(playerid);
|
|
|
|
} else {
|
|
|
|
selected_targets.splice(selected_targets.indexOf(playerid), 1);
|
|
|
|
}
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
if (candidate) {
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
if (photo.selected) return;
|
2023-06-09 01:16:23 +08:00
|
|
|
const id = photo.playerid;
|
2024-01-25 03:23:29 +08:00
|
|
|
const ret = lcall("CanUseCardToTarget", card, id, selected_targets,
|
|
|
|
JSON.stringify(roomScene.extra_data));
|
2022-09-14 13:01:10 +08:00
|
|
|
photo.selectable = ret;
|
2023-08-02 02:19:51 +08:00
|
|
|
if (roomScene.extra_data instanceof Object) {
|
2023-12-06 21:08:56 +08:00
|
|
|
const must = roomScene.extra_data.must_targets;
|
|
|
|
const included = roomScene.extra_data.include_targets;
|
2023-12-09 21:57:47 +08:00
|
|
|
const exclusive = roomScene.extra_data.exclusive_targets;
|
|
|
|
if (exclusive instanceof Array) {
|
|
|
|
if (exclusive.indexOf(id) === -1) photo.selectable = false;
|
2023-08-02 02:19:51 +08:00
|
|
|
}
|
2023-12-06 21:08:56 +08:00
|
|
|
if (must instanceof Array) {
|
|
|
|
if (must.filter((val) => {
|
|
|
|
return selected_targets.indexOf(val) === -1;
|
|
|
|
}).length !== 0 && must.indexOf(id) === -1) photo.selectable = false;
|
|
|
|
}
|
|
|
|
if (included instanceof Array) {
|
|
|
|
if (included.filter((val) => {
|
|
|
|
return selected_targets.indexOf(val) !== -1;
|
2024-01-25 03:23:29 +08:00
|
|
|
}).length === 0 && included.indexOf(id) === -1)
|
|
|
|
photo.selectable = false;
|
2023-12-06 21:08:56 +08:00
|
|
|
}
|
2023-08-02 02:19:51 +08:00
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
})
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
okButton.enabled = lcall("CardFeasible", card, selected_targets);
|
2023-01-29 18:11:41 +08:00
|
|
|
if (okButton.enabled && roomScene.state === "responding") {
|
2024-01-25 03:23:29 +08:00
|
|
|
okButton.enabled =
|
|
|
|
lcall("CardFitPattern", card, roomScene.responding_card) &&
|
|
|
|
(roomScene.autoPending || !lcall("CardProhibitedUse", card));
|
2023-06-09 01:16:23 +08:00
|
|
|
} else if (okButton.enabled && roomScene.state === "playing") {
|
2024-01-25 03:23:29 +08:00
|
|
|
okButton.enabled = lcall("CanUseCard", card, Self.id,
|
|
|
|
JSON.stringify(roomScene.extra_data));
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
2023-01-16 19:13:07 +08:00
|
|
|
if (okButton.enabled) {
|
|
|
|
if (roomScene.extra_data instanceof Object) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const must = roomScene.extra_data.must_targets;
|
2023-12-06 21:08:56 +08:00
|
|
|
const included = roomScene.extra_data.include_targets;
|
2023-01-16 19:13:07 +08:00
|
|
|
if (must instanceof Array) {
|
2023-12-06 21:08:56 +08:00
|
|
|
if (must.filter((val) => {
|
2023-01-16 19:13:07 +08:00
|
|
|
return selected_targets.indexOf(val) === -1;
|
2023-12-06 21:08:56 +08:00
|
|
|
}).length !== 0) okButton.enabled = false;
|
|
|
|
}
|
|
|
|
if (included instanceof Array) {
|
|
|
|
if (included.filter((val) => {
|
|
|
|
return selected_targets.indexOf(val) !== -1;
|
|
|
|
}).length === 0) okButton.enabled = false;
|
2023-01-16 19:13:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
} else {
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
photo.state = "normal";
|
|
|
|
photo.selected = false;
|
|
|
|
});
|
2022-04-30 15:27:56 +08:00
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["RemovePlayer"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int uid
|
2023-06-09 01:16:23 +08:00
|
|
|
const uid = JSON.parse(jsonData)[0];
|
|
|
|
const model = getPhotoModel(uid);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model.id = -1;
|
|
|
|
model.screenName = "";
|
|
|
|
model.general = "";
|
2023-06-04 19:31:44 +08:00
|
|
|
model.isOwner = false;
|
|
|
|
roomScene.isFull = false;
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-03-24 21:23:42 +08:00
|
|
|
}
|
2022-03-27 14:49:41 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["RoomOwner"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int uid of the owner
|
2023-06-09 01:16:23 +08:00
|
|
|
const uid = JSON.parse(jsonData)[0];
|
2022-03-30 14:14:40 +08:00
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
roomScene.isOwner = (Self.id === uid);
|
2022-03-30 14:14:40 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const model = getPhotoModel(uid);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model.isOwner = true;
|
|
|
|
}
|
2022-03-27 14:49:41 +08:00
|
|
|
}
|
2022-03-28 22:24:30 +08:00
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
function checkAllReady() {
|
|
|
|
let allReady = true;
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = photoModel.get(i);
|
2023-06-04 19:31:44 +08:00
|
|
|
if (!item.isOwner && !item.ready) {
|
|
|
|
allReady = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
roomScene.isAllReady = allReady;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["ReadyChanged"] = (j) => {
|
|
|
|
const data = JSON.parse(j);
|
|
|
|
const id = data[0];
|
|
|
|
const ready = data[1];
|
|
|
|
|
|
|
|
if (id === Self.id) {
|
|
|
|
roomScene.isReady = ready === 1;
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const model = getPhotoModel(id);
|
2023-06-04 19:31:44 +08:00
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model.ready = ready ? true : false;
|
|
|
|
checkAllReady();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["NetStateChanged"] = (j) => {
|
|
|
|
const data = JSON.parse(j);
|
|
|
|
const id = data[0];
|
|
|
|
let state = data[1];
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const model = getPhotoModel(id);
|
|
|
|
if (state === "run" && model.dead) {
|
2023-06-04 19:31:44 +08:00
|
|
|
state = "leave";
|
|
|
|
}
|
|
|
|
model.netstate = state;
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["PropertyUpdate"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int id, string property_name, value
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const uid = data[0];
|
|
|
|
const property_name = data[1];
|
2023-08-13 02:25:04 +08:00
|
|
|
let value = data[2];
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
let model = getPhotoModel(uid);
|
2023-06-04 19:31:44 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
if (typeof(model) !== "undefined") {
|
2023-08-13 02:25:04 +08:00
|
|
|
if (property_name == "sealedSlots")
|
|
|
|
value = JSON.stringify(value); // 辣鸡qml
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
model[property_name] = value;
|
|
|
|
}
|
2023-07-16 15:32:16 +08:00
|
|
|
|
|
|
|
if (property_name === "phase") {
|
|
|
|
let item = getPhoto(uid);
|
|
|
|
item.playing = value < 8; // Player.NotActive
|
|
|
|
}
|
2022-03-28 22:24:30 +08:00
|
|
|
}
|
|
|
|
|
2023-06-23 22:18:11 +08:00
|
|
|
callbacks["UpdateCard"] = (j) => {
|
|
|
|
const id = parseInt(j);
|
|
|
|
let card;
|
|
|
|
roomScene.tableCards.forEach((v) => {
|
|
|
|
if (v.cid === id) {
|
|
|
|
card = v;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!card) {
|
|
|
|
roomScene.dashboard.handcardArea.cards.forEach((v) => {
|
|
|
|
if (v.cid === id) {
|
|
|
|
card = v;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!card) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
card.setData(lcall("GetCardData", id));
|
2023-06-23 22:18:11 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["StartGame"] = (jsonData) => {
|
2023-04-27 14:15:08 +08:00
|
|
|
roomScene.isStarted = true;
|
|
|
|
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = photoModel.get(i);
|
2023-06-04 19:31:44 +08:00
|
|
|
item.ready = false;
|
2023-04-27 14:15:08 +08:00
|
|
|
item.general = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["ArrangeSeats"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: seat order
|
2023-06-09 01:16:23 +08:00
|
|
|
const order = JSON.parse(jsonData);
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = photoModel.get(i);
|
2022-04-30 15:27:56 +08:00
|
|
|
item.seatNumber = order.indexOf(item.id) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make Self to the first of list, then reorder photomodel
|
2023-06-09 01:16:23 +08:00
|
|
|
const selfIndex = order.indexOf(Self.id);
|
|
|
|
const after = order.splice(selfIndex);
|
2022-04-30 15:27:56 +08:00
|
|
|
after.push(...order);
|
2023-06-09 01:16:23 +08:00
|
|
|
const photoOrder = after;
|
2022-04-30 15:27:56 +08:00
|
|
|
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = photoModel.get(i);
|
2022-04-30 15:27:56 +08:00
|
|
|
item.index = photoOrder.indexOf(item.id);
|
|
|
|
}
|
2023-02-26 16:51:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
arrangePhotos();
|
2022-03-28 22:24:30 +08:00
|
|
|
}
|
2022-03-30 14:14:40 +08:00
|
|
|
|
|
|
|
function cancelAllFocus() {
|
2022-04-30 15:27:56 +08:00
|
|
|
let item;
|
2023-04-27 14:15:08 +08:00
|
|
|
for (let i = 0; i < playerNum; i++) {
|
2022-04-30 15:27:56 +08:00
|
|
|
item = photos.itemAt(i);
|
|
|
|
item.progressBar.visible = false;
|
|
|
|
item.progressTip = "";
|
|
|
|
}
|
2022-03-30 14:14:40 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["MoveFocus"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int[] focuses, string command
|
|
|
|
cancelAllFocus();
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const focuses = data[0];
|
|
|
|
const command = data[1];
|
2023-02-26 16:51:29 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
let item, model;
|
2023-04-27 14:15:08 +08:00
|
|
|
for (let i = 0; i < playerNum; i++) {
|
2022-04-30 15:27:56 +08:00
|
|
|
model = photoModel.get(i);
|
|
|
|
if (focuses.indexOf(model.id) != -1) {
|
|
|
|
item = photos.itemAt(i);
|
|
|
|
item.progressBar.visible = true;
|
2024-01-25 03:23:29 +08:00
|
|
|
item.progressTip = luatr(command)
|
|
|
|
+ luatr(" thinking...");
|
2022-05-01 18:37:13 +08:00
|
|
|
|
2023-07-16 15:32:16 +08:00
|
|
|
/*
|
2022-05-01 18:37:13 +08:00
|
|
|
if (command === "PlayCard") {
|
|
|
|
item.playing = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
item = photos.itemAt(i);
|
|
|
|
if (command === "PlayCard") {
|
|
|
|
item.playing = false;
|
|
|
|
}
|
2023-07-16 15:32:16 +08:00
|
|
|
*/
|
2022-05-01 18:37:13 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-30 14:14:40 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["PlayerRunned"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int runner, int robot
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const runner = data[0];
|
|
|
|
const robot = data[1];
|
2022-04-30 15:27:56 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const model = getPhotoModel(runner);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model.id = robot;
|
|
|
|
}
|
2022-04-03 06:41:55 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForGeneral"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: string[] Generals
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const generals = data[0];
|
|
|
|
const n = data[1];
|
2023-08-24 21:37:06 +08:00
|
|
|
const convert = data[2];
|
|
|
|
const heg = data[3];
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.setPrompt(luatr("#AskForGeneral"), true);
|
2022-04-30 15:27:56 +08:00
|
|
|
roomScene.state = "replying";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/ChooseGeneralBox.qml");
|
2023-06-09 01:16:23 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
2022-04-30 15:27:56 +08:00
|
|
|
box.accepted.connect(() => {
|
2023-04-19 14:07:16 +08:00
|
|
|
replyToServer(JSON.stringify(box.choices));
|
2022-04-30 15:27:56 +08:00
|
|
|
});
|
2023-04-19 14:07:16 +08:00
|
|
|
box.choiceNum = n;
|
2023-08-24 21:37:06 +08:00
|
|
|
box.convertDisabled = !!convert;
|
2023-04-23 21:10:07 +08:00
|
|
|
box.needSameKingdom = !!heg;
|
2023-04-19 14:07:16 +08:00
|
|
|
for (let i = 0; i < generals.length; i++)
|
|
|
|
box.generalList.append({ "name": generals[i] });
|
2022-04-30 15:27:56 +08:00
|
|
|
box.updatePosition();
|
2022-03-30 14:14:40 +08:00
|
|
|
}
|
2022-04-02 15:11:13 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForSkillInvoke"] = (jsonData) => {
|
2023-04-04 15:59:21 +08:00
|
|
|
// jsonData: [ string name, string prompt ]
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const skill = data[0];
|
|
|
|
const prompt = data[1];
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.promptText = prompt ? processPrompt(prompt)
|
2024-01-25 03:23:29 +08:00
|
|
|
: luatr("#AskForSkillInvoke").arg(luatr(skill));
|
2022-12-18 12:52:52 +08:00
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.okCancel.visible = true;
|
|
|
|
roomScene.okButton.enabled = true;
|
|
|
|
roomScene.cancelButton.enabled = true;
|
2022-04-02 15:11:13 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForGuanxing"] = (jsonData) => {
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const cards = [];
|
|
|
|
const min_top_cards = data.min_top_cards;
|
|
|
|
const max_top_cards = data.max_top_cards;
|
|
|
|
const min_bottom_cards = data.min_bottom_cards;
|
|
|
|
const max_bottom_cards = data.max_bottom_cards;
|
|
|
|
const top_area_name = data.top_area_name;
|
|
|
|
const bottom_area_name = data.bottom_area_name;
|
2023-06-19 00:20:50 +08:00
|
|
|
const prompt = data.prompt;
|
2023-01-29 18:11:41 +08:00
|
|
|
roomScene.state = "replying";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/GuanxingBox.qml");
|
|
|
|
data.cards.forEach(id => cards.push(lcall("GetCardData", id)));
|
2023-06-09 01:16:23 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
2023-06-19 00:20:50 +08:00
|
|
|
box.prompt = prompt;
|
2023-06-09 01:16:23 +08:00
|
|
|
if (max_top_cards === 0) {
|
2023-04-25 19:02:17 +08:00
|
|
|
box.areaCapacities = [max_bottom_cards];
|
|
|
|
box.areaLimits = [min_bottom_cards];
|
2024-01-25 03:23:29 +08:00
|
|
|
box.areaNames = [luatr(bottom_area_name)];
|
2023-04-25 19:02:17 +08:00
|
|
|
} else {
|
2023-08-02 02:19:51 +08:00
|
|
|
if (max_bottom_cards === 0) {
|
|
|
|
box.areaCapacities = [max_top_cards];
|
|
|
|
box.areaLimits = [min_top_cards];
|
2024-01-25 03:23:29 +08:00
|
|
|
box.areaNames = [luatr(top_area_name)];
|
2023-08-02 02:19:51 +08:00
|
|
|
} else {
|
|
|
|
box.areaCapacities = [max_top_cards, max_bottom_cards];
|
|
|
|
box.areaLimits = [min_top_cards, min_bottom_cards];
|
2024-01-25 03:23:29 +08:00
|
|
|
box.areaNames = [luatr(top_area_name), luatr(bottom_area_name)];
|
2023-08-02 02:19:51 +08:00
|
|
|
}
|
2023-04-25 19:02:17 +08:00
|
|
|
}
|
2023-01-29 18:11:41 +08:00
|
|
|
box.cards = cards;
|
|
|
|
box.arrangeCards();
|
|
|
|
box.accepted.connect(() => {
|
|
|
|
replyToServer(JSON.stringify(box.getResult()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForExchange"] = (jsonData) => {
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const cards = [];
|
|
|
|
const cards_name = [];
|
|
|
|
const capacities = [];
|
|
|
|
const limits = [];
|
2023-06-07 13:02:53 +08:00
|
|
|
roomScene.state = "replying";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/GuanxingBox.qml");
|
2023-06-07 13:02:53 +08:00
|
|
|
let for_i = 0;
|
2023-06-09 01:16:23 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
2023-06-07 13:02:53 +08:00
|
|
|
data.piles.forEach(ids => {
|
2023-06-09 01:16:23 +08:00
|
|
|
if (ids.length > 0) {
|
2024-01-25 03:23:29 +08:00
|
|
|
ids.forEach(id => cards.push(lcall("GetCardData", id)));
|
2023-06-09 01:16:23 +08:00
|
|
|
capacities.push(ids.length);
|
|
|
|
limits.push(0);
|
2024-01-25 03:23:29 +08:00
|
|
|
cards_name.push(luatr(data.piles_name[for_i]));
|
2023-06-09 01:16:23 +08:00
|
|
|
for_i ++;
|
|
|
|
}
|
2023-06-07 13:02:53 +08:00
|
|
|
});
|
|
|
|
box.areaCapacities = capacities
|
|
|
|
box.areaLimits = limits
|
|
|
|
box.areaNames = cards_name
|
|
|
|
box.cards = cards;
|
|
|
|
box.arrangeCards();
|
|
|
|
box.accepted.connect(() => {
|
|
|
|
replyToServer(JSON.stringify(box.getResult()));
|
|
|
|
});
|
|
|
|
}
|
2023-07-16 15:29:20 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForChoice"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: [ string[] choices, string skill ]
|
|
|
|
// TODO: multiple choices, e.g. benxi_ol
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const choices = data[0];
|
2023-07-16 15:29:20 +08:00
|
|
|
const all_choices = data[1];
|
|
|
|
const skill_name = data[2];
|
|
|
|
const prompt = data[3];
|
|
|
|
const detailed = data[4];
|
2023-01-29 18:11:41 +08:00
|
|
|
if (prompt === "") {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.promptText = luatr("#AskForChoice")
|
|
|
|
.arg(luatr(skill_name));
|
2023-01-29 18:11:41 +08:00
|
|
|
} else {
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.setPrompt(processPrompt(prompt), true);
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
roomScene.state = "replying";
|
2023-06-10 02:18:51 +08:00
|
|
|
let qmlSrc;
|
|
|
|
if (!detailed) {
|
|
|
|
qmlSrc = "../RoomElement/ChoiceBox.qml";
|
|
|
|
} else {
|
|
|
|
qmlSrc = "../RoomElement/DetailedChoiceBox.qml";
|
|
|
|
}
|
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent(qmlSrc);
|
2023-06-09 01:16:23 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
2022-04-30 15:27:56 +08:00
|
|
|
box.options = choices;
|
|
|
|
box.skill_name = skill_name;
|
2023-07-16 15:29:20 +08:00
|
|
|
box.all_options = all_choices;
|
2022-04-30 15:27:56 +08:00
|
|
|
box.accepted.connect(() => {
|
2023-08-02 02:19:51 +08:00
|
|
|
replyToServer(all_choices[box.result]);
|
2022-04-30 15:27:56 +08:00
|
|
|
});
|
2022-04-02 15:11:13 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2023-12-06 21:07:35 +08:00
|
|
|
callbacks["AskForChoices"] = (jsonData) => {
|
2023-11-07 12:57:00 +08:00
|
|
|
// jsonData: [ string[] choices, string skill ]
|
|
|
|
// TODO: multiple choices, e.g. benxi_ol
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const choices = data[0];
|
|
|
|
const all_choices = data[1];
|
|
|
|
const min_num = data[2][0];
|
|
|
|
const max_num = data[2][1];
|
|
|
|
const cancelable = data[3];
|
|
|
|
const skill_name = data[4];
|
|
|
|
const prompt = data[5];
|
|
|
|
const detailed = data[6];
|
|
|
|
if (prompt === "") {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.promptText = luatr("#AskForChoices")
|
|
|
|
.arg(luatr(skill_name));
|
2023-11-07 12:57:00 +08:00
|
|
|
} else {
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.setPrompt(processPrompt(prompt), true);
|
2023-11-07 12:57:00 +08:00
|
|
|
}
|
|
|
|
roomScene.state = "replying";
|
|
|
|
let qmlSrc;
|
|
|
|
if (!detailed) {
|
|
|
|
qmlSrc = "../RoomElement/CheckBox.qml";
|
|
|
|
} else {
|
|
|
|
qmlSrc = "../RoomElement/DetailedCheckBox.qml";
|
|
|
|
}
|
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent(qmlSrc);
|
|
|
|
const box = roomScene.popupBox.item;
|
|
|
|
box.options = choices;
|
|
|
|
box.skill_name = skill_name;
|
|
|
|
box.all_options = all_choices;
|
|
|
|
box.min_num = min_num;
|
|
|
|
box.max_num = max_num;
|
|
|
|
box.cancelable = cancelable;
|
|
|
|
box.accepted.connect(() => {
|
|
|
|
const ret = [];
|
|
|
|
box.result.forEach(id => {
|
|
|
|
ret.push(all_choices[id]);
|
|
|
|
});
|
|
|
|
replyToServer(JSON.stringify(ret));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForCardChosen"] = (jsonData) => {
|
2022-09-14 13:01:10 +08:00
|
|
|
// jsonData: [ int[] handcards, int[] equips, int[] delayedtricks,
|
|
|
|
// string reason ]
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
2023-08-24 21:37:24 +08:00
|
|
|
const reason = data._reason;
|
2023-11-07 21:14:51 +08:00
|
|
|
const prompt = data._prompt;
|
|
|
|
if (prompt === "") {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.promptText = luatr("#AskForChooseCard")
|
|
|
|
.arg(luatr(reason));
|
2023-11-07 21:14:51 +08:00
|
|
|
} else {
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.setPrompt(processPrompt(prompt), true);
|
2023-11-07 21:14:51 +08:00
|
|
|
}
|
2022-09-14 13:01:10 +08:00
|
|
|
roomScene.state = "replying";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/PlayerCardBox.qml");
|
2023-08-24 21:37:24 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
2023-11-07 21:14:51 +08:00
|
|
|
box.prompt = prompt;
|
2023-08-24 21:37:24 +08:00
|
|
|
for (let d of data.card_data) {
|
|
|
|
const arr = [];
|
|
|
|
const ids = d[1];
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
ids.forEach(id => arr.push(lcall("GetCardData", id)));
|
2023-08-24 21:37:24 +08:00
|
|
|
box.addCustomCards(d[0], arr);
|
|
|
|
}
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
roomScene.popupBox.moveToCenter();
|
2024-01-25 03:23:29 +08:00
|
|
|
box.cardSelected.connect(cid => replyToServer(cid));
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForCardsChosen"] = (jsonData) => {
|
2023-03-01 21:41:16 +08:00
|
|
|
// jsonData: [ int[] handcards, int[] equips, int[] delayedtricks,
|
|
|
|
// int min, int max, string reason ]
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
2023-08-24 21:37:24 +08:00
|
|
|
const min = data._min;
|
|
|
|
const max = data._max;
|
|
|
|
const reason = data._reason;
|
2023-11-07 21:14:51 +08:00
|
|
|
const prompt = data._prompt;
|
|
|
|
if (prompt === "") {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.promptText = luatr("#AskForChooseCards")
|
|
|
|
.arg(luatr(reason)).arg(min).arg(max);
|
2023-11-07 21:14:51 +08:00
|
|
|
} else {
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.setPrompt(processPrompt(prompt), true);
|
2023-11-07 21:14:51 +08:00
|
|
|
}
|
|
|
|
|
2023-03-01 21:41:16 +08:00
|
|
|
roomScene.state = "replying";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/PlayerCardBox.qml");
|
2023-06-09 01:16:23 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
2023-03-01 21:41:16 +08:00
|
|
|
box.multiChoose = true;
|
|
|
|
box.min = min;
|
|
|
|
box.max = max;
|
2023-11-07 21:14:51 +08:00
|
|
|
box.prompt = prompt;
|
2023-08-24 21:37:24 +08:00
|
|
|
for (let d of data.card_data) {
|
|
|
|
const arr = [];
|
|
|
|
const ids = d[1];
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
ids.forEach(id => arr.push(lcall("GetCardData", id)));
|
2023-08-24 21:37:24 +08:00
|
|
|
box.addCustomCards(d[0], arr);
|
|
|
|
}
|
|
|
|
|
2023-03-01 21:41:16 +08:00
|
|
|
roomScene.popupBox.moveToCenter();
|
|
|
|
box.cardsSelected.connect((ids) => {
|
|
|
|
replyToServer(JSON.stringify(ids));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-19 14:27:54 +08:00
|
|
|
callbacks["AskForPoxi"] = (jsonData) => {
|
2023-10-27 22:19:30 +08:00
|
|
|
const { type, data, extra_data, cancelable } = JSON.parse(jsonData);
|
2023-09-19 14:27:54 +08:00
|
|
|
|
|
|
|
roomScene.state = "replying";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/PoxiBox.qml");
|
2023-09-19 14:27:54 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
|
|
|
box.poxi_type = type;
|
|
|
|
box.card_data = data;
|
2023-10-27 22:19:30 +08:00
|
|
|
box.extra_data = extra_data;
|
|
|
|
box.cancelable = cancelable;
|
2023-09-19 14:27:54 +08:00
|
|
|
for (let d of data) {
|
|
|
|
const arr = [];
|
|
|
|
const ids = d[1];
|
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
ids.forEach(id => arr.push(lcall("GetCardData", id)));
|
2023-09-19 14:27:54 +08:00
|
|
|
box.addCustomCards(d[0], arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
roomScene.popupBox.moveToCenter();
|
|
|
|
box.cardsSelected.connect((ids) => {
|
|
|
|
replyToServer(JSON.stringify(ids));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForMoveCardInBoard"] = (jsonData) => {
|
2023-05-20 16:00:03 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
2023-07-16 19:18:43 +08:00
|
|
|
const { cards, cardsPosition, generalNames, playerIds } = data;
|
2023-05-20 16:00:03 +08:00
|
|
|
|
|
|
|
roomScene.state = "replying";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/MoveCardInBoardBox.qml");
|
2023-05-20 16:00:03 +08:00
|
|
|
|
|
|
|
const boxCards = [];
|
|
|
|
cards.forEach(id => {
|
2023-07-16 19:18:43 +08:00
|
|
|
const cardPos = cardsPosition[cards.findIndex(cid => cid === id)];
|
2024-01-25 03:23:29 +08:00
|
|
|
const d = lcall("GetCardData", id, playerIds[cardPos]);
|
|
|
|
boxCards.push(d);
|
2023-05-20 16:00:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const box = roomScene.popupBox.item;
|
|
|
|
box.cards = boxCards;
|
|
|
|
box.cardsPosition = cardsPosition;
|
2023-07-16 19:18:43 +08:00
|
|
|
box.playerIds = playerIds;
|
2023-05-20 16:00:03 +08:00
|
|
|
box.generalNames = generalNames.map(name => {
|
|
|
|
const namesSplited = name.split('/');
|
2024-01-25 03:23:29 +08:00
|
|
|
if (namesSplited.length > 1) {
|
|
|
|
return namesSplited.map(nameSplited => luatr(nameSplited)).join('/');
|
|
|
|
}
|
|
|
|
return luatr(name);
|
2023-05-20 16:00:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
box.arrangeCards();
|
|
|
|
box.accepted.connect(() => {
|
|
|
|
replyToServer(JSON.stringify(box.getResult()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["MoveCards"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: merged moves
|
2023-06-09 01:16:23 +08:00
|
|
|
const moves = JSON.parse(jsonData);
|
2022-04-30 15:27:56 +08:00
|
|
|
moveCards(moves);
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["PlayCard"] = (jsonData) => {
|
2022-04-30 15:27:56 +08:00
|
|
|
// jsonData: int playerId
|
2023-06-09 01:16:23 +08:00
|
|
|
const playerId = parseInt(jsonData);
|
|
|
|
if (playerId === Self.id) {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.setPrompt(luatr("#PlayCard"), true);
|
2022-04-30 15:27:56 +08:00
|
|
|
roomScene.state = "playing";
|
2022-09-14 13:01:10 +08:00
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["LoseSkill"] = (jsonData) => {
|
2022-09-14 13:01:10 +08:00
|
|
|
// jsonData: [ int player_id, string skill_name ]
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const id = data[0];
|
|
|
|
const skill_name = data[1];
|
|
|
|
const prelight = data[2];
|
2022-09-14 13:01:10 +08:00
|
|
|
if (id === Self.id) {
|
2023-04-23 21:10:07 +08:00
|
|
|
dashboard.loseSkill(skill_name, prelight);
|
2022-09-14 13:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AddSkill"] = (jsonData) => {
|
2022-09-14 13:01:10 +08:00
|
|
|
// jsonData: [ int player_id, string skill_name ]
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const id = data[0];
|
|
|
|
const skill_name = data[1];
|
|
|
|
const prelight = data[2];
|
2022-09-14 13:01:10 +08:00
|
|
|
if (id === Self.id) {
|
2023-04-23 21:10:07 +08:00
|
|
|
dashboard.addSkill(skill_name, prelight);
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-09-15 11:17:13 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["PrelightSkill"] = (jsonData) => {
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const skill_name = data[0];
|
|
|
|
const prelight = data[1];
|
2023-04-23 21:10:07 +08:00
|
|
|
|
|
|
|
dashboard.prelightSkill(skill_name, prelight);
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForUseActiveSkill"] = (jsonData) => {
|
2022-09-15 11:17:13 +08:00
|
|
|
// jsonData: string skill_name, string prompt
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const skill_name = data[0];
|
|
|
|
const prompt = data[1];
|
|
|
|
const cancelable = data[2];
|
|
|
|
const extra_data = data[3] ?? {};
|
2022-09-15 11:17:13 +08:00
|
|
|
if (prompt === "") {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.promptText = luatr("#AskForUseActiveSkill")
|
|
|
|
.arg(luatr(skill_name));
|
2023-01-29 18:11:41 +08:00
|
|
|
} else {
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.setPrompt(processPrompt(prompt), true);
|
2022-09-15 11:17:13 +08:00
|
|
|
}
|
|
|
|
|
2022-12-18 21:19:35 +08:00
|
|
|
roomScene.respond_play = false;
|
2022-09-15 11:17:13 +08:00
|
|
|
roomScene.state = "responding";
|
2023-06-04 19:40:14 +08:00
|
|
|
|
2024-01-25 03:23:29 +08:00
|
|
|
if (lcall('GetSkillData', skill_name).isViewAsSkill) {
|
2023-06-04 19:40:14 +08:00
|
|
|
roomScene.responding_card = ".";
|
|
|
|
}
|
|
|
|
|
2023-04-20 00:19:48 +08:00
|
|
|
roomScene.autoPending = true;
|
2023-05-19 23:03:39 +08:00
|
|
|
roomScene.extra_data = extra_data;
|
|
|
|
// dashboard.startPending(skill_name);
|
|
|
|
roomScene.activateSkill(skill_name, true);
|
2022-09-15 11:17:13 +08:00
|
|
|
cancelButton.enabled = cancelable;
|
|
|
|
}
|
2022-12-18 12:52:52 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["CancelRequest"] = () => {
|
2022-12-18 12:52:52 +08:00
|
|
|
roomScene.state = "notactive";
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["GameLog"] = (jsonData) => {
|
2022-12-18 12:52:52 +08:00
|
|
|
roomScene.addToLog(jsonData)
|
|
|
|
}
|
2022-12-18 21:19:35 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForUseCard"] = (jsonData) => {
|
2023-01-16 19:13:07 +08:00
|
|
|
// jsonData: card, pattern, prompt, cancelable, {}
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const cardname = data[0];
|
|
|
|
const pattern = data[1];
|
|
|
|
const prompt = data[2];
|
|
|
|
const extra_data = data[4];
|
2023-12-10 18:55:16 +08:00
|
|
|
const disabledSkillNames = data[5];
|
2023-01-16 19:13:07 +08:00
|
|
|
if (extra_data != null) {
|
2024-01-25 03:23:29 +08:00
|
|
|
if (extra_data.effectTo !== Self.id &&
|
|
|
|
roomScene.skippedUseEventId.find(id => id === extra_data.useEventId)) {
|
2023-07-16 19:18:43 +08:00
|
|
|
doCancelButton();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
roomScene.extra_data = extra_data;
|
|
|
|
}
|
2023-01-16 19:13:07 +08:00
|
|
|
}
|
2022-12-18 21:19:35 +08:00
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
if (prompt === "") {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.promptText = luatr("#AskForUseCard")
|
|
|
|
.arg(luatr(cardname));
|
2023-01-29 18:11:41 +08:00
|
|
|
} else {
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.setPrompt(processPrompt(prompt), true);
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
2023-01-16 19:13:07 +08:00
|
|
|
roomScene.responding_card = pattern;
|
2022-12-18 21:19:35 +08:00
|
|
|
roomScene.respond_play = false;
|
2023-12-10 18:55:16 +08:00
|
|
|
disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames);
|
2022-12-18 21:19:35 +08:00
|
|
|
roomScene.state = "responding";
|
|
|
|
okButton.enabled = false;
|
|
|
|
cancelButton.enabled = true;
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["AskForResponseCard"] = (jsonData) => {
|
2023-01-16 19:13:07 +08:00
|
|
|
// jsonData: card_name, pattern, prompt, cancelable, {}
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const cardname = data[0];
|
|
|
|
const pattern = data[1];
|
|
|
|
const prompt = data[2];
|
2023-12-10 18:55:16 +08:00
|
|
|
const disabledSkillNames = data[5];
|
2022-12-18 21:19:35 +08:00
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
if (prompt === "") {
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.promptText = luatr("#AskForResponseCard")
|
|
|
|
.arg(luatr(cardname));
|
2023-01-29 18:11:41 +08:00
|
|
|
} else {
|
2024-01-26 14:02:55 +08:00
|
|
|
roomScene.setPrompt(processPrompt(prompt), true);
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
2023-01-16 19:13:07 +08:00
|
|
|
roomScene.responding_card = pattern;
|
2022-12-18 21:19:35 +08:00
|
|
|
roomScene.respond_play = true;
|
2023-12-10 18:55:16 +08:00
|
|
|
disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames);
|
2022-12-18 21:19:35 +08:00
|
|
|
roomScene.state = "responding";
|
|
|
|
okButton.enabled = false;
|
|
|
|
cancelButton.enabled = true;
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["WaitForNullification"] = () => {
|
2022-12-18 21:19:35 +08:00
|
|
|
roomScene.state = "notactive";
|
|
|
|
}
|
2022-12-20 12:51:54 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["SetPlayerMark"] = (jsonData) => {
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const player = getPhoto(data[0]);
|
|
|
|
const mark = data[1];
|
2023-12-06 21:07:35 +08:00
|
|
|
const value = data[2] instanceof Object ? data[2] : data[2].toString();
|
2023-08-13 01:39:45 +08:00
|
|
|
let area = mark.startsWith("@!") ? player.picMarkArea : player.markArea;
|
2023-06-09 17:23:02 +08:00
|
|
|
if (data[2] === 0) {
|
2023-08-13 01:39:45 +08:00
|
|
|
area.removeMark(mark);
|
2023-02-15 19:54:35 +08:00
|
|
|
} else {
|
2023-08-13 01:39:45 +08:00
|
|
|
area.setMark(mark, mark.startsWith("@@") ? "" : value);
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 21:07:35 +08:00
|
|
|
callbacks["SetBanner"] = (jsonData) => {
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const mark = data[0];
|
|
|
|
const value = data[1] instanceof Object ? data[1] : data[1].toString();
|
|
|
|
let area = roomScene.banner;
|
|
|
|
if (data[1] === 0) {
|
|
|
|
area.removeMark(mark);
|
|
|
|
} else {
|
|
|
|
area.setMark(mark, mark.startsWith("@@") ? "" : value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["Animate"] = (jsonData) => {
|
2022-12-20 12:51:54 +08:00
|
|
|
// jsonData: [Object object]
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
2022-12-20 12:51:54 +08:00
|
|
|
switch (data.type) {
|
|
|
|
case "Indicate":
|
|
|
|
data.to.forEach(item => {
|
|
|
|
doIndicate(data.from, [item[0]]);
|
|
|
|
if (item[1]) {
|
|
|
|
doIndicate(item[0], item.slice(1));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
break;
|
|
|
|
case "Emotion":
|
2023-01-29 18:11:41 +08:00
|
|
|
setEmotion(data.player, data.emotion, data.is_card);
|
2022-12-20 12:51:54 +08:00
|
|
|
break;
|
|
|
|
case "LightBox":
|
|
|
|
break;
|
2023-02-21 13:44:24 +08:00
|
|
|
case "SuperLightBox": {
|
2023-06-09 01:16:23 +08:00
|
|
|
const path = data.path;
|
|
|
|
const jsonData = data.data;
|
2023-02-21 13:44:24 +08:00
|
|
|
roomScene.bigAnim.source = AppPath + "/" + path;
|
|
|
|
if (jsonData && jsonData !== "") {
|
|
|
|
roomScene.bigAnim.item.loadData(jsonData);
|
|
|
|
}
|
2022-12-20 12:51:54 +08:00
|
|
|
break;
|
2023-02-21 13:44:24 +08:00
|
|
|
}
|
2023-01-29 18:11:41 +08:00
|
|
|
case "InvokeSkill": {
|
2023-06-09 01:16:23 +08:00
|
|
|
const id = data.player;
|
2024-01-25 03:23:29 +08:00
|
|
|
const component =
|
|
|
|
Qt.createComponent("../RoomElement/SkillInvokeAnimation.qml");
|
2023-01-29 18:11:41 +08:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return;
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const photo = getPhoto(id);
|
2023-01-29 18:11:41 +08:00
|
|
|
if (!photo) {
|
2023-04-27 14:15:08 +08:00
|
|
|
return null;
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const animation = component.createObject(photo, {
|
2024-01-25 03:23:29 +08:00
|
|
|
skill_name: luatr(data.name),
|
2023-01-29 18:11:41 +08:00
|
|
|
skill_type: (data.skill_type ? data.skill_type : "special"),
|
|
|
|
});
|
|
|
|
animation.anchors.centerIn = photo;
|
|
|
|
animation.finished.connect(() => animation.destroy());
|
|
|
|
break;
|
|
|
|
}
|
2023-08-02 01:57:08 +08:00
|
|
|
case "InvokeUltSkill": {
|
|
|
|
const id = data.player;
|
|
|
|
const photo = getPhoto(id);
|
|
|
|
if (!photo) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
roomScene.bigAnim.source = "../RoomElement/UltSkillAnimation.qml";
|
|
|
|
roomScene.bigAnim.item.loadData({
|
|
|
|
skill_name: data.name,
|
2023-11-07 21:14:51 +08:00
|
|
|
general: data.deputy ? photo.deputyGeneral : photo.general,
|
2023-08-02 01:57:08 +08:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2022-12-20 12:51:54 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["LogEvent"] = (jsonData) => {
|
2022-12-20 12:51:54 +08:00
|
|
|
// jsonData: [Object object]
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(jsonData);
|
2022-12-20 12:51:54 +08:00
|
|
|
switch (data.type) {
|
2023-01-29 18:11:41 +08:00
|
|
|
case "Damage": {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = getPhotoOrDashboard(data.to);
|
2022-12-20 12:51:54 +08:00
|
|
|
setEmotion(data.to, "damage");
|
|
|
|
item.tremble();
|
2023-02-21 13:44:24 +08:00
|
|
|
data.damageType = data.damageType || "normal_damage";
|
2024-01-25 03:23:29 +08:00
|
|
|
Backend.playSound("./audio/system/" + data.damageType +
|
|
|
|
(data.damageNum > 1 ? "2" : ""));
|
2023-01-29 18:11:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "LoseHP": {
|
|
|
|
Backend.playSound("./audio/system/losehp");
|
|
|
|
break;
|
|
|
|
}
|
2023-06-04 19:31:44 +08:00
|
|
|
case "ChangeMaxHp": {
|
|
|
|
if (data.num < 0) {
|
|
|
|
Backend.playSound("./audio/system/losemaxhp");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-01-29 18:11:41 +08:00
|
|
|
case "PlaySkillSound": {
|
2023-06-09 01:16:23 +08:00
|
|
|
const skill = data.name;
|
2023-08-24 21:37:24 +08:00
|
|
|
// let extension = data.extension;
|
|
|
|
let extension;
|
|
|
|
let path;
|
|
|
|
let dat;
|
|
|
|
|
|
|
|
// try main general
|
|
|
|
if (data.general) {
|
2024-01-25 03:23:29 +08:00
|
|
|
dat = lcall("GetGeneralData", data.general);
|
2023-08-24 21:37:24 +08:00
|
|
|
extension = dat.extension;
|
2024-01-25 03:23:29 +08:00
|
|
|
path = "./packages/" + extension + "/audio/skill/" + skill + "_"
|
|
|
|
+ data.general;
|
2023-08-24 21:37:24 +08:00
|
|
|
if (Backend.exists(path + ".mp3") || Backend.exists(path + "1.mp3")) {
|
|
|
|
Backend.playSound(path, data.i);
|
|
|
|
break;
|
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
2023-08-24 21:37:24 +08:00
|
|
|
|
|
|
|
// secondly try deputy general
|
|
|
|
if (data.deputy) {
|
2024-01-25 03:23:29 +08:00
|
|
|
dat = lcall("GetGeneralData", data.deputy);
|
2023-08-24 21:37:24 +08:00
|
|
|
extension = dat.extension;
|
2024-01-25 03:23:29 +08:00
|
|
|
path = "./packages/" + extension + "/audio/skill/" + skill + "_"
|
|
|
|
+ data.deputy;
|
2023-08-24 21:37:24 +08:00
|
|
|
if (Backend.exists(path + ".mp3") || Backend.exists(path + "1.mp3")) {
|
|
|
|
Backend.playSound(path, data.i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally normal skill
|
2024-01-25 03:23:29 +08:00
|
|
|
dat = lcall("GetSkillData", skill);
|
2023-08-24 21:37:24 +08:00
|
|
|
extension = dat.extension;
|
|
|
|
path = "./packages/" + extension + "/audio/skill/" + skill;
|
|
|
|
Backend.playSound(path, data.i);
|
2023-01-29 18:11:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "PlaySound": {
|
|
|
|
Backend.playSound(data.name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "Death": {
|
2023-06-09 01:16:23 +08:00
|
|
|
const item = getPhoto(data.to);
|
2024-01-25 03:23:29 +08:00
|
|
|
const extension = lcall("GetGeneralData", item.general).extension;
|
|
|
|
Backend.playSound("./packages/" + extension + "/audio/death/"
|
|
|
|
+ item.general);
|
|
|
|
break;
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
2022-12-20 12:51:54 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
callbacks["GameOver"] = (jsonData) => {
|
2022-12-20 12:51:54 +08:00
|
|
|
roomScene.state = "notactive";
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.popupBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/GameOverBox.qml");
|
2023-06-09 01:16:23 +08:00
|
|
|
const box = roomScene.popupBox.item;
|
2022-12-20 12:51:54 +08:00
|
|
|
box.winner = jsonData;
|
2023-06-04 19:31:44 +08:00
|
|
|
// roomScene.isStarted = false;
|
2022-12-20 12:51:54 +08:00
|
|
|
}
|
2023-02-21 13:44:24 +08:00
|
|
|
|
2023-03-01 21:41:16 +08:00
|
|
|
callbacks["FillAG"] = (j) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(j);
|
|
|
|
const ids = data[0];
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.manualBox.sourceComponent =
|
|
|
|
Qt.createComponent("../RoomElement/AG.qml");
|
2023-03-01 21:41:16 +08:00
|
|
|
roomScene.manualBox.item.addIds(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["AskForAG"] = (j) => {
|
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.manualBox.item.interactive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["TakeAG"] = (j) => {
|
|
|
|
if (!roomScene.manualBox.item) return;
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(j);
|
|
|
|
const pid = data[0];
|
|
|
|
const cid = data[1];
|
|
|
|
const item = getPhoto(pid);
|
2024-01-25 03:23:29 +08:00
|
|
|
const general = luatr(item.general);
|
2023-03-01 21:41:16 +08:00
|
|
|
|
|
|
|
// the item should be AG box
|
|
|
|
roomScene.manualBox.item.takeAG(general, cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["CloseAG"] = () => roomScene.manualBox.item.close();
|
|
|
|
|
2023-02-21 13:44:24 +08:00
|
|
|
callbacks["CustomDialog"] = (j) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(j);
|
|
|
|
const path = data.path;
|
|
|
|
const dat = data.data;
|
2023-02-21 13:44:24 +08:00
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.popupBox.source = AppPath + "/" + path;
|
|
|
|
if (dat) {
|
|
|
|
roomScene.popupBox.item.loadData(dat);
|
|
|
|
}
|
|
|
|
}
|
2023-04-05 01:05:06 +08:00
|
|
|
|
2024-01-11 18:36:05 +08:00
|
|
|
callbacks["MiniGame"] = (j) => {
|
|
|
|
const data = JSON.parse(j);
|
|
|
|
const game = data.type;
|
|
|
|
const dat = data.data;
|
2024-01-25 03:23:29 +08:00
|
|
|
const gdata = lcall("GetMiniGame", game, Self.id, JSON.stringify(dat));
|
2024-01-11 18:36:05 +08:00
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.popupBox.source = AppPath + "/" + gdata.qml_path + ".qml";
|
|
|
|
if (dat) {
|
|
|
|
roomScene.popupBox.item.loadData(dat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["UpdateMiniGame"] = (j) => {
|
|
|
|
const data = JSON.parse(j);
|
|
|
|
if (roomScene.popupBox.item) {
|
|
|
|
roomScene.popupBox.item.updateData(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 01:05:06 +08:00
|
|
|
callbacks["UpdateLimitSkill"] = (j) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = JSON.parse(j);
|
|
|
|
const id = data[0];
|
|
|
|
const skill = data[1];
|
|
|
|
const time = data[2];
|
2023-04-05 01:05:06 +08:00
|
|
|
|
2023-06-09 01:16:23 +08:00
|
|
|
const photo = getPhoto(id);
|
2023-04-05 01:05:06 +08:00
|
|
|
if (photo) {
|
|
|
|
photo.updateLimitSkill(skill, time);
|
|
|
|
}
|
|
|
|
}
|
2023-04-20 00:19:48 +08:00
|
|
|
|
|
|
|
callbacks["UpdateDrawPile"] = (j) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = parseInt(j);
|
2023-04-20 00:19:48 +08:00
|
|
|
roomScene.miscStatus.pileNum = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["UpdateRoundNum"] = (j) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = parseInt(j);
|
2023-04-20 00:19:48 +08:00
|
|
|
roomScene.miscStatus.roundNum = data;
|
|
|
|
}
|
2023-04-27 14:15:08 +08:00
|
|
|
|
2023-06-27 16:50:24 +08:00
|
|
|
callbacks["UpdateGameData"] = (j) => {
|
|
|
|
const data = JSON.parse(j);
|
|
|
|
const id = data[0];
|
|
|
|
const total = data[1];
|
|
|
|
const win = data[2];
|
|
|
|
const run = data[3];
|
|
|
|
const photo = getPhoto(id);
|
|
|
|
if (photo) {
|
|
|
|
photo.totalGame = total;
|
|
|
|
photo.winGame = win;
|
|
|
|
photo.runGame = run;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:15:08 +08:00
|
|
|
// 神貂蝉
|
|
|
|
|
|
|
|
callbacks["StartChangeSelf"] = (j) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const id = parseInt(j);
|
2023-04-27 14:15:08 +08:00
|
|
|
ClientInstance.notifyServer("PushRequest", "changeself," + j);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["ChangeSelf"] = (j) => {
|
2023-06-09 01:16:23 +08:00
|
|
|
const data = parseInt(j);
|
2023-04-27 14:15:08 +08:00
|
|
|
if (Self.id === data) {
|
2023-06-09 01:16:23 +08:00
|
|
|
const msg = mainWindow.fetchMessage();
|
2023-04-27 14:15:08 +08:00
|
|
|
if (!msg) return;
|
|
|
|
mainWindow.handleMessage(msg.command, msg.jsonData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
changeSelf(data);
|
|
|
|
}
|
2023-05-19 07:45:21 +08:00
|
|
|
|
|
|
|
callbacks["AskForLuckCard"] = (j) => {
|
|
|
|
// jsonData: int time
|
2023-12-06 21:07:35 +08:00
|
|
|
if (config.observing || config.replaying) return;
|
2023-05-19 07:45:21 +08:00
|
|
|
const time = parseInt(j);
|
2024-01-25 03:23:29 +08:00
|
|
|
roomScene.setPrompt(luatr("#AskForLuckCard").arg(time), true);
|
2023-05-19 07:45:21 +08:00
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.extra_data = {
|
|
|
|
luckCard: true,
|
|
|
|
time: time,
|
|
|
|
};
|
|
|
|
roomScene.okCancel.visible = true;
|
|
|
|
roomScene.okButton.enabled = true;
|
|
|
|
roomScene.cancelButton.enabled = true;
|
|
|
|
}
|
2023-07-02 20:39:42 +08:00
|
|
|
|
|
|
|
callbacks["CancelRequest"] = (jsonData) => {
|
|
|
|
ClientInstance.replyToServer("", "__cancel")
|
|
|
|
}
|
2023-08-01 21:01:01 +08:00
|
|
|
|
|
|
|
callbacks["ReplayerDurationSet"] = (j) => {
|
|
|
|
roomScene.replayerDuration = parseInt(j);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["ReplayerElapsedChange"] = (j) => {
|
|
|
|
roomScene.replayerElapsed = parseInt(j);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["ReplayerSpeedChange"] = (j) => {
|
|
|
|
roomScene.replayerSpeed = parseFloat(j);
|
|
|
|
}
|