2023-04-23 12:40:54 +09:00
|
|
|
"use strict";
|
2025-08-31 18:28:13 +09:00
|
|
|
const AsyncFunction = async function () { }.constructor;
|
|
|
|
class Operation {
|
|
|
|
static #operations = new Map();
|
|
|
|
static #id = 0;
|
|
|
|
static get nextId() {
|
|
|
|
return ++Operation.#id;
|
|
|
|
}
|
|
|
|
static addOperation(id, callback) {
|
|
|
|
Operation.#operations.set(id, callback);
|
|
|
|
}
|
|
|
|
}
|
2023-06-10 00:06:54 +09:00
|
|
|
|
2023-04-23 12:40:54 +09:00
|
|
|
function discard(target, card) {
|
|
|
|
console.log("DIS!CAR!D!");
|
|
|
|
postMessage({ type: "game", game: { command: "discard", target: target, card: card } });
|
|
|
|
}
|
|
|
|
|
2025-08-31 18:28:13 +09:00
|
|
|
/*
|
|
|
|
function selectUser(from, callback) {
|
|
|
|
const opeId = Operation.nextId;
|
|
|
|
postMessage({ type: "game", game: { command: "selectUser", from: from, id: opeId } });
|
|
|
|
Operation.addOperation(opeId, callback);
|
|
|
|
}*/
|
2023-04-23 12:40:54 +09:00
|
|
|
|
2025-08-31 18:28:13 +09:00
|
|
|
function selectCards(count, target, targetStockId, callback) {/*todo*/
|
|
|
|
const opeId = Operation.nextId;
|
|
|
|
postMessage({ type: "game", game: { command: "selectCards", target: target, count: count, targetStockId: targetStockId, id: opeId } });
|
|
|
|
Operation.addOperation(opeId, callback);
|
2023-04-23 12:40:54 +09:00
|
|
|
}
|
|
|
|
|
2025-08-31 18:28:13 +09:00
|
|
|
function getCard(target, cardId) {
|
|
|
|
return target.cards.find(it => it.cardType.id == cardId);
|
|
|
|
}
|
2023-04-23 12:40:54 +09:00
|
|
|
|
2025-08-31 18:28:13 +09:00
|
|
|
async function wait(time) {
|
|
|
|
await new Promise(resolve => {
|
|
|
|
setTimeout(resolve, time);
|
|
|
|
});
|
2023-04-23 12:40:54 +09:00
|
|
|
}
|
|
|
|
|
2025-08-31 18:28:13 +09:00
|
|
|
onmessage = async e => {
|
2023-04-23 12:40:54 +09:00
|
|
|
console.log(e);
|
|
|
|
switch (e.data.type) {
|
|
|
|
case "run":
|
2023-06-10 00:06:54 +09:00
|
|
|
let fun = new AsyncFunction("target", "players", e.data.function);
|
2025-08-31 18:28:13 +09:00
|
|
|
await fun(e.data.target, e.data.players);
|
2023-04-23 12:40:54 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|