2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-04-14 10:22:00 +00:00
|
|
|
var Card = {
|
2022-04-30 07:27:56 +00:00
|
|
|
Unknown : 0,
|
|
|
|
PlayerHand : 1,
|
|
|
|
PlayerEquip : 2,
|
|
|
|
PlayerJudge : 3,
|
|
|
|
PlayerSpecial : 4,
|
|
|
|
Processing : 5,
|
|
|
|
DrawPile : 6,
|
|
|
|
DiscardPile : 7,
|
|
|
|
Void : 8
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 11:40:28 +00:00
|
|
|
function arrangePhotos() {
|
2022-04-30 07:27:56 +00:00
|
|
|
/* Layout of photos:
|
|
|
|
* +---------------+
|
|
|
|
* | 6 5 4 3 2 |
|
|
|
|
* | 7 1 |
|
2023-04-27 06:15:08 +00:00
|
|
|
* | 0 |
|
2022-04-30 07:27:56 +00:00
|
|
|
* +---------------+
|
|
|
|
*/
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
const photoWidth = 175 * 0.75;
|
|
|
|
// Padding is negative, because photos are scaled.
|
|
|
|
const roomAreaPadding = -16;
|
|
|
|
const verticalPadding = -175 / 8;
|
|
|
|
const horizontalSpacing = 32;
|
|
|
|
let verticalSpacing = (roomArea.width - photoWidth * 7) / 8;
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
// Position 1-7
|
2022-09-14 05:01:10 +00:00
|
|
|
let startX = verticalPadding + verticalSpacing;
|
|
|
|
let padding = photoWidth + verticalSpacing;
|
|
|
|
let regions = [
|
2023-04-27 06:15:08 +00:00
|
|
|
{ x: startX + padding * 6, y: roomScene.height - 220 },
|
2022-09-14 05:01:10 +00: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 07:27:56 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const regularSeatIndex = [
|
2023-04-27 06:15:08 +00: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 07:27:56 +00:00
|
|
|
];
|
|
|
|
let seatIndex = regularSeatIndex[playerNum - 2];
|
|
|
|
|
|
|
|
let item, region, i;
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
for (i = 0; i < playerNum; i++) {
|
2022-04-30 07:27:56 +00:00
|
|
|
item = photos.itemAt(i);
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
region = regions[seatIndex[photoModel.get(i).index]];
|
2022-04-30 07:27:56 +00:00
|
|
|
item.x = region.x;
|
|
|
|
item.y = region.y;
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-03-24 13:23:42 +00:00
|
|
|
|
2022-04-02 07:11:13 +00:00
|
|
|
function doOkButton() {
|
2022-09-14 05:01:10 +00:00
|
|
|
if (roomScene.state == "playing" || roomScene.state == "responding") {
|
2023-05-19 15:03:39 +00:00
|
|
|
const reply = JSON.stringify(
|
2022-04-30 07:27:56 +00:00
|
|
|
{
|
|
|
|
card: dashboard.getSelectedCard(),
|
2023-03-20 12:15:24 +00:00
|
|
|
targets: selected_targets,
|
|
|
|
special_skill: roomScene.getCurrentCardUseMethod(),
|
2023-04-08 12:45:55 +00:00
|
|
|
interaction_data: roomScene.skillInteraction.item ? roomScene.skillInteraction.item.answer : undefined,
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2023-05-19 15:03:39 +00:00
|
|
|
);
|
|
|
|
replyToServer(reply);
|
2022-04-30 07:27:56 +00:00
|
|
|
return;
|
2023-02-26 08:51:29 +00:00
|
|
|
}
|
2023-05-18 23:45:21 +00:00
|
|
|
if (roomScene.extra_data.luckCard) {
|
|
|
|
okButton.enabled = false;
|
|
|
|
ClientInstance.notifyServer("PushRequest", [
|
|
|
|
"luckcard", true
|
|
|
|
].join(","));
|
|
|
|
|
|
|
|
if (roomScene.extra_data.time == 1) {
|
|
|
|
roomScene.state = "notactive";
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
replyToServer("1");
|
2022-04-02 07:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function doCancelButton() {
|
2022-09-14 05:01:10 +00:00
|
|
|
if (roomScene.state == "playing") {
|
2022-09-15 03:17:13 +00:00
|
|
|
dashboard.stopPending();
|
2022-09-14 05:01:10 +00:00
|
|
|
dashboard.deactivateSkillButton();
|
|
|
|
dashboard.unSelectAll();
|
|
|
|
dashboard.enableCards();
|
2022-09-15 03:17:13 +00:00
|
|
|
dashboard.enableSkills();
|
2022-09-14 05:01:10 +00:00
|
|
|
return;
|
|
|
|
} else if (roomScene.state == "responding") {
|
2023-04-19 16:19:48 +00:00
|
|
|
let p = dashboard.pending_skill;
|
2022-09-15 03:17:13 +00:00
|
|
|
dashboard.stopPending();
|
2022-09-14 05:01:10 +00:00
|
|
|
dashboard.deactivateSkillButton();
|
|
|
|
dashboard.unSelectAll();
|
2023-04-19 16:19:48 +00:00
|
|
|
if (roomScene.autoPending || !p) {
|
|
|
|
replyToServer("__cancel");
|
|
|
|
} else {
|
|
|
|
dashboard.enableCards(roomScene.responding_card);
|
|
|
|
dashboard.enableSkills(roomScene.responding_card);
|
|
|
|
}
|
2022-09-14 05:01:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-02-26 08:51:29 +00:00
|
|
|
|
2023-05-18 23:45:21 +00:00
|
|
|
if (roomScene.extra_data.luckCard) {
|
|
|
|
ClientInstance.notifyServer("PushRequest", [
|
|
|
|
"luckcard", false
|
|
|
|
].join(","));
|
|
|
|
roomScene.state = "notactive";
|
|
|
|
return;
|
|
|
|
}
|
2022-12-18 13:19:35 +00:00
|
|
|
replyToServer("__cancel");
|
2022-04-02 07:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function replyToServer(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
ClientInstance.replyToServer("", jsonData);
|
2023-04-27 06:15:08 +00:00
|
|
|
if (!mainWindow.is_pending) {
|
|
|
|
roomScene.state = "notactive";
|
|
|
|
} else {
|
|
|
|
roomScene.state = "";
|
|
|
|
let data = mainWindow.fetchMessage();
|
|
|
|
return mainWindow.handleMessage(data.command, data.jsonData);
|
|
|
|
}
|
2022-04-02 07:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 10:22:00 +00:00
|
|
|
function getPhotoModel(id) {
|
2022-04-30 07:27:56 +00:00
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
|
|
|
let item = photoModel.get(i);
|
|
|
|
if (item.id === id) {
|
|
|
|
return item;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
return undefined;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPhoto(id) {
|
2022-04-30 07:27:56 +00:00
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
|
|
|
let item = photoModel.get(i);
|
|
|
|
if (item.id === id) {
|
|
|
|
return photos.itemAt(i);
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
return undefined;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPhotoOrDashboard(id) {
|
2023-04-27 06:15:08 +00:00
|
|
|
if (id === Self.id)
|
|
|
|
return dashboard;
|
|
|
|
return getPhoto(id);
|
2023-01-29 10:11:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 10:22:00 +00:00
|
|
|
function getAreaItem(area, id) {
|
2022-04-30 07:27:56 +00:00
|
|
|
if (area === Card.DrawPile) {
|
|
|
|
return drawPile;
|
2023-05-13 06:16:09 +00:00
|
|
|
} else if (area === Card.DiscardPile || area === Card.Processing || area === Card.Void) {
|
2022-04-30 07:27:56 +00:00
|
|
|
return tablePile;
|
|
|
|
} else if (area === Card.AG) {
|
|
|
|
return popupBox.item;
|
|
|
|
}
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
let photo = getPhoto(id);
|
2022-04-30 07:27:56 +00:00
|
|
|
if (!photo) {
|
2022-04-14 10:22:00 +00:00
|
|
|
return null;
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (area === Card.PlayerHand) {
|
2023-04-27 06:15:08 +00:00
|
|
|
return id === Self.id ? dashboard.handcardArea : photo.handcardArea;
|
2023-02-15 16:54:39 +00:00
|
|
|
} else if (area === Card.PlayerEquip) {
|
2022-04-30 07:27:56 +00:00
|
|
|
return photo.equipArea;
|
2023-02-15 16:54:39 +00:00
|
|
|
} else if (area === Card.PlayerJudge) {
|
2022-04-30 07:27:56 +00:00
|
|
|
return photo.delayedTrickArea;
|
2023-02-15 16:54:39 +00:00
|
|
|
} else if (area === Card.PlayerSpecial) {
|
2022-04-30 07:27:56 +00:00
|
|
|
return photo.specialArea;
|
2023-02-15 16:54:39 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
return null;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function moveCards(moves) {
|
2022-04-30 07:27:56 +00:00
|
|
|
for (let i = 0; i < moves.length; i++) {
|
|
|
|
let move = moves[i];
|
|
|
|
let from = getAreaItem(move.fromArea, move.from);
|
|
|
|
let to = getAreaItem(move.toArea, move.to);
|
|
|
|
if (!from || !to || from === to)
|
|
|
|
continue;
|
2023-02-21 05:44:24 +00:00
|
|
|
let items = from.remove(move.ids, move.fromSpecialName);
|
2022-04-30 07:27:56 +00:00
|
|
|
if (items.length > 0)
|
2023-02-21 05:44:24 +00:00
|
|
|
to.add(items, move.specialName);
|
2022-04-30 07:27:56 +00:00
|
|
|
to.updateCardPosition(true);
|
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
function setEmotion(id, emotion, isCardId) {
|
2023-01-03 15:37:14 +00:00
|
|
|
let path;
|
|
|
|
if (OS === "Win") {
|
2023-01-07 07:20:44 +00:00
|
|
|
// Windows: file:///C:/xxx/xxxx
|
|
|
|
path = (SkinBank.PIXANIM_DIR + emotion).replace("file:///", "");
|
2023-01-03 15:37:14 +00:00
|
|
|
} else {
|
|
|
|
path = (SkinBank.PIXANIM_DIR + emotion).replace("file://", "");
|
|
|
|
}
|
|
|
|
|
2022-12-20 04:51:54 +00:00
|
|
|
if (!Backend.exists(path)) {
|
2023-02-21 05:44:24 +00: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 04:51:54 +00:00
|
|
|
}
|
|
|
|
if (!Backend.isDir(path)) {
|
|
|
|
// TODO: set picture emotion
|
|
|
|
return;
|
|
|
|
}
|
2023-05-20 08:00:03 +00:00
|
|
|
let component = Qt.createComponent("../RoomElement/PixmapAnimation.qml");
|
2022-04-30 07:27:56 +00:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return;
|
|
|
|
|
2023-01-29 10:11:41 +00: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 06:15:08 +00:00
|
|
|
return null;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2023-03-01 13:41:16 +00:00
|
|
|
let animation = component.createObject(photo, {source: (OS === "Win" ? "file:///" : "") + path});
|
2022-12-20 04:51:54 +00:00
|
|
|
animation.anchors.centerIn = photo;
|
2023-01-29 10:11:41 +00: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 07:27:56 +00:00
|
|
|
animation.start();
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function changeHp(id, delta, losthp) {
|
2022-04-30 07:27:56 +00:00
|
|
|
let photo = getPhoto(id);
|
|
|
|
if (!photo) {
|
2023-04-27 06:15:08 +00:00
|
|
|
return null;
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
if (delta < 0) {
|
|
|
|
if (!losthp) {
|
|
|
|
setEmotion(id, "damage")
|
|
|
|
photo.tremble()
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function doIndicate(from, tos) {
|
2023-05-20 08:00:03 +00:00
|
|
|
let component = Qt.createComponent("../RoomElement/IndicatorLine.qml");
|
2022-04-30 07:27:56 +00:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let fromItem = getPhotoOrDashboard(from);
|
|
|
|
let fromPos = mapFromItem(fromItem, fromItem.width / 2, fromItem.height / 2);
|
|
|
|
|
|
|
|
let end = [];
|
|
|
|
for (let i = 0; i < tos.length; i++) {
|
|
|
|
if (from === tos[i])
|
|
|
|
continue;
|
|
|
|
let toItem = getPhotoOrDashboard(tos[i]);
|
|
|
|
let toPos = mapFromItem(toItem, toItem.width / 2, toItem.height / 2);
|
|
|
|
end.push(toPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
let color = "#96943D";
|
|
|
|
let line = component.createObject(roomScene, {start: fromPos, end: end, color: color});
|
|
|
|
line.finished.connect(() => line.destroy());
|
|
|
|
line.running = true;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
function changeSelf(id) {
|
|
|
|
Backend.callLuaFunction("ChangeSelf", [id]);
|
|
|
|
|
|
|
|
// move new selfPhoto to dashboard
|
|
|
|
let order = new Array(photoModel.count);
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
|
|
|
let item = photoModel.get(i);
|
|
|
|
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) {
|
|
|
|
let data = mainWindow.fetchMessage();
|
|
|
|
return mainWindow.handleMessage(data.command, data.jsonData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 13:23:42 +00:00
|
|
|
callbacks["AddPlayer"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: int id, string screenName, string avatar
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
|
|
|
let item = photoModel.get(i);
|
|
|
|
if (item.id === -1) {
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let uid = data[0];
|
|
|
|
let name = data[1];
|
|
|
|
let avatar = data[2];
|
|
|
|
item.id = uid;
|
|
|
|
item.screenName = name;
|
|
|
|
item.general = avatar;
|
|
|
|
return;
|
2022-03-24 13:23:42 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-24 13:23:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function enableTargets(card) { // card: int | { skill: string, subcards: int[] }
|
2022-12-18 13:19:35 +00:00
|
|
|
if (roomScene.respond_play) {
|
|
|
|
let candidate = (!isNaN(card) && card !== -1) || typeof(card) === "string";
|
2023-01-29 10:11:41 +00:00
|
|
|
if (candidate) {
|
|
|
|
okButton.enabled = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardFitPattern",
|
|
|
|
[card, roomScene.responding_card]
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
2022-12-18 13:19:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
let i = 0;
|
|
|
|
let candidate = (!isNaN(card) && card !== -1) || typeof(card) === "string";
|
2023-04-27 06:15:08 +00:00
|
|
|
let all_photos = [];
|
|
|
|
for (i = 0; i < playerNum; i++) {
|
2022-04-30 07:27:56 +00:00
|
|
|
all_photos.push(photos.itemAt(i))
|
|
|
|
}
|
|
|
|
selected_targets = [];
|
|
|
|
for (i = 0; i < playerNum; i++) {
|
|
|
|
all_photos[i].selected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (candidate) {
|
|
|
|
let data = {
|
|
|
|
ok_enabled: false,
|
|
|
|
enabled_targets: []
|
2022-03-24 13:23:42 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
photo.state = "candidate";
|
|
|
|
let id = photo.playerid;
|
|
|
|
let ret = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CanUseCardToTarget",
|
|
|
|
[card, id, selected_targets]
|
|
|
|
));
|
|
|
|
photo.selectable = ret;
|
|
|
|
})
|
|
|
|
|
|
|
|
okButton.enabled = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardFeasible", [card, selected_targets]
|
|
|
|
));
|
2023-01-29 10:11:41 +00:00
|
|
|
if (okButton.enabled && roomScene.state === "responding") {
|
|
|
|
okButton.enabled = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardFitPattern",
|
|
|
|
[card, roomScene.responding_card]
|
|
|
|
));
|
|
|
|
} else if (okButton.enabled && roomScene.state == "playing") {
|
|
|
|
okButton.enabled = JSON.parse(Backend.callLuaFunction("CanUseCard", [card, Self.id]));
|
|
|
|
}
|
2023-01-16 11:13:07 +00:00
|
|
|
if (okButton.enabled) {
|
|
|
|
if (roomScene.extra_data instanceof Object) {
|
|
|
|
let must = roomScene.extra_data.must_targets;
|
|
|
|
if (must instanceof Array) {
|
|
|
|
okButton.enabled = (must.length === 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
} else {
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
photo.state = "normal";
|
|
|
|
photo.selected = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateSelectedTargets(playerid, selected) {
|
|
|
|
let i = 0;
|
|
|
|
let card = dashboard.getSelectedCard();
|
2022-09-14 05:01:10 +00:00
|
|
|
let candidate = (!isNaN(card) && card !== -1) || typeof(card) === "string";
|
2023-04-27 06:15:08 +00:00
|
|
|
let all_photos = [];
|
|
|
|
for (i = 0; i < playerNum; i++) {
|
2022-04-30 07:27:56 +00: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 05:01:10 +00:00
|
|
|
if (candidate) {
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
if (photo.selected) return;
|
|
|
|
let id = photo.playerid;
|
|
|
|
let ret = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CanUseCardToTarget",
|
|
|
|
[card, id, selected_targets]
|
|
|
|
));
|
|
|
|
photo.selectable = ret;
|
|
|
|
})
|
|
|
|
|
|
|
|
okButton.enabled = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardFeasible", [card, selected_targets]
|
2022-04-30 07:27:56 +00:00
|
|
|
));
|
2023-01-29 10:11:41 +00:00
|
|
|
if (okButton.enabled && roomScene.state === "responding") {
|
|
|
|
okButton.enabled = JSON.parse(Backend.callLuaFunction(
|
|
|
|
"CardFitPattern",
|
|
|
|
[card, roomScene.responding_card]
|
|
|
|
));
|
|
|
|
} else if (okButton.enabled && roomScene.state == "playing") {
|
|
|
|
okButton.enabled = JSON.parse(Backend.callLuaFunction("CanUseCard", [card, Self.id]));
|
|
|
|
}
|
2023-01-16 11:13:07 +00:00
|
|
|
if (okButton.enabled) {
|
|
|
|
if (roomScene.extra_data instanceof Object) {
|
|
|
|
let must = roomScene.extra_data.must_targets;
|
|
|
|
if (must instanceof Array) {
|
|
|
|
okButton.enabled = (must.filter((val) => {
|
|
|
|
return selected_targets.indexOf(val) === -1;
|
|
|
|
}).length === 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 05:01:10 +00:00
|
|
|
} else {
|
|
|
|
all_photos.forEach(photo => {
|
|
|
|
photo.state = "normal";
|
|
|
|
photo.selected = false;
|
|
|
|
});
|
2022-04-30 07:27:56 +00:00
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["RemovePlayer"] = function(jsonData) {
|
|
|
|
// jsonData: int uid
|
|
|
|
let uid = JSON.parse(jsonData)[0];
|
|
|
|
let model = getPhotoModel(uid);
|
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model.id = -1;
|
|
|
|
model.screenName = "";
|
|
|
|
model.general = "";
|
|
|
|
}
|
2022-03-24 13:23:42 +00:00
|
|
|
}
|
2022-03-27 06:49:41 +00:00
|
|
|
|
|
|
|
callbacks["RoomOwner"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: int uid of the owner
|
|
|
|
let uid = JSON.parse(jsonData)[0];
|
2022-03-30 06:14:40 +00:00
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
if (Self.id === uid) {
|
|
|
|
roomScene.isOwner = true;
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
let model = getPhotoModel(uid);
|
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model.isOwner = true;
|
|
|
|
}
|
2022-03-27 06:49:41 +00:00
|
|
|
}
|
2022-03-28 14:24:30 +00:00
|
|
|
|
|
|
|
callbacks["PropertyUpdate"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: int id, string property_name, value
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let uid = data[0];
|
|
|
|
let property_name = data[1];
|
|
|
|
let value = data[2];
|
|
|
|
|
|
|
|
let model = getPhotoModel(uid);
|
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model[property_name] = value;
|
|
|
|
}
|
2022-03-28 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
callbacks["StartGame"] = function(jsonData) {
|
|
|
|
roomScene.isStarted = true;
|
|
|
|
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
|
|
|
let item = photoModel.get(i);
|
|
|
|
item.general = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 14:24:30 +00:00
|
|
|
callbacks["ArrangeSeats"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: seat order
|
|
|
|
let order = JSON.parse(jsonData);
|
|
|
|
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
|
|
|
let item = photoModel.get(i);
|
|
|
|
item.seatNumber = order.indexOf(item.id) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make Self to the first of list, then reorder photomodel
|
|
|
|
let selfIndex = order.indexOf(Self.id);
|
|
|
|
let after = order.splice(selfIndex);
|
|
|
|
after.push(...order);
|
2023-04-27 06:15:08 +00:00
|
|
|
let photoOrder = after;
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < photoModel.count; i++) {
|
|
|
|
let item = photoModel.get(i);
|
|
|
|
item.index = photoOrder.indexOf(item.id);
|
|
|
|
}
|
2023-02-26 08:51:29 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
arrangePhotos();
|
2022-03-28 14:24:30 +00:00
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
|
|
function cancelAllFocus() {
|
2022-04-30 07:27:56 +00:00
|
|
|
let item;
|
2023-04-27 06:15:08 +00:00
|
|
|
for (let i = 0; i < playerNum; i++) {
|
2022-04-30 07:27:56 +00:00
|
|
|
item = photos.itemAt(i);
|
|
|
|
item.progressBar.visible = false;
|
|
|
|
item.progressTip = "";
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["MoveFocus"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: int[] focuses, string command
|
|
|
|
cancelAllFocus();
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let focuses = data[0];
|
|
|
|
let command = data[1];
|
2023-02-26 08:51:29 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
let item, model;
|
2023-04-27 06:15:08 +00:00
|
|
|
for (let i = 0; i < playerNum; i++) {
|
2022-04-30 07:27:56 +00:00
|
|
|
model = photoModel.get(i);
|
|
|
|
if (focuses.indexOf(model.id) != -1) {
|
|
|
|
item = photos.itemAt(i);
|
|
|
|
item.progressBar.visible = true;
|
2023-02-26 08:51:29 +00:00
|
|
|
item.progressTip = Backend.translate(command)
|
2022-05-01 10:37:13 +00:00
|
|
|
+ Backend.translate(" thinking...");
|
|
|
|
|
|
|
|
if (command === "PlayCard") {
|
|
|
|
item.playing = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
item = photos.itemAt(i);
|
|
|
|
if (command === "PlayCard") {
|
|
|
|
item.playing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-30 06:14:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 22:41:55 +00:00
|
|
|
callbacks["PlayerRunned"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: int runner, int robot
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let runner = data[0];
|
|
|
|
let robot = data[1];
|
|
|
|
|
|
|
|
let model = getPhotoModel(runner);
|
|
|
|
if (typeof(model) !== "undefined") {
|
|
|
|
model.id = robot;
|
|
|
|
}
|
2022-04-02 22:41:55 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 06:14:40 +00:00
|
|
|
callbacks["AskForGeneral"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: string[] Generals
|
|
|
|
let data = JSON.parse(jsonData);
|
2023-04-19 06:07:16 +00:00
|
|
|
let generals = data[0];
|
|
|
|
let n = data[1];
|
2023-04-23 13:10:07 +00:00
|
|
|
let heg = data[2];
|
2022-05-01 10:37:13 +00:00
|
|
|
roomScene.promptText = Backend.translate("#AskForGeneral");
|
2022-04-30 07:27:56 +00:00
|
|
|
roomScene.state = "replying";
|
2023-05-20 08:00:03 +00:00
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/ChooseGeneralBox.qml");
|
2022-04-30 07:27:56 +00:00
|
|
|
let box = roomScene.popupBox.item;
|
|
|
|
box.accepted.connect(() => {
|
2023-04-19 06:07:16 +00:00
|
|
|
replyToServer(JSON.stringify(box.choices));
|
2022-04-30 07:27:56 +00:00
|
|
|
});
|
2023-04-19 06:07:16 +00:00
|
|
|
box.choiceNum = n;
|
2023-04-23 13:10:07 +00:00
|
|
|
box.needSameKingdom = !!heg;
|
2023-04-19 06:07:16 +00:00
|
|
|
for (let i = 0; i < generals.length; i++)
|
|
|
|
box.generalList.append({ "name": generals[i] });
|
2022-04-30 07:27:56 +00:00
|
|
|
box.updatePosition();
|
2022-03-30 06:14:40 +00:00
|
|
|
}
|
2022-04-02 07:11:13 +00:00
|
|
|
|
|
|
|
callbacks["AskForSkillInvoke"] = function(jsonData) {
|
2023-04-04 07:59:21 +00:00
|
|
|
// jsonData: [ string name, string prompt ]
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let skill = data[0];
|
|
|
|
let prompt = data[1];
|
|
|
|
roomScene.promptText = prompt ? processPrompt(prompt) : Backend.translate("#AskForSkillInvoke")
|
|
|
|
.arg(Backend.translate(skill));
|
2022-12-18 04:52:52 +00:00
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.okCancel.visible = true;
|
|
|
|
roomScene.okButton.enabled = true;
|
|
|
|
roomScene.cancelButton.enabled = true;
|
2022-04-02 07:11:13 +00:00
|
|
|
}
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
callbacks["AskForGuanxing"] = function(jsonData) {
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let cards = [];
|
2023-04-25 11:02:17 +00:00
|
|
|
let min_top_cards = data.min_top_cards;
|
|
|
|
let max_top_cards = data.max_top_cards;
|
|
|
|
let min_bottom_cards = data.min_bottom_cards;
|
|
|
|
let max_bottom_cards = data.max_bottom_cards;
|
2023-01-29 10:11:41 +00:00
|
|
|
roomScene.state = "replying";
|
2023-05-20 08:00:03 +00:00
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/GuanxingBox.qml");
|
2023-01-29 10:11:41 +00:00
|
|
|
data.cards.forEach(id => {
|
|
|
|
let d = Backend.callLuaFunction("GetCardData", [id]);
|
|
|
|
cards.push(JSON.parse(d));
|
|
|
|
});
|
|
|
|
let box = roomScene.popupBox.item;
|
2023-04-25 11:02:17 +00:00
|
|
|
if (max_top_cards == 0) {
|
|
|
|
box.areaCapacities = [max_bottom_cards];
|
|
|
|
box.areaLimits = [min_bottom_cards];
|
|
|
|
box.areaNames = ["Bottom"];
|
|
|
|
} else {
|
|
|
|
box.areaCapacities = [max_top_cards, max_bottom_cards];
|
|
|
|
box.areaLimits = [min_top_cards, min_bottom_cards];
|
|
|
|
box.areaNames = ["Top", "Bottom"];
|
|
|
|
}
|
2023-01-29 10:11:41 +00:00
|
|
|
box.cards = cards;
|
|
|
|
box.arrangeCards();
|
|
|
|
box.accepted.connect(() => {
|
|
|
|
replyToServer(JSON.stringify(box.getResult()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 07:11:13 +00:00
|
|
|
callbacks["AskForChoice"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: [ string[] choices, string skill ]
|
|
|
|
// TODO: multiple choices, e.g. benxi_ol
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let choices = data[0];
|
|
|
|
let skill_name = data[1];
|
2023-01-29 10:11:41 +00:00
|
|
|
let prompt = data[2];
|
|
|
|
if (prompt === "") {
|
|
|
|
roomScene.promptText = Backend.translate("#AskForChoice")
|
|
|
|
.arg(Backend.translate(skill_name));
|
|
|
|
} else {
|
|
|
|
roomScene.promptText = processPrompt(prompt);
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
roomScene.state = "replying";
|
2023-05-20 08:00:03 +00:00
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/ChoiceBox.qml");
|
2022-04-30 07:27:56 +00:00
|
|
|
let box = roomScene.popupBox.item;
|
|
|
|
box.options = choices;
|
|
|
|
box.skill_name = skill_name;
|
|
|
|
box.accepted.connect(() => {
|
|
|
|
replyToServer(choices[box.result]);
|
|
|
|
});
|
2022-04-02 07:11:13 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
callbacks["AskForCardChosen"] = function(jsonData) {
|
|
|
|
// jsonData: [ int[] handcards, int[] equips, int[] delayedtricks,
|
|
|
|
// string reason ]
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let handcard_ids = data[0];
|
|
|
|
let equip_ids = data[1];
|
|
|
|
let delayedTrick_ids = data[2];
|
|
|
|
let reason = data[3];
|
|
|
|
let handcards = [];
|
|
|
|
let equips = [];
|
|
|
|
let delayedTricks = [];
|
|
|
|
|
|
|
|
handcard_ids.forEach(id => {
|
|
|
|
let card_data = JSON.parse(Backend.callLuaFunction("GetCardData", [id]));
|
|
|
|
handcards.push(card_data);
|
|
|
|
});
|
|
|
|
|
|
|
|
equip_ids.forEach(id => {
|
|
|
|
let card_data = JSON.parse(Backend.callLuaFunction("GetCardData", [id]));
|
|
|
|
equips.push(card_data);
|
|
|
|
});
|
|
|
|
|
|
|
|
delayedTrick_ids.forEach(id => {
|
|
|
|
let card_data = JSON.parse(Backend.callLuaFunction("GetCardData", [id]));
|
|
|
|
delayedTricks.push(card_data);
|
|
|
|
});
|
|
|
|
|
|
|
|
roomScene.promptText = Backend.translate("#AskForChooseCard")
|
|
|
|
.arg(Backend.translate(reason));
|
|
|
|
roomScene.state = "replying";
|
2023-05-20 08:00:03 +00:00
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/PlayerCardBox.qml");
|
2022-09-14 05:01:10 +00:00
|
|
|
let box = roomScene.popupBox.item;
|
|
|
|
box.addHandcards(handcards);
|
|
|
|
box.addEquips(equips);
|
|
|
|
box.addDelayedTricks(delayedTricks);
|
|
|
|
roomScene.popupBox.moveToCenter();
|
|
|
|
box.cardSelected.connect(function(cid){
|
|
|
|
replyToServer(cid);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:41:16 +00:00
|
|
|
callbacks["AskForCardsChosen"] = function(jsonData) {
|
|
|
|
// jsonData: [ int[] handcards, int[] equips, int[] delayedtricks,
|
|
|
|
// int min, int max, string reason ]
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let handcard_ids = data[0];
|
|
|
|
let equip_ids = data[1];
|
|
|
|
let delayedTrick_ids = data[2];
|
|
|
|
let min = data[3];
|
|
|
|
let max = data[4];
|
|
|
|
let reason = data[5];
|
|
|
|
let handcards = [];
|
|
|
|
let equips = [];
|
|
|
|
let delayedTricks = [];
|
|
|
|
|
|
|
|
handcard_ids.forEach(id => {
|
|
|
|
let card_data = JSON.parse(Backend.callLuaFunction("GetCardData", [id]));
|
|
|
|
handcards.push(card_data);
|
|
|
|
});
|
|
|
|
|
|
|
|
equip_ids.forEach(id => {
|
|
|
|
let card_data = JSON.parse(Backend.callLuaFunction("GetCardData", [id]));
|
|
|
|
equips.push(card_data);
|
|
|
|
});
|
|
|
|
|
|
|
|
delayedTrick_ids.forEach(id => {
|
|
|
|
let card_data = JSON.parse(Backend.callLuaFunction("GetCardData", [id]));
|
|
|
|
delayedTricks.push(card_data);
|
|
|
|
});
|
|
|
|
|
|
|
|
roomScene.promptText = Backend.translate("#AskForChooseCard")
|
|
|
|
.arg(Backend.translate(reason));
|
|
|
|
roomScene.state = "replying";
|
2023-05-20 08:00:03 +00:00
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/PlayerCardBox.qml");
|
2023-03-01 13:41:16 +00:00
|
|
|
let box = roomScene.popupBox.item;
|
|
|
|
box.multiChoose = true;
|
|
|
|
box.min = min;
|
|
|
|
box.max = max;
|
|
|
|
box.addHandcards(handcards);
|
|
|
|
box.addEquips(equips);
|
|
|
|
box.addDelayedTricks(delayedTricks);
|
|
|
|
roomScene.popupBox.moveToCenter();
|
|
|
|
box.cardsSelected.connect((ids) => {
|
|
|
|
replyToServer(JSON.stringify(ids));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-20 08:00:03 +00:00
|
|
|
callbacks["AskForMoveCardInBoard"] = function(jsonData) {
|
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
const { cards, cardsPosition, generalNames } = data;
|
|
|
|
|
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/MoveCardInBoardBox.qml");
|
|
|
|
|
|
|
|
const boxCards = [];
|
|
|
|
cards.forEach(id => {
|
|
|
|
let d = Backend.callLuaFunction("GetCardData", [id]);
|
|
|
|
boxCards.push(JSON.parse(d));
|
|
|
|
});
|
|
|
|
|
|
|
|
const box = roomScene.popupBox.item;
|
|
|
|
box.cards = boxCards;
|
|
|
|
box.cardsPosition = cardsPosition;
|
|
|
|
box.generalNames = generalNames.map(name => {
|
|
|
|
const namesSplited = name.split('/');
|
|
|
|
return namesSplited.length > 1 ? namesSplited.map(nameSplited => Backend.translate(nameSplited)).join('/') : Backend.translate(name)
|
|
|
|
});
|
|
|
|
|
|
|
|
box.arrangeCards();
|
|
|
|
box.accepted.connect(() => {
|
|
|
|
replyToServer(JSON.stringify(box.getResult()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-14 10:22:00 +00:00
|
|
|
callbacks["MoveCards"] = function(jsonData) {
|
2022-04-30 07:27:56 +00:00
|
|
|
// jsonData: merged moves
|
|
|
|
let moves = JSON.parse(jsonData);
|
|
|
|
moveCards(moves);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["PlayCard"] = function(jsonData) {
|
|
|
|
// jsonData: int playerId
|
|
|
|
let playerId = parseInt(jsonData);
|
|
|
|
if (playerId == Self.id) {
|
2022-05-01 10:37:13 +00:00
|
|
|
roomScene.promptText = Backend.translate("#PlayCard");
|
2022-04-30 07:27:56 +00:00
|
|
|
roomScene.state = "playing";
|
2022-09-14 05:01:10 +00:00
|
|
|
okButton.enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["LoseSkill"] = function(jsonData) {
|
|
|
|
// jsonData: [ int player_id, string skill_name ]
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let id = data[0];
|
|
|
|
let skill_name = data[1];
|
2023-04-23 13:10:07 +00:00
|
|
|
let prelight = data[2];
|
2022-09-14 05:01:10 +00:00
|
|
|
if (id === Self.id) {
|
2023-04-23 13:10:07 +00:00
|
|
|
dashboard.loseSkill(skill_name, prelight);
|
2022-09-14 05:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["AddSkill"] = function(jsonData) {
|
|
|
|
// jsonData: [ int player_id, string skill_name ]
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let id = data[0];
|
|
|
|
let skill_name = data[1];
|
2023-04-23 13:10:07 +00:00
|
|
|
let prelight = data[2];
|
2022-09-14 05:01:10 +00:00
|
|
|
if (id === Self.id) {
|
2023-04-23 13:10:07 +00:00
|
|
|
dashboard.addSkill(skill_name, prelight);
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-09-15 03:17:13 +00:00
|
|
|
|
2023-04-23 13:10:07 +00:00
|
|
|
callbacks["PrelightSkill"] = function(jsonData) {
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let skill_name = data[0];
|
|
|
|
let prelight = data[1];
|
|
|
|
|
|
|
|
dashboard.prelightSkill(skill_name, prelight);
|
|
|
|
}
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
// prompt: 'string:<src>:<dest>:<arg>:<arg2>'
|
|
|
|
function processPrompt(prompt) {
|
|
|
|
let data = prompt.split(":");
|
|
|
|
let raw = Backend.translate(data[0]);
|
|
|
|
let src = parseInt(data[1]);
|
|
|
|
let dest = parseInt(data[2]);
|
2023-04-27 06:15:08 +00:00
|
|
|
if (raw.match("%src")) raw = raw.replace("%src", Backend.translate(getPhoto(src).general));
|
|
|
|
if (raw.match("%dest")) raw = raw.replace("%dest", Backend.translate(getPhoto(dest).general));
|
2023-01-29 10:11:41 +00:00
|
|
|
if (raw.match("%arg")) raw = raw.replace("%arg", Backend.translate(data[3]));
|
|
|
|
if (raw.match("%arg2")) raw = raw.replace("%arg2", Backend.translate(data[4]));
|
|
|
|
return raw;
|
|
|
|
}
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
callbacks["AskForUseActiveSkill"] = function(jsonData) {
|
|
|
|
// jsonData: string skill_name, string prompt
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let skill_name = data[0];
|
|
|
|
let prompt = data[1];
|
|
|
|
let cancelable = data[2];
|
2023-05-19 15:03:39 +00:00
|
|
|
let extra_data = data[3] ?? {};
|
2022-09-15 03:17:13 +00:00
|
|
|
if (prompt === "") {
|
|
|
|
roomScene.promptText = Backend.translate("#AskForUseActiveSkill")
|
|
|
|
.arg(Backend.translate(skill_name));
|
2023-01-29 10:11:41 +00:00
|
|
|
} else {
|
|
|
|
roomScene.promptText = processPrompt(prompt);
|
2022-09-15 03:17:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 13:19:35 +00:00
|
|
|
roomScene.respond_play = false;
|
2022-09-15 03:17:13 +00:00
|
|
|
roomScene.state = "responding";
|
2023-05-19 15:03:39 +00:00
|
|
|
roomScene.responding_card = ".";
|
2023-04-19 16:19:48 +00:00
|
|
|
roomScene.autoPending = true;
|
2023-05-19 15:03:39 +00:00
|
|
|
roomScene.extra_data = extra_data;
|
|
|
|
// dashboard.startPending(skill_name);
|
|
|
|
roomScene.activateSkill(skill_name, true);
|
2022-09-15 03:17:13 +00:00
|
|
|
cancelButton.enabled = cancelable;
|
|
|
|
}
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
|
|
callbacks["CancelRequest"] = function() {
|
|
|
|
roomScene.state = "notactive";
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["GameLog"] = function(jsonData) {
|
|
|
|
roomScene.addToLog(jsonData)
|
|
|
|
}
|
2022-12-18 13:19:35 +00:00
|
|
|
|
|
|
|
callbacks["AskForUseCard"] = function(jsonData) {
|
2023-01-16 11:13:07 +00:00
|
|
|
// jsonData: card, pattern, prompt, cancelable, {}
|
2022-12-18 13:19:35 +00:00
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let cardname = data[0];
|
2023-01-16 11:13:07 +00:00
|
|
|
let pattern = data[1];
|
|
|
|
let prompt = data[2];
|
|
|
|
let extra_data = data[4];
|
|
|
|
if (extra_data != null) {
|
|
|
|
roomScene.extra_data = extra_data;
|
|
|
|
}
|
2022-12-18 13:19:35 +00:00
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
if (prompt === "") {
|
|
|
|
roomScene.promptText = Backend.translate("#AskForUseCard")
|
|
|
|
.arg(Backend.translate(cardname));
|
|
|
|
} else {
|
|
|
|
roomScene.promptText = processPrompt(prompt);
|
|
|
|
}
|
2023-01-16 11:13:07 +00:00
|
|
|
roomScene.responding_card = pattern;
|
2022-12-18 13:19:35 +00:00
|
|
|
roomScene.respond_play = false;
|
|
|
|
roomScene.state = "responding";
|
|
|
|
okButton.enabled = false;
|
|
|
|
cancelButton.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["AskForResponseCard"] = function(jsonData) {
|
2023-01-16 11:13:07 +00:00
|
|
|
// jsonData: card_name, pattern, prompt, cancelable, {}
|
2022-12-18 13:19:35 +00:00
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
let cardname = data[0];
|
2023-01-16 11:13:07 +00:00
|
|
|
let pattern = data[1];
|
|
|
|
let prompt = data[2];
|
2022-12-18 13:19:35 +00:00
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
if (prompt === "") {
|
|
|
|
roomScene.promptText = Backend.translate("#AskForResponseCard")
|
|
|
|
.arg(Backend.translate(cardname));
|
|
|
|
} else {
|
|
|
|
roomScene.promptText = processPrompt(prompt);
|
|
|
|
}
|
2023-01-16 11:13:07 +00:00
|
|
|
roomScene.responding_card = pattern;
|
2022-12-18 13:19:35 +00:00
|
|
|
roomScene.respond_play = true;
|
|
|
|
roomScene.state = "responding";
|
|
|
|
okButton.enabled = false;
|
|
|
|
cancelButton.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["WaitForNullification"] = function() {
|
|
|
|
roomScene.state = "notactive";
|
|
|
|
}
|
2022-12-20 04:51:54 +00:00
|
|
|
|
2023-02-15 11:54:35 +00:00
|
|
|
callbacks["SetPlayerMark"] = function(jsonData) {
|
|
|
|
let data = JSON.parse(jsonData);
|
2023-04-27 06:15:08 +00:00
|
|
|
let player = getPhoto(data[0]);
|
2023-02-15 11:54:35 +00:00
|
|
|
let mark = data[1];
|
2023-05-13 06:20:34 +00:00
|
|
|
let value = data[2] instanceof Array ? data[2] : data[2].toString();
|
2023-02-15 11:54:35 +00:00
|
|
|
if (value == 0) {
|
|
|
|
player.markArea.removeMark(mark);
|
|
|
|
} else {
|
|
|
|
player.markArea.setMark(mark, mark.startsWith("@@") ? "" : value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 04:51:54 +00:00
|
|
|
callbacks["Animate"] = function(jsonData) {
|
|
|
|
// jsonData: [Object object]
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
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 10:11:41 +00:00
|
|
|
setEmotion(data.player, data.emotion, data.is_card);
|
2022-12-20 04:51:54 +00:00
|
|
|
break;
|
|
|
|
case "LightBox":
|
|
|
|
break;
|
2023-02-21 05:44:24 +00:00
|
|
|
case "SuperLightBox": {
|
|
|
|
let path = data.path;
|
|
|
|
let jsonData = data.data;
|
|
|
|
roomScene.bigAnim.source = AppPath + "/" + path;
|
|
|
|
if (jsonData && jsonData !== "") {
|
|
|
|
roomScene.bigAnim.item.loadData(jsonData);
|
|
|
|
}
|
2022-12-20 04:51:54 +00:00
|
|
|
break;
|
2023-02-21 05:44:24 +00:00
|
|
|
}
|
2023-01-29 10:11:41 +00:00
|
|
|
case "InvokeSkill": {
|
|
|
|
let id = data.player;
|
2023-05-20 08:00:03 +00:00
|
|
|
let component = Qt.createComponent("../RoomElement/SkillInvokeAnimation.qml");
|
2023-01-29 10:11:41 +00:00
|
|
|
if (component.status !== Component.Ready)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let photo = getPhoto(id);
|
|
|
|
if (!photo) {
|
2023-04-27 06:15:08 +00:00
|
|
|
return null;
|
2023-01-29 10:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let animation = component.createObject(photo, {
|
|
|
|
skill_name: Backend.translate(data.name),
|
|
|
|
skill_type: (data.skill_type ? data.skill_type : "special"),
|
|
|
|
});
|
|
|
|
animation.anchors.centerIn = photo;
|
|
|
|
animation.finished.connect(() => animation.destroy());
|
|
|
|
break;
|
|
|
|
}
|
2022-12-20 04:51:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["LogEvent"] = function(jsonData) {
|
|
|
|
// jsonData: [Object object]
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
switch (data.type) {
|
2023-01-29 10:11:41 +00:00
|
|
|
case "Damage": {
|
2022-12-20 04:51:54 +00:00
|
|
|
let item = getPhotoOrDashboard(data.to);
|
|
|
|
setEmotion(data.to, "damage");
|
|
|
|
item.tremble();
|
2023-02-21 05:44:24 +00:00
|
|
|
data.damageType = data.damageType || "normal_damage";
|
2023-01-29 10:11:41 +00:00
|
|
|
Backend.playSound("./audio/system/" + data.damageType + (data.damageNum > 1 ? "2" : ""));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "LoseHP": {
|
|
|
|
Backend.playSound("./audio/system/losehp");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "PlaySkillSound": {
|
2023-02-15 11:54:35 +00:00
|
|
|
let skill = data.name;
|
|
|
|
let extension = data.extension;
|
|
|
|
if (!extension) {
|
|
|
|
let data = JSON.parse(Backend.callLuaFunction("GetSkillData", [skill]));
|
|
|
|
extension = data.extension;
|
|
|
|
}
|
|
|
|
Backend.playSound("./packages/" + extension + "/audio/skill/" + skill, data.i);
|
2023-01-29 10:11:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "PlaySound": {
|
|
|
|
Backend.playSound(data.name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "Death": {
|
|
|
|
let item = getPhoto(data.to);
|
2023-02-15 11:54:35 +00:00
|
|
|
let extension = JSON.parse(Backend.callLuaFunction("GetGeneralData", [item.general])).extension;
|
|
|
|
Backend.playSound("./packages/" + extension + "/audio/death/" + item.general);
|
2023-01-29 10:11:41 +00:00
|
|
|
}
|
2022-12-20 04:51:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["GameOver"] = function(jsonData) {
|
|
|
|
roomScene.state = "notactive";
|
2023-05-20 08:00:03 +00:00
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/GameOverBox.qml");
|
2022-12-20 04:51:54 +00:00
|
|
|
let box = roomScene.popupBox.item;
|
|
|
|
box.winner = jsonData;
|
2023-01-29 10:11:41 +00:00
|
|
|
roomScene.isStarted = false;
|
2022-12-20 04:51:54 +00:00
|
|
|
}
|
2023-02-21 05:44:24 +00:00
|
|
|
|
2023-03-01 13:41:16 +00:00
|
|
|
callbacks["FillAG"] = (j) => {
|
|
|
|
let data = JSON.parse(j);
|
|
|
|
let ids = data[0];
|
2023-05-20 08:00:03 +00:00
|
|
|
roomScene.manualBox.sourceComponent = Qt.createComponent("../RoomElement/AG.qml");
|
2023-03-01 13:41:16 +00: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;
|
|
|
|
let data = JSON.parse(j);
|
|
|
|
let pid = data[0];
|
|
|
|
let cid = data[1];
|
2023-04-27 06:15:08 +00:00
|
|
|
let item = getPhoto(pid);
|
2023-03-01 13:41:16 +00:00
|
|
|
let general = Backend.translate(item.general);
|
|
|
|
|
|
|
|
// the item should be AG box
|
|
|
|
roomScene.manualBox.item.takeAG(general, cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["CloseAG"] = () => roomScene.manualBox.item.close();
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
callbacks["CustomDialog"] = (j) => {
|
|
|
|
let data = JSON.parse(j);
|
|
|
|
let path = data.path;
|
|
|
|
let dat = data.data;
|
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.popupBox.source = AppPath + "/" + path;
|
|
|
|
if (dat) {
|
|
|
|
roomScene.popupBox.item.loadData(dat);
|
|
|
|
}
|
|
|
|
}
|
2023-04-04 17:05:06 +00:00
|
|
|
|
|
|
|
callbacks["UpdateLimitSkill"] = (j) => {
|
|
|
|
let data = JSON.parse(j);
|
|
|
|
let id = data[0];
|
|
|
|
let skill = data[1];
|
|
|
|
let time = data[2];
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
let photo = getPhoto(id);
|
2023-04-04 17:05:06 +00:00
|
|
|
if (photo) {
|
|
|
|
photo.updateLimitSkill(skill, time);
|
|
|
|
}
|
|
|
|
}
|
2023-04-19 16:19:48 +00:00
|
|
|
|
|
|
|
callbacks["UpdateDrawPile"] = (j) => {
|
|
|
|
let data = parseInt(j);
|
|
|
|
roomScene.miscStatus.pileNum = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["UpdateRoundNum"] = (j) => {
|
|
|
|
let data = parseInt(j);
|
|
|
|
roomScene.miscStatus.roundNum = data;
|
|
|
|
}
|
2023-04-27 06:15:08 +00:00
|
|
|
|
|
|
|
// 神貂蝉
|
|
|
|
|
|
|
|
callbacks["StartChangeSelf"] = (j) => {
|
|
|
|
let id = parseInt(j);
|
|
|
|
ClientInstance.notifyServer("PushRequest", "changeself," + j);
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["ChangeSelf"] = (j) => {
|
|
|
|
let data = parseInt(j);
|
|
|
|
if (Self.id === data) {
|
|
|
|
let msg = mainWindow.fetchMessage();
|
|
|
|
if (!msg) return;
|
|
|
|
mainWindow.handleMessage(msg.command, msg.jsonData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
changeSelf(data);
|
|
|
|
}
|
2023-05-18 23:45:21 +00:00
|
|
|
|
|
|
|
callbacks["AskForLuckCard"] = (j) => {
|
|
|
|
// jsonData: int time
|
|
|
|
const time = parseInt(j);
|
|
|
|
roomScene.promptText = Backend.translate("#AskForLuckCard").arg(time);
|
|
|
|
roomScene.state = "replying";
|
|
|
|
roomScene.extra_data = {
|
|
|
|
luckCard: true,
|
|
|
|
time: time,
|
|
|
|
};
|
|
|
|
roomScene.okCancel.visible = true;
|
|
|
|
roomScene.okButton.enabled = true;
|
|
|
|
roomScene.cancelButton.enabled = true;
|
|
|
|
}
|