Commit f6414f4d authored by timel's avatar timel

Merge branch 'chore/dependencies' into 'main'

Chore/dependencies

See merge request !262
parents 15167474 18400f60
Pipeline #23130 passed with stages
in 11 minutes and 55 seconds
......@@ -2,8 +2,6 @@
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:prettier/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:valtio/recommended"
],
"plugins": [
......@@ -11,17 +9,20 @@
"simple-import-sort"
],
"rules": {
"eqeqeq": 0,
"no-var": "error",
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn",
"eqeqeq": "warn",
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface"
],
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}
]
},
"settings": {
......@@ -30,5 +31,7 @@
"typescript": true
}
},
"ignorePatterns": ["src/api/ocgcore/idl/ocgcore.ts"]
"ignorePatterns": [
"src/api/ocgcore/idl/ocgcore.ts"
]
}
This diff is collapsed.
......@@ -3,19 +3,11 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@ant-design/pro-components": "^2.4.4",
"@ant-design/pro-components": "^2.6.12",
"@dnd-kit/core": "^6.0.8",
"@dnd-kit/sortable": "^7.0.2",
"@react-spring/web": "^9.7.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.23",
"@types/react": "^18.0.33",
"@types/react-dom": "^18.0.11",
"@types/sql.js": "^1.4.4",
"antd": "^5.4.0",
"@react-spring/web": "^9.7.3",
"antd": "^5.8.3",
"classnames": "^2.3.2",
"cookies-ts": "^1.0.5",
"eventemitter3": "^5.0.1",
......@@ -28,15 +20,12 @@
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.5",
"react-router-dom": "^6.10.0",
"react-scripts": "^2.1.3",
"react-router-dom": "^6.15.0",
"sql.js": "^1.8.0",
"u-reset.css": "^2.0.1",
"uuid": "^9.0.0",
"valtio": "^1.10.4",
"vite-plugin-svgr": "^2.4.0",
"web-vitals": "^2.1.4",
"valtio": "^1.11.2",
"vite-plugin-svgr": "^3.2.0",
"ygopro-deck-encode": "^1.0.3"
},
"scripts": {
......@@ -46,14 +35,11 @@
"build:prod": "vite build --base=https://cdn02.moecube.com:444/neos/",
"preview": "vite preview",
"lint": "eslint --ext .ts --ext .tsx src",
"fmt": "eslint --ext .ts --ext .tsx src --fix && cd rust-src && cargo fmt",
"test": "react-scripts test",
"eject": "react-scripts eject"
"fmt": "eslint --ext .ts --ext .tsx src --fix && cd rust-src && cargo fmt"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
"react-app"
]
},
"browserslist": {
......@@ -70,25 +56,28 @@
},
"devDependencies": {
"@types/google-protobuf": "^3.15.6",
"@types/lodash-es": "^4.17.7",
"@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"@vitejs/plugin-react": "^3.1.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"@types/lodash-es": "^4.17.8",
"@types/node": "^20.5.0",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@types/sql.js": "^1.4.4",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"@vitejs/plugin-react": "^4.0.4",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-valtio": "^0.6.2",
"prettier": "^2.8.7",
"sass": "^1.61.0",
"typescript": "^4.9.5",
"vite": "^4.2.1",
"vite-plugin-sass-dts": "^1.3.8",
"prettier": "^3.0.1",
"sass": "^1.65.1",
"typescript": "^5.1.6",
"vite": "^4.4.9",
"vite-plugin-sass-dts": "^1.3.9",
"vite-plugin-wasm-pack": "^0.1.12",
"vite-tsconfig-paths": "^4.0.8",
"vite-tsconfig-paths": "^4.2.0",
"vite-ydk-loader": "^0.0.2"
}
}
......@@ -28,14 +28,14 @@ export async function initForbiddens(): Promise<void> {
// 获取禁限信息
export async function getForbiddenInfo(
id: number
id: number,
): Promise<number | undefined> {
return await get(id, idb);
}
// 解析函数,提取卡片编号和限制张数
function parseCardInfo(
input: string
input: string,
): { cardId: number; limitCount: number } | null {
const match = input.match(/^(\d+)\s+(\d+)\s+--/);
if (match) {
......
......@@ -9,7 +9,7 @@ export interface MatchInfo {
export async function match(
username: string,
extraId: number,
arena: string = "entertain"
arena: string = "entertain",
): Promise<MatchInfo | undefined> {
const headers = { Authorization: "Basic " + btoa(username + ":" + extraId) };
let response: Response | undefined = undefined;
......
......@@ -68,7 +68,7 @@ export default class CtosResponsePacket extends YgoProPacket {
}
case "select_counter_response": {
extraData = adaptSelectCounterResponse(
response.select_counter_response
response.select_counter_response,
);
break;
......
......@@ -3,7 +3,7 @@ import { BufferWriter } from "rust-src";
import { ygopro } from "../../../idl/ocgcore";
export default (
response: ygopro.CtosGameMsgResponse.SelectBattleCmdResponse
response: ygopro.CtosGameMsgResponse.SelectBattleCmdResponse,
) => {
const writer = new BufferWriter();
......
......@@ -3,7 +3,7 @@ import { BufferWriter } from "rust-src";
import { ygopro } from "../../../idl/ocgcore";
export default (
response: ygopro.CtosGameMsgResponse.SelectEffectYnResponse
response: ygopro.CtosGameMsgResponse.SelectEffectYnResponse,
) => {
const writer = new BufferWriter();
......
......@@ -3,7 +3,7 @@ import { BufferWriter } from "rust-src";
import { ygopro } from "../../../idl/ocgcore";
export default (
response: ygopro.CtosGameMsgResponse.SelectPositionResponse
response: ygopro.CtosGameMsgResponse.SelectPositionResponse,
) => {
const writer = new BufferWriter();
......
......@@ -44,7 +44,7 @@ export class YgoProPacket {
try {
if (array.byteLength < PACKET_MIN_LEN) {
throw new Error(
"Packet length too short, length = " + array.byteLength
"Packet length too short, length = " + array.byteLength,
);
}
} catch (e) {
......
......@@ -24,7 +24,7 @@ export default (data: Uint8Array) => {
new MsgAnnounce.Option({
code: i,
response: 1 << i,
})
}),
);
}
}
......
......@@ -23,7 +23,7 @@ export default (data: Uint8Array) => {
new MsgAnnounce.Option({
code,
response: code,
})
}),
);
}
......
......@@ -23,7 +23,7 @@ export default (data: Uint8Array) => {
new MsgAnnounce.Option({
code: num,
response: i,
})
}),
);
}
......
......@@ -24,7 +24,7 @@ export default (data: Uint8Array) => {
new MsgAnnounce.Option({
code: i,
response: 1 << i,
})
}),
);
}
}
......
......@@ -17,9 +17,9 @@ export default (data: Uint8Array) => {
const target_location = reader.readCardLocation();
if (
target_location.controller == 0 &&
target_location.zone == 0 &&
target_location.sequence == 0
target_location.controller === 0 &&
target_location.zone === 0 &&
target_location.sequence === 0
) {
// 全零表示直接攻击玩家
return new MsgAttack({
......
......@@ -24,7 +24,7 @@ export default (data: Uint8Array) => {
zone: CardZone.MZONE,
sequence: i,
disabled,
})
}),
);
}
......@@ -37,7 +37,7 @@ export default (data: Uint8Array) => {
zone: CardZone.SZONE,
sequence: i,
disabled,
})
}),
);
}
......@@ -50,7 +50,7 @@ export default (data: Uint8Array) => {
zone: CardZone.MZONE,
sequence: i,
disabled,
})
}),
);
}
......@@ -63,7 +63,7 @@ export default (data: Uint8Array) => {
zone: CardZone.SZONE,
sequence: i,
disabled,
})
}),
);
}
......
......@@ -230,7 +230,7 @@ export default class GameMsgAdapter implements StocAdapter {
case GAME_MSG.MSG_TOSS_COIN: {
gameMsg.toss = MsgTossAdapter(
gameData,
ygopro.StocGameMessage.MsgToss.TossType.COIN
ygopro.StocGameMessage.MsgToss.TossType.COIN,
);
break;
......@@ -238,7 +238,7 @@ export default class GameMsgAdapter implements StocAdapter {
case GAME_MSG.MSG_TOSS_DICE: {
gameMsg.toss = MsgTossAdapter(
gameData,
ygopro.StocGameMessage.MsgToss.TossType.DICE
ygopro.StocGameMessage.MsgToss.TossType.DICE,
);
break;
......@@ -261,7 +261,7 @@ export default class GameMsgAdapter implements StocAdapter {
case GAME_MSG.MSG_SHUFFLE_HAND: {
gameMsg.shuffle_hand_extra = MsgShuffleHandExtraAdapter(
gameData,
false
false,
);
break;
......@@ -269,7 +269,7 @@ export default class GameMsgAdapter implements StocAdapter {
case GAME_MSG.MSG_SHUFFLE_EXTRA: {
gameMsg.shuffle_hand_extra = MsgShuffleHandExtraAdapter(
gameData,
true
true,
);
break;
......
......@@ -72,7 +72,7 @@ class PenetrateManager {
private readRepeatedField(
reader: BufferReaderExt,
repeatedType: string
repeatedType: string,
): any {
const handler = this.readFieldHandlerMap.get(repeatedType);
......
......@@ -26,7 +26,7 @@ export default (data: Uint8Array) => {
sequence,
position: numberToCardPosition(position),
overlay_count,
})
}),
);
} else {
zone_actions.push(
......@@ -34,7 +34,7 @@ export default (data: Uint8Array) => {
zone: ygopro.CardZone.MZONE,
sequence,
position: ygopro.CardPosition.FACEDOWN,
})
}),
);
}
}
......@@ -50,7 +50,7 @@ export default (data: Uint8Array) => {
zone: ygopro.CardZone.SZONE,
sequence,
position: numberToCardPosition(position),
})
}),
);
} else {
zone_actions.push(
......@@ -58,7 +58,7 @@ export default (data: Uint8Array) => {
zone: ygopro.CardZone.SZONE,
sequence,
position: ygopro.CardPosition.FACEDOWN,
})
}),
);
}
}
......@@ -70,7 +70,7 @@ export default (data: Uint8Array) => {
zone: ygopro.CardZone.DECK,
sequence,
position: ygopro.CardPosition.FACEDOWN_ATTACK,
})
}),
);
}
......@@ -80,7 +80,7 @@ export default (data: Uint8Array) => {
new MsgReloadField.ZoneAction({
zone: ygopro.CardZone.HAND,
sequence,
})
}),
);
}
......@@ -90,7 +90,7 @@ export default (data: Uint8Array) => {
new MsgReloadField.ZoneAction({
zone: ygopro.CardZone.GRAVE,
sequence,
})
}),
);
}
......@@ -100,7 +100,7 @@ export default (data: Uint8Array) => {
new MsgReloadField.ZoneAction({
zone: ygopro.CardZone.REMOVED,
sequence,
})
}),
);
}
......@@ -111,7 +111,7 @@ export default (data: Uint8Array) => {
zone: ygopro.CardZone.EXTRA,
sequence,
position: ygopro.CardPosition.FACEDOWN_ATTACK,
})
}),
);
}
......@@ -145,7 +145,7 @@ export default (data: Uint8Array) => {
lp,
zone_actions,
// chain_actions,
})
}),
);
}
......
......@@ -44,7 +44,7 @@ export default (data: Uint8Array) => {
const directAttackAble = reader.inner.readUint8();
const attackData = new MsgSelectBattleCmd.BattleCmd.BattleData({
card_info: cardInfo,
direct_attackable: directAttackAble == 1,
direct_attackable: directAttackAble === 1,
response: (i << 16) + 1,
});
attackCmd.battle_datas.push(attackData);
......@@ -53,9 +53,9 @@ export default (data: Uint8Array) => {
msg.battle_cmds = [activateCmd, attackCmd];
// 是否可进入M2阶段
msg.enable_m2 = reader.inner.readUint8() == 1;
msg.enable_m2 = reader.inner.readUint8() === 1;
//时是否可结束回合
msg.enable_ep = reader.inner.readUint8() == 1;
msg.enable_ep = reader.inner.readUint8() === 1;
return msg;
};
......@@ -13,7 +13,7 @@ export default (data: Uint8Array) => {
const reader = new BufferReaderExt(data);
const player = reader.inner.readUint8();
const cancelable = reader.inner.readUint8() != 0;
const cancelable = reader.inner.readUint8() !== 0;
const min = reader.inner.readUint8();
const max = reader.inner.readUint8();
const count = reader.inner.readUint8();
......@@ -25,7 +25,7 @@ export default (data: Uint8Array) => {
const location = reader.readCardLocation();
msg.cards.push(
new MsgSelectCard.SelectAbleCard({ code, location, response: i })
new MsgSelectCard.SelectAbleCard({ code, location, response: i }),
);
}
......
......@@ -17,7 +17,7 @@ export default (data: Uint8Array) => {
const player = reader.inner.readUint8();
const count = reader.inner.readUint8();
const spCount = reader.inner.readUint8();
const forced = reader.inner.readUint8() != 0;
const forced = reader.inner.readUint8() !== 0;
const hint0 = reader.inner.readUint32();
const hint1 = reader.inner.readUint32();
......@@ -43,7 +43,7 @@ export default (data: Uint8Array) => {
location,
effect_description: effect_desc,
response: i,
})
}),
);
}
......
......@@ -33,7 +33,7 @@ export default (data: Uint8Array) => {
code,
location,
counter_count: counterCount,
})
}),
);
}
......
......@@ -19,7 +19,7 @@ export default (data: Uint8Array) => {
const _field = ~reader.readUint32();
// TODO: 暂时和`ygopro2`一样不支持取消操作,后续需要再考虑加上
if (count == 0) {
if (count === 0) {
count = 1;
}
......@@ -30,67 +30,67 @@ export default (data: Uint8Array) => {
});
for (let i = 0; i < 2; i++) {
const controller = i == 0 ? player : 1 - player;
const field = i == 0 ? _field & 0xffff : _field >> 16;
const controller = i === 0 ? player : 1 - player;
const field = i === 0 ? _field & 0xffff : _field >> 16;
if ((field & 0x7f) != 0) {
if ((field & 0x7f) !== 0) {
// 怪兽区
const zone = ygopro.CardZone.MZONE;
const filter = field & 0x7f;
for (let sequence = 0; sequence < 7; sequence++) {
if ((filter & (1 << sequence)) != 0) {
if ((filter & (1 << sequence)) !== 0) {
msg.places.push(
new MsgSelectPlace.SelectAblePlace({
controller,
zone,
sequence: sequence,
})
}),
);
}
}
}
if ((field & 0x1f00) != 0) {
if ((field & 0x1f00) !== 0) {
// 魔法陷阱区
const zone = ygopro.CardZone.SZONE;
const filter = (field >> 8) & 0x1f;
for (let sequence = 0; sequence < 5; sequence++) {
if ((filter & (1 << sequence)) != 0) {
if ((filter & (1 << sequence)) !== 0) {
msg.places.push(
new MsgSelectPlace.SelectAblePlace({
controller,
zone,
sequence,
})
}),
);
}
}
}
if ((field & 0xc000) != 0) {
if ((field & 0xc000) !== 0) {
// 灵摆区?
const zone = ygopro.CardZone.SZONE;
const filter = (field >> 14) & 0x3;
if ((filter & 0x1) != 0) {
if ((filter & 0x1) !== 0) {
msg.places.push(
new MsgSelectPlace.SelectAblePlace({
controller,
zone,
sequence: 6,
})
}),
);
}
if ((filter & 0x2) != 0) {
if ((filter & 0x2) !== 0) {
msg.places.push(
new MsgSelectPlace.SelectAblePlace({
controller,
zone,
sequence: 7,
})
}),
);
}
}
......
......@@ -28,28 +28,28 @@ export default (data: Uint8Array) => {
msg.positions.push(
new MsgSelectPosition.SelectAblePosition({
position: ygopro.CardPosition.FACEUP_ATTACK,
})
}),
);
}
if ((positions & 0x2) > 0) {
msg.positions.push(
new MsgSelectPosition.SelectAblePosition({
position: ygopro.CardPosition.FACEDOWN_ATTACK,
})
}),
);
}
if ((positions & 0x4) > 0) {
msg.positions.push(
new MsgSelectPosition.SelectAblePosition({
position: ygopro.CardPosition.FACEUP_DEFENSE,
})
}),
);
}
if ((positions & 0x8) > 0) {
msg.positions.push(
new MsgSelectPosition.SelectAblePosition({
position: ygopro.CardPosition.FACEDOWN_DEFENSE,
})
}),
);
}
......
......@@ -41,7 +41,7 @@ export default (data: Uint8Array) => {
level1: para & 0xffff,
level2: para >> 16,
response: i,
})
}),
);
}
......@@ -60,7 +60,7 @@ export default (data: Uint8Array) => {
level1,
level2,
response: i,
})
}),
);
}
......
......@@ -13,7 +13,7 @@ export default (data: Uint8Array) => {
const reader = new BufferReaderExt(data);
const player = reader.inner.readUint8();
const cancelable = reader.inner.readUint8() != 0;
const cancelable = reader.inner.readUint8() !== 0;
const min = reader.inner.readUint8();
const max = reader.inner.readUint8();
const count = reader.inner.readUint8();
......@@ -37,7 +37,7 @@ export default (data: Uint8Array) => {
location,
level,
response: i,
})
}),
);
}
......
......@@ -13,8 +13,8 @@ export default (data: Uint8Array) => {
const reader = new BufferReaderExt(data);
const player = reader.inner.readUint8();
const finishable = reader.inner.readUint8() != 0;
const cancelable = reader.inner.readUint8() != 0;
const finishable = reader.inner.readUint8() !== 0;
const cancelable = reader.inner.readUint8() !== 0;
const min = reader.inner.readUint8();
const max = reader.inner.readUint8();
......@@ -32,7 +32,7 @@ export default (data: Uint8Array) => {
const location = reader.readCardLocation();
msg.selectable_cards.push(
new MsgSelectUnselectCard.Info({ code, location, response: i })
new MsgSelectUnselectCard.Info({ code, location, response: i }),
);
}
......@@ -42,7 +42,7 @@ export default (data: Uint8Array) => {
const location = reader.readCardLocation();
msg.selected_cards.push(
new MsgSelectUnselectCard.Info({ code, location, response: i })
new MsgSelectUnselectCard.Info({ code, location, response: i }),
);
}
......
......@@ -16,7 +16,7 @@ export default (data: Uint8Array) => {
const name_0 = cutString(decoder.decode(data.slice(offset, offset + LEN)));
offset += LEN;
const name_0_tag = cutString(
decoder.decode(data.slice(offset, offset + LEN))
decoder.decode(data.slice(offset, offset + LEN)),
);
offset += LEN;
const name_0_c = cutString(decoder.decode(data.slice(offset, offset + LEN)));
......@@ -24,7 +24,7 @@ export default (data: Uint8Array) => {
const name_1 = cutString(decoder.decode(data.slice(offset, offset + LEN)));
offset += LEN;
const name_1_tag = cutString(
decoder.decode(data.slice(offset, offset + LEN))
decoder.decode(data.slice(offset, offset + LEN)),
);
offset += LEN;
const name_1_c = cutString(decoder.decode(data.slice(offset, offset + LEN)));
......
......@@ -29,7 +29,7 @@ export default (data: Uint8Array) => {
code,
location,
response: i,
})
}),
);
}
......
......@@ -50,7 +50,7 @@ export default (data: Uint8Array) => {
try {
while (true) {
const len = reader.inner.readInt32();
if (len == 4) continue;
if (len === 4) continue;
const pos = reader.inner.offset();
const action = _readUpdateAction(reader);
if (action) {
......@@ -66,10 +66,10 @@ export default (data: Uint8Array) => {
};
function _readUpdateAction(
reader: BufferReaderExt
reader: BufferReaderExt,
): MsgUpdateData.Action | undefined {
const flag = reader.inner.readInt32();
if (flag == 0) return undefined;
if (flag === 0) return undefined;
const mask = -1;
let code = mask;
......
......@@ -24,7 +24,7 @@ export default class HsPlayerEnterAdapter implements StocAdapter {
const decoder = new TextDecoder("utf-16");
const name = decoder.decode(
_cutoff_name(exData.slice(0, UTF16_BUFFER_MAX_LEN * UINT8_PER_UINT16))
_cutoff_name(exData.slice(0, UTF16_BUFFER_MAX_LEN * UINT8_PER_UINT16)),
);
const dataView = new DataView(exData.buffer);
......
......@@ -17,7 +17,7 @@ export default class TypeChangeAdapter implements StocAdapter {
upcast(): ygopro.YgoStocMsg {
const type_ = new DataView(this.packet.exData.buffer).getUint8(0);
const isHost = ((type_ >> 4) & 0xf) != 0;
const isHost = ((type_ >> 4) & 0xf) !== 0;
let selfType = ygopro.StocTypeChange.SelfType.UNKNOWN;
switch (type_ & 0xf) {
......
......@@ -67,7 +67,7 @@ export function utf8ArrayToStr(array: Uint8Array) {
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
);
break;
}
......@@ -115,7 +115,7 @@ export function cardZoneToNumber(zone: ygopro.CardZone): number {
}
export function numberToCardZone(
location: number
location: number,
): ygopro.CardZone | undefined {
switch (location) {
case 0x01: {
......@@ -156,7 +156,7 @@ export function numberToCardZone(
// TODO: 需要考虑超量叠加情况下的位运算
export function numberToCardPosition(
position: number
position: number,
): ygopro.CardPosition | undefined {
switch (position) {
case 0x1: {
......@@ -190,7 +190,7 @@ export function numberToCardPosition(
}
export function numberToChainFlag(
flag: number
flag: number,
): ygopro.StocGameMessage.MsgSelectChain.ChainFlag | undefined {
switch (flag) {
case 0: {
......@@ -218,7 +218,7 @@ const chunkItems = <T>(items: T[]) =>
export function _cutoff_name(data: Uint8Array): Uint8Array {
let res: number[] = [];
for (const char of chunkItems(Array.from(data))) {
if (!char.every((item) => item == 0)) {
if (!char.every((item) => item === 0)) {
res = res.concat(char);
} else {
break;
......
......@@ -273,7 +273,7 @@ export function sendSelectBattleCmdResponse(value: number) {
select_battle_cmd: new ygopro.CtosGameMsgResponse.SelectBattleCmdResponse(
{
selected_cmd: value,
}
},
),
}),
});
......
......@@ -7,4 +7,4 @@ export const useConfig = () =>
automation: automationConfig,
defaults: defaultsConfig,
...envConfig,
} satisfies Record<string, unknown>);
}) satisfies Record<string, unknown>;
......@@ -21,7 +21,7 @@ declare global {
interface Console {
color: (
color: string,
backgroundColor?: string
backgroundColor?: string,
) => (...args: Parameters<console.log>) => void;
}
}
......
......@@ -3,7 +3,7 @@ console.color =
(...args: any[]) => {
console.log(
`%c${args.join(" ")}`,
`color: ${color}; backgroundColor: ${backgroundColor ?? "none"}`
`color: ${color}; backgroundColor: ${backgroundColor ?? "none"}`,
);
};
......
......@@ -16,14 +16,14 @@ const getEnd = (task: Task) => `${task}-end`;
/** 在组件之中注册方法,注意注册的方法一旦执行成功,必须返回一个true */
const register = <T extends unknown[]>(
task: Task,
fn: (...args: T) => Promise<boolean>
fn: (...args: T) => Promise<boolean>,
) => {
eventEmitter.on(
task,
async ({ taskId, args }: { taskId: string; args: T }) => {
const result = await fn(...args);
if (result) eventEmitter.emit(getEnd(task), taskId);
}
},
);
};
......
......@@ -4,7 +4,7 @@ export async function pfetch(
options?: {
init?: RequestInit;
progressCallback?: (progress: number) => void;
}
},
): Promise<Response> {
const response = await fetch(input, options?.init);
const clonedResponse = response.clone(); // Clone the response to create a new body stream
......@@ -12,7 +12,7 @@ export async function pfetch(
if (typeof options?.progressCallback === "function") {
const contentLength = parseInt(
response.headers.get("content-length") || "0",
10
10,
);
let bytesRead = 0;
......
......@@ -30,7 +30,7 @@ import { theme } from "@/ui/theme";
import { NeosRouter } from "./ui/NeosRouter";
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
document.getElementById("root") as HTMLElement,
);
root.render(
......@@ -40,5 +40,5 @@ root.render(
<NeosRouter />
</ProConfigProvider>
</App>
</ConfigProvider>
</ConfigProvider>,
);
......@@ -44,7 +44,7 @@ export default async function (action: socketAction) {
const { initInfo: info, isReplay, replayInfo } = action;
if (info) {
ws = new WebSocketStream(info.ip, (conn, _event) =>
handleSocketOpen(conn, info.ip, info.player, info.passWd)
handleSocketOpen(conn, info.ip, info.player, info.passWd),
);
await ws.execute(handleSocketMessage);
......
......@@ -59,13 +59,13 @@ function getFtsCondtions(conditions: FtsConditions): string {
const atkCondition = atk
? `atk BETWEEN ${handleFinite(atk.min, "min")} AND ${handleFinite(
atk.max,
"max"
"max",
)} AND ${assertMonster}`
: undefined;
const defCondition = def
? `def BETWEEN ${handleFinite(def.min, "min")} AND ${handleFinite(
def.max,
"max"
"max",
)} AND ${assertMonster}`
: undefined;
const raceCondition = races?.map((race) => `race = ${race}`).join(" OR ");
......
......@@ -110,7 +110,7 @@ export default async function (action: sqliteAction): Promise<sqliteResult> {
export function constructCardMeta(
id: number,
data: CardData,
text: CardText
text: CardText,
): CardMeta {
const level = data.level ?? 0;
data.level = level & 0xff;
......
......@@ -11,7 +11,7 @@ export default async (attack: ygopro.StocGameMessage.MsgAttack) => {
const attacker = cardStore.at(
attack.attacker_location.zone,
attack.attacker_location.controller,
attack.attacker_location.sequence
attack.attacker_location.sequence,
);
if (attacker) {
......
......@@ -6,7 +6,7 @@ export default (becomeTarget: ygopro.StocGameMessage.MsgBecomeTarget) => {
const target = cardStore.at(
location.zone,
location.controller,
location.sequence
location.sequence,
);
if (target) {
console.info(`${target.meta.text.name} become target`);
......
......@@ -23,7 +23,7 @@ export default async (chainSolved: ygopro.StocGameMessage.MsgChainSolved) => {
}
} else {
console.warn(
`pop from chains return null! solved_index=${chainSolved.solved_index}, len of chains in store=${matStore.chains.length}`
`pop from chains return null! solved_index=${chainSolved.solved_index}, len of chains in store=${matStore.chains.length}`,
);
}
};
......@@ -28,6 +28,6 @@ export default async (draw: ygopro.StocGameMessage.MsgDraw) => {
await Promise.all(
cardStore
.at(ygopro.CardZone.HAND, draw.player)
.map((card) => callCardMove(card.uuid))
.map((card) => callCardMove(card.uuid)),
);
};
......@@ -53,7 +53,7 @@ export default async (move: MsgMove) => {
from.is_overlay ? ":" + from.overlay_sequence : ""
}${ygopro.CardZone[to.zone]}:${to.sequence}${
to.is_overlay ? ":" + to.overlay_sequence : ""
}`
}`,
);
let target: CardType;
......@@ -64,14 +64,14 @@ export default async (move: MsgMove) => {
from.zone,
from.controller,
from.sequence,
from.overlay_sequence
from.overlay_sequence,
);
if (overlayMaterial) {
target = overlayMaterial;
} else {
console.warn(
`<Move>overlayMaterial from zone=${from.zone}, controller=${from.controller},
sequence=${from.sequence}, overlay_sequence=${from.overlay_sequence} is null`
sequence=${from.sequence}, overlay_sequence=${from.overlay_sequence} is null`,
);
return;
}
......@@ -81,7 +81,7 @@ export default async (move: MsgMove) => {
target = card;
} else {
console.warn(
`<Move>card from zone=${from.zone}, controller=${from.controller} sequence=${from.sequence} is null`
`<Move>card from zone=${from.zone}, controller=${from.controller} sequence=${from.sequence} is null`,
);
console.info(cardStore.at(from.zone, from.controller));
return;
......@@ -106,7 +106,7 @@ export default async (move: MsgMove) => {
location.zone,
location.controller,
location.sequence,
location.overlay_sequence
location.overlay_sequence,
);
if (overlayMaterial) {
// 超量素材的位置应该和超量怪兽保持一致
......@@ -117,7 +117,7 @@ export default async (move: MsgMove) => {
await callCardMove(overlayMaterial.uuid);
} else {
console.warn(
`<Move>overlayMaterial from zone=${location.zone}, controller=${location.controller}, sequence=${location.sequence}, overlay_sequence=${location.overlay_sequence} is null`
`<Move>overlayMaterial from zone=${location.zone}, controller=${location.controller}, sequence=${location.sequence}, overlay_sequence=${location.overlay_sequence} is null`,
);
}
}
......@@ -132,11 +132,11 @@ export default async (move: MsgMove) => {
!from.is_overlay
)
fromCards.forEach(
(c) => c.location.sequence > from.sequence && c.location.sequence--
(c) => c.location.sequence > from.sequence && c.location.sequence--,
);
if ([HAND, GRAVE, REMOVED, DECK, EXTRA, TZONE].includes(to.zone))
toCards.forEach(
(c) => c.location.sequence >= to.sequence && c.location.sequence++
(c) => c.location.sequence >= to.sequence && c.location.sequence++,
);
if (from.is_overlay) {
// 超量素材的序号也需要维护
......@@ -144,7 +144,7 @@ export default async (move: MsgMove) => {
for (const overlay of cardStore.findOverlay(
from.zone,
from.controller,
from.sequence
from.sequence,
)) {
if (overlay.location.overlay_sequence > overlay_sequence) {
overlay.location.overlay_sequence--;
......@@ -174,7 +174,7 @@ export default async (move: MsgMove) => {
for (const overlay of cardStore.findOverlay(
from.zone,
from.controller,
from.sequence
from.sequence,
)) {
overlay.location.zone = to.zone;
overlay.location.controller = to.controller;
......
......@@ -41,7 +41,7 @@ export default (selectBattleCmd: MsgSelectBattleCmd) => {
});
} else {
console.warn(
`<selectBattleCmd>target from zone=${location}, player=${player}, sequence=${sequence} is null`
`<selectBattleCmd>target from zone=${location}, player=${player}, sequence=${sequence} is null`,
);
}
} else {
......@@ -54,7 +54,7 @@ export default (selectBattleCmd: MsgSelectBattleCmd) => {
};
function battleTypeToInteracType(
battleType: MsgSelectBattleCmd.BattleCmd.BattleType
battleType: MsgSelectBattleCmd.BattleCmd.BattleType,
): InteractType | undefined {
switch (battleType) {
case MsgSelectBattleCmd.BattleCmd.BattleType.ATTACK: {
......
......@@ -11,7 +11,7 @@ export default async (selectCard: MsgSelectCard) => {
// TODO: handle release_param
const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta(
cards
cards,
);
await displaySelectActionsModal({
cancelable,
......
......@@ -13,7 +13,7 @@ export default async (selectChain: MsgSelectChain) => {
const chains = selectChain.chains;
const chainSetting = matStore.chainSetting;
if (chainSetting == ChainSetting.CHAIN_IGNORE) {
if (chainSetting === ChainSetting.CHAIN_IGNORE) {
// 如果玩家配置了忽略连锁,直接回应后端并返回
sendSelectSingleResponse(-1);
return;
......@@ -28,7 +28,7 @@ export default async (selectChain: MsgSelectChain) => {
// 直接回答
handle_flag = 0;
} else {
if (chainSetting == ChainSetting.CHAIN_ALL) {
if (chainSetting === ChainSetting.CHAIN_ALL) {
// 配置了全部连锁,则处理多张
handle_flag = 2;
} else {
......@@ -71,7 +71,7 @@ export default async (selectChain: MsgSelectChain) => {
selectHintData: 203,
});
const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta(
chains
chains,
);
await displaySelectActionsModal({
isChain: true,
......
......@@ -15,11 +15,11 @@ export default async (selectEffectYn: MsgSelectEffectYn) => {
? (
desc: string,
cardMeta: CardMeta,
cardLocation: ygopro.CardLocation
cardLocation: ygopro.CardLocation,
) => {
const desc1 = desc.replace(
`[%ls]`,
fetchStrings(Region.System, cardLocation.zone + 1000)
fetchStrings(Region.System, cardLocation.zone + 1000),
);
const desc2 = desc1.replace(`[%ls]`, cardMeta.text.name || "[?]");
return desc2;
......
......@@ -40,7 +40,7 @@ export default (selectIdleCmd: MsgSelectIdleCmd) => {
});
} else {
console.warn(
`target from zone=${location}, controller=${player}, sequence=${sequence} is null`
`target from zone=${location}, controller=${player}, sequence=${sequence} is null`,
);
}
} else {
......@@ -54,7 +54,7 @@ export default (selectIdleCmd: MsgSelectIdleCmd) => {
};
function idleTypeToInteractType(
idleType: MsgSelectIdleCmd.IdleCmd.IdleType
idleType: MsgSelectIdleCmd.IdleCmd.IdleType,
): InteractType | undefined {
switch (idleType) {
case MsgSelectIdleCmd.IdleCmd.IdleType.SUMMON: {
......
......@@ -16,7 +16,7 @@ export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
const meta = await fetchCard(code >> 4);
const msg = getCardStr(meta, code & 0xf) || "[?]";
return { msg, response };
})
)
}),
),
);
};
......@@ -4,7 +4,7 @@ import { InteractType, placeStore } from "@/stores";
type MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace;
export default (selectPlace: MsgSelectPlace) => {
if (selectPlace.count != 1) {
if (selectPlace.count !== 1) {
console.warn(`Unhandled case: ${selectPlace}`);
return;
}
......
......@@ -6,7 +6,7 @@ type MsgSelectPosition = ygopro.StocGameMessage.MsgSelectPosition;
export default async (selectPosition: MsgSelectPosition) => {
const _player = selectPosition.player;
const positions = selectPosition.positions.map(
(position) => position.position
(position) => position.position,
);
await displayPositionModal(positions);
};
......@@ -7,7 +7,7 @@ type MsgSelectTribute = ygopro.StocGameMessage.MsgSelectTribute;
export default async (selectTribute: MsgSelectTribute) => {
// TODO: 当玩家选择卡数大于`max`时,是否也合法?
const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta(
selectTribute.selectable_cards
selectTribute.selectable_cards,
);
await displaySelectActionsModal({
overflow: true,
......
......@@ -27,16 +27,16 @@ export default async (shuffleHandExtra: MsgShuffleHandExtra) => {
await callCardMove(card.uuid);
} else {
console.warn(
`<ShuffleHandExtra>sequence poped is none, controller=${controller}, code=${card.code}, sequence=${sequence}`
`<ShuffleHandExtra>sequence poped is none, controller=${controller}, code=${card.code}, sequence=${sequence}`,
);
}
} else {
console.warn(
`<ShuffleHandExtra>target from records is null, controller=${controller}, cards=${cards.map(
(card) => card.code
)}, codes=${codes}`
(card) => card.code,
)}, codes=${codes}`,
);
}
})
}),
);
};
......@@ -7,13 +7,13 @@ import MsgShuffleSetCard = ygopro.StocGameMessage.MsgShuffleSetCard;
export default async (shuffleSetCard: MsgShuffleSetCard) => {
const from_locations = shuffleSetCard.from_locations;
const overlay_locations = shuffleSetCard.overlay_locations;
if (from_locations.length == 0) {
if (from_locations.length === 0) {
console.error("<ShuffleSetCard>from_locations is empty");
return;
}
if (from_locations.length != overlay_locations.length) {
if (from_locations.length !== overlay_locations.length) {
console.error(
"<ShuffleSetCard>length of from_locations and overlay_locations not matched"
"<ShuffleSetCard>length of from_locations and overlay_locations not matched",
);
}
......@@ -39,7 +39,7 @@ export default async (shuffleSetCard: MsgShuffleSetCard) => {
for (const overlay of cardStore.findOverlay(
from.zone,
from.controller,
from.sequence
from.sequence,
)) {
// 更新sequence
overlay.location.sequence = overlay_location.sequence;
......@@ -48,6 +48,6 @@ export default async (shuffleSetCard: MsgShuffleSetCard) => {
// 这里其实有个疑惑,如果超量素材也跟着洗切的话,洗切的意义好像就没有了,感觉算是个k社没想好的设计?
}
}
})
}),
);
};
......@@ -11,7 +11,7 @@ export default async (sortCard: MsgSortCard) => {
meta,
response: response!,
};
})
}),
);
await displaySortCardModal(options);
};
......@@ -69,9 +69,9 @@ export default async (start: ygopro.StocGameMessage.MsgStart) => {
},
isToken: !((i + 1) % 3),
selected: false,
})
)
)
}),
),
),
);
cardStore.inner.push(...cards);
......
......@@ -23,7 +23,7 @@ export default async (updateData: MsgUpdateData) => {
const meta = target.meta;
if (action.location !== undefined) {
if (target.location.position != action.location.position) {
if (target.location.position !== action.location.position) {
// Currently only update position
target.location.position = action.location.position;
// animation
......@@ -51,7 +51,7 @@ export default async (updateData: MsgUpdateData) => {
// TODO: counters
} else {
console.warn(
`<UpdateData>target from zone=${zone}, controller=${controller}, sequence=${sequence} is null`
`<UpdateData>target from zone=${zone}, controller=${controller}, sequence=${sequence} is null`,
);
console.info(field);
}
......
......@@ -8,6 +8,6 @@ export default async (win: MsgWin) => {
await displayEndModal(
matStore.isMe(win_player),
fetchStrings(Region.Victory, `0x${reason.toString(16)}`)
fetchStrings(Region.Victory, `0x${reason.toString(16)}`),
);
};
......@@ -15,7 +15,7 @@ export default function handleSocketOpen(
ws: WebSocket | undefined,
_ip: string,
player: string,
passWd: string
passWd: string,
) {
console.log("WebSocket opened.");
......
......@@ -19,7 +19,7 @@ export default function handleHsPlayerChange(pb: ygopro.YgoStocMsg) {
"<HsPlayerChange>Player " +
change.pos +
" moved to " +
change.moved_pos
change.moved_pos,
);
roomStore.players[change.moved_pos] = roomStore.players[change.pos];
roomStore.players[change.pos] = undefined;
......
......@@ -23,11 +23,11 @@ const helper = async (
mustSelects: Option[],
selectables: Option[],
selected?: boolean,
mustSelect?: boolean
mustSelect?: boolean,
) => {
const controller = location.controller;
const newID =
code != 0
code !== 0
? code
: cardStore.at(location.zone, controller, location.sequence)?.code || 0;
const meta = await fetchCard(newID);
......@@ -63,7 +63,7 @@ export const fetchCheckCardMeta = async (
effect_description?: number;
}[],
selected?: boolean,
mustSelect?: boolean
mustSelect?: boolean,
) => {
const selecteds: Option[] = [];
const mustSelects: Option[] = [];
......@@ -75,7 +75,7 @@ export const fetchCheckCardMeta = async (
mustSelects,
selectables,
selected,
mustSelect
mustSelect,
); // TODO: 研究下改成并行
}
return { selecteds, mustSelects, selectables };
......
......@@ -34,13 +34,13 @@ class CardStore implements NeosStore {
zone: ygopro.CardZone,
controller: number,
sequence?: number,
overlay_sequence?: number
overlay_sequence?: number,
): CardType | undefined;
at(
zone: ygopro.CardZone,
controller: number,
sequence?: number,
overlay_sequence?: number
overlay_sequence?: number,
) {
if (sequence !== undefined) {
if (overlay_sequence !== undefined) {
......@@ -51,7 +51,7 @@ class CardStore implements NeosStore {
card.location.controller === controller &&
card.location.sequence === sequence &&
card.location.is_overlay === true &&
card.location.overlay_sequence === overlay_sequence
card.location.overlay_sequence === overlay_sequence,
)
.at(0);
} else {
......@@ -61,7 +61,7 @@ class CardStore implements NeosStore {
card.location.zone === zone &&
card.location.controller === controller &&
card.location.sequence === sequence &&
card.location.is_overlay === false
card.location.is_overlay === false,
)
.at(0);
}
......@@ -70,7 +70,7 @@ class CardStore implements NeosStore {
(card) =>
card.location.zone === zone &&
card.location.controller === controller &&
card.location.is_overlay === false
card.location.is_overlay === false,
);
}
}
......@@ -81,14 +81,14 @@ class CardStore implements NeosStore {
findOverlay(
zone: ygopro.CardZone,
controller: number,
sequence: number
sequence: number,
): CardType[] {
return this.inner.filter(
(card) =>
card.location.zone === zone &&
card.location.controller === controller &&
card.location.sequence === sequence &&
card.location.is_overlay
card.location.is_overlay,
);
}
reset(): void {
......
......@@ -22,7 +22,7 @@ export const deckStore = proxy({
async update(deckName: string, deck: IDeck): Promise<boolean> {
const index = deckStore.decks.findIndex(
(deck) => deck.deckName === deckName
(deck) => deck.deckName === deckName,
);
if (index === -1) return false;
deckStore.decks[index] = deck;
......@@ -40,7 +40,7 @@ export const deckStore = proxy({
async delete(deckName: string): Promise<boolean> {
const index = deckStore.decks.findIndex(
(deck) => deck.deckName === deckName
(deck) => deck.deckName === deckName,
);
if (index === -1) return false;
deckStore.decks.splice(index, 1);
......
......@@ -25,7 +25,7 @@ export const fetchSelectHintMeta = async ({
const cardMeta = await fetchCard(selectHintData);
selectHintMeta = fetchStrings(Region.System, 569).replace(
"[%ls]",
cardMeta.text.name || "[?]"
cardMeta.text.name || "[?]",
);
} else {
selectHintMeta = await getStrings(selectHintData);
......@@ -67,7 +67,7 @@ export const fetchEsHintMeta = async ({
const fieldMeta = cardStore.at(
location.zone,
location.controller,
location.sequence
location.sequence,
);
if (fieldMeta?.meta.text.name) {
esHint = esHint.replace("[?]", fieldMeta.meta.text.name);
......
......@@ -28,7 +28,7 @@ export const isMe = (controller: number): boolean => {
default:
// 自己是观战者
// 这里假设偶数方的玩家是自己
return controller % 2 == 0;
return controller % 2 === 0;
}
};
......
......@@ -54,7 +54,7 @@ class PlaceStore implements NeosStore {
zone: ygopro.CardZone.MZONE | ygopro.CardZone.SZONE,
controller: number,
sequence: number,
state: BlockState
state: BlockState,
) {
placeStore.inner[zone][matStore.isMe(controller) ? "me" : "op"][sequence] =
state;
......@@ -63,7 +63,7 @@ class PlaceStore implements NeosStore {
(["me", "op"] as const).forEach((who) => {
([MZONE, SZONE] as const).forEach((where) => {
placeStore.inner[where][who].forEach(
(block) => (block.interactivity = undefined)
(block) => (block.interactivity = undefined),
);
});
});
......
......@@ -36,7 +36,7 @@ export enum RoomStage {
class RoomStore implements NeosStore {
joined: boolean = false; // 是否已经加入房间
players: (Player | undefined)[] = Array.from({ length: 4 }).map(
(_) => undefined
(_) => undefined,
); // 进入房间的玩家列表
observerCount: number = 0; // 观战者数量
isHost: boolean = false; // 当前玩家是否是房主
......
......@@ -29,7 +29,7 @@ export const CardDetail: React.FC<{
extraCardTypes(card?.data.type ?? 0)
.map((t) => fetchStrings(Region.System, Type2StringCodeMap.get(t) || 0))
.join(" / "),
[card?.data.type]
[card?.data.type],
);
return (
<div className={classNames(styles.detail, { [styles.open]: open })}>
......@@ -59,7 +59,7 @@ export const CardDetail: React.FC<{
<Descriptions.Item label="属性">
{fetchStrings(
Region.System,
Attribute2StringCodeMap.get(card?.data.attribute ?? 0) || 0
Attribute2StringCodeMap.get(card?.data.attribute ?? 0) || 0,
)}
</Descriptions.Item>
)}
......@@ -67,7 +67,7 @@ export const CardDetail: React.FC<{
<Descriptions.Item label="种族" span={2}>
{fetchStrings(
Region.System,
Race2StringCodeMap.get(card?.data.race ?? 0) || 0
Race2StringCodeMap.get(card?.data.race ?? 0) || 0,
)}
</Descriptions.Item>
)}
......
......@@ -53,7 +53,7 @@ export const DeckSelect: React.FC<{
maskClosable: true,
onOk: async () => {
const results = await Promise.all(
newDeck.current.map((deck) => deckStore.add(deck))
newDeck.current.map((deck) => deckStore.add(deck)),
);
newDeck.current = [];
if (results.length)
......@@ -186,7 +186,7 @@ const DeckUploader: React.FC<{ onLoaded: (deck: IDeck) => void }> = ({
name: "file",
multiple: true,
onChange(info) {
if (uploadState != "ERROR") {
if (uploadState !== "ERROR") {
info.file.status = "done";
}
},
......
......@@ -218,7 +218,7 @@ const Search: React.FC = () => {
types: [],
};
const [searchConditions, setSearchConditions] = useState<FtsConditions>(
emptySearchConditions
emptySearchConditions,
);
const [searchResult, setSearchResult] = useState<CardMeta[]>([]);
......@@ -236,7 +236,7 @@ const Search: React.FC = () => {
return () =>
setSortRef(
(a: CardMeta, b: CardMeta) =>
((a.data?.[key] ?? 0) - (b.data?.[key] ?? 0)) * scale
((a.data?.[key] ?? 0) - (b.data?.[key] ?? 0)) * scale,
);
};
......@@ -409,7 +409,7 @@ const DeckZone: React.FC<{
},
hover: ({ value, source }) => {
setAllowToDrop(
type !== source ? editDeckStore.canAdd(value, type).result : true
type !== source ? editDeckStore.canAdd(value, type).result : true,
);
},
collect: (monitor) => ({
......
......@@ -13,7 +13,7 @@ export interface EditingDeck {
}
export const iDeckToEditingDeck = async (
ideck: IDeck
ideck: IDeck,
): Promise<EditingDeck> => ({
deckName: ideck.deckName,
main: await Promise.all(ideck.main.map(fetchCard)),
......
......@@ -35,7 +35,7 @@ export const AnnounceModal = () => {
open={isOpen}
footer={
<Button
disabled={selected.length != min}
disabled={selected.length !== min}
onClick={() => {
let response = selected.reduce((res, current) => res | current, 0); // 多个选择求或
sendSelectOptionResponse(response);
......@@ -65,7 +65,7 @@ export const AnnounceModal = () => {
let rs: (arg?: any) => void = () => {};
export const displayAnnounceModal = async (
args: Omit<AnnounceModalProps, "isOpen">
args: Omit<AnnounceModalProps, "isOpen">,
) => {
Object.entries(args).forEach(([key, value]) => {
// @ts-ignore
......
......@@ -33,7 +33,7 @@ export const CardListModal = () => {
cardList = cardStore.findOverlay(
monster.location.zone,
monster.location.controller,
monster.location.sequence
monster.location.sequence,
);
}
......
......@@ -24,7 +24,7 @@ const RegexWrapper: React.FC<{
const matches = text.match(re);
if (!matches) return <>{text}</>;
const sepRe = new RegExp(
matches?.reduce((acc, cur) => `${acc}|${cur}`) ?? ""
matches?.reduce((acc, cur) => `${acc}|${cur}`) ?? "",
);
const parts = text.split(sepRe);
return (
......
......@@ -104,7 +104,7 @@ const AttLine = (props: {
const attribute = props.attribute
? fetchStrings(
Region.System,
Attribute2StringCodeMap.get(props.attribute) || 0
Attribute2StringCodeMap.get(props.attribute) || 0,
)
: undefined;
const types = props.types
......@@ -153,7 +153,7 @@ const _CounterLine = (props: { counters: { [type: number]: number } }) => {
};
export const showCardModal = (
card: Partial<Pick<typeof store, "meta" | "counters">>
card: Partial<Pick<typeof store, "meta" | "counters">>,
) => {
store.isOpen = true;
store.meta = card?.meta ?? defaultStore.meta;
......
......@@ -34,7 +34,7 @@ export const CheckCounterModal = () => {
const options = snapCheckCounterModal.options;
const counterName = fetchStrings(
Region.Counter,
`0x${snapCheckCounterModal.counterType!}`
`0x${snapCheckCounterModal.counterType!}`,
); // FIXME: 这里转十六进制的逻辑有问题
const [selected, setSelected] = useState(new Array(options.length));
......@@ -93,7 +93,7 @@ export const CheckCounterModal = () => {
let rs: (arg?: any) => void = () => {};
export const displayCheckCounterModal = async (
args: Omit<CheckCounterModalProps, "isOpen">
args: Omit<CheckCounterModalProps, "isOpen">,
) => {
Object.entries(args).forEach(([key, value]) => {
// @ts-ignore
......
......@@ -59,7 +59,7 @@ export const HintNotification = () => {
if (meHand !== HandResult.UNKNOWN && opHand !== HandResult.UNKNOWN) {
notify.open({
message: `{我方出示${getHandResultText(
meHand
meHand,
)},对方出示${getHandResultText(opHand)}}`,
placement: "topLeft",
style: style,
......@@ -71,7 +71,7 @@ export const HintNotification = () => {
if (currentPhase) {
const message = fetchStrings(
Region.System,
Phase2StringCodeMap.get(currentPhase) ?? 0
Phase2StringCodeMap.get(currentPhase) ?? 0,
);
notify.open({
message,
......@@ -79,7 +79,7 @@ export const HintNotification = () => {
style: style,
});
console.color("DeepPink")(
`${message}(${matStore.isMe(matStore.currentPlayer) ? "me" : "op"})`
`${message}(${matStore.isMe(matStore.currentPlayer) ? "me" : "op"})`,
);
}
}, [currentPhase]);
......
......@@ -71,7 +71,7 @@ export const handleEffectActivation = async (
desc: string;
response: number;
effectCode: number | undefined;
}[]
}[],
) => {
if (!effectInteractivies.length) {
return;
......
......@@ -19,7 +19,7 @@ const localStore = proxy<PositionModalProps>(defaultProps);
export const PositionModal = () => {
const { isOpen, positions } = useSnapshot(localStore);
const [selected, setSelected] = useState<ygopro.CardPosition | undefined>(
undefined
undefined,
);
return (
......@@ -84,7 +84,7 @@ function cardPositionToChinese(position: ygopro.CardPosition): string {
let rs: (arg?: any) => void = () => {};
export const displayPositionModal = async (
positions: ygopro.CardPosition[]
positions: ygopro.CardPosition[],
) => {
localStore.positions = positions;
localStore.isOpen = true;
......
......@@ -69,7 +69,7 @@ export const SelectActionsModal: React.FC = () => {
let rs: (v?: any) => void = () => {};
export const displaySelectActionsModal = async (
args: Partial<Omit<typeof defaultProps, "isOpen">>
args: Partial<Omit<typeof defaultProps, "isOpen">>,
) => {
resetSelectActionsModal(); // 先重置为初始状态
Object.entries(args).forEach(([key, value]) => {
......
......@@ -65,7 +65,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
const [sumLevel1, sumLevel2] = (["level1", "level2"] as const).map((key) =>
[...mustSelects, ...result]
.map((option) => option[key] || 0)
.reduce((sum, current) => sum + current, 0)
.reduce((sum, current) => sum + current, 0),
);
const levelMatched = overflow
? sumLevel1 >= totalLevels || sumLevel2 >= totalLevels
......@@ -73,7 +73,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
setSubmitable(
single
? result.length === 1
: result.length >= min && result.length <= max && levelMatched
: result.length >= min && result.length <= max && levelMatched,
);
}, [result.length]);
......@@ -91,7 +91,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
}, [selectables]);
const [submitText, finishText, cancelText] = [1211, 1296, 1295].map((n) =>
fetchStrings(Region.System, n)
fetchStrings(Region.System, n),
);
return (
......@@ -167,7 +167,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
))}
</CheckCard.Group>
</div>
)
),
)}
<p>
<span>
......
......@@ -35,12 +35,12 @@ export const SimpleSelectCardsModal: React.FC = () => {
let rs: (options: Snapshot<Option[]>) => void = () => {};
export const displaySimpleSelectCardsModal = async (
args: Omit<typeof defaultProps, "isOpen">
args: Omit<typeof defaultProps, "isOpen">,
) => {
localStore.selectables = args.selectables;
localStore.isOpen = true;
const res = await new Promise<Snapshot<Option[]>>(
(resolve) => (rs = resolve)
(resolve) => (rs = resolve),
); // 等待在组件内resolve
localStore.isOpen = false;
return res;
......
......@@ -50,7 +50,7 @@ export const SortCardModal = () => {
useSensor(PointerSensor),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
})
}),
);
const onFinish = () => {
......
......@@ -54,7 +54,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
focusOpacity: 1,
subZ: 0,
opacity: 1,
} satisfies SpringApiProps)
}) satisfies SpringApiProps,
);
// 每张卡都需要移动到初始位置
......@@ -76,7 +76,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
const register = <T extends any[]>(
task: Task,
fn: (...args: T) => Promise<unknown>
fn: (...args: T) => Promise<unknown>,
) => {
eventbus.register(task, async (uuid, ...rest: T) => {
if (uuid === card.uuid) {
......@@ -108,7 +108,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
useEffect(() => {
setGrowing(
!!idleInteractivities.length &&
[MZONE, SZONE, HAND, TZONE].includes(card.location.zone)
[MZONE, SZONE, HAND, TZONE].includes(card.location.zone),
);
}, [idleInteractivities]);
......@@ -142,7 +142,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
}
const actions = [...map.entries()];
const nonEffectActions = actions.filter(
([action]) => action !== InteractType.ACTIVATE
([action]) => action !== InteractType.ACTIVATE,
);
const getNonEffectResponse = (action: InteractType, card: CardType) =>
card.idleInteractivities.find((item) => item.interactType === action)!
......@@ -170,17 +170,17 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
sendSelectIdleCmdResponse(option[0].response!);
}
},
})
}),
);
const hasEffect =
cards.reduce(
(prev, acc) => [
...prev,
...acc.idleInteractivities.filter(
({ interactType }) => interactType === InteractType.ACTIVATE
({ interactType }) => interactType === InteractType.ACTIVATE,
),
],
[] as Interactivity<number>[]
[] as Interactivity<number>[],
).length > 0;
const effectItem: DropdownItem = {
key: nonEffectItem.length,
......@@ -200,8 +200,9 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
.filter(
(card) =>
card.idleInteractivities.find(
({ interactType }) => interactType === InteractType.ACTIVATE
) !== undefined
({ interactType }) =>
interactType === InteractType.ACTIVATE,
) !== undefined,
)
.map((card) => ({
meta: card.meta,
......@@ -215,14 +216,14 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
handleEffectActivation(
tmpCard.idleInteractivities
.filter(
({ interactType }) => interactType === InteractType.ACTIVATE
({ interactType }) => interactType === InteractType.ACTIVATE,
)
.map((x) => ({
desc: interactTypeToString(x.interactType),
response: x.response,
effectCode: x.activateIndex,
})),
tmpCard.meta
tmpCard.meta,
);
},
};
......@@ -242,7 +243,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
const overlayMaterials = cardStore.findOverlay(
card.location.zone,
card.location.controller,
card.location.sequence
card.location.sequence,
);
if (overlayMaterials.length > 0) {
displayCardListModal({
......@@ -279,7 +280,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
transform: to(
[spring.x, spring.y, spring.z, spring.rx, spring.ry, spring.rz],
(x, y, z, rx, ry, rz) =>
`translate(${x}px, ${y}px) rotateX(${rx}deg) rotateZ(${rz}deg)`
`translate(${x}px, ${y}px) rotateX(${rx}deg) rotateZ(${rz}deg)`,
),
"--z": spring.z,
"--sub-z": spring.subZ.to([0, 50, 100], [0, 200, 0]), // 中间高,两边低
......@@ -335,7 +336,7 @@ type DropdownItem = NonNullable<MenuProps["items"]>[number] & {
const handleEffectActivation = (
effectInteractivies: Interactivy[],
meta?: CardMeta
meta?: CardMeta,
) => {
if (!effectInteractivies.length) return;
else if (effectInteractivies.length === 1) {
......
......@@ -8,8 +8,8 @@ import { asyncStart } from "./utils";
export const focus = async (props: { card: CardType; api: SpringApi }) => {
const { card, api } = props;
if (
card.location.zone == ygopro.CardZone.HAND ||
card.location.zone == ygopro.CardZone.DECK
card.location.zone === ygopro.CardZone.HAND ||
card.location.zone === ygopro.CardZone.DECK
) {
const current = { ...api.current[0].get() };
await asyncStart(api)({
......
......@@ -31,7 +31,7 @@ export const moveToHand: MoveFunc = async (props) => {
const THETA =
2 *
Math.atan(
hand_card_width / 2 / (HAND_CIRCLE_CENTER_OFFSET_Y + HAND_CARD_HEIGHT)
hand_card_width / 2 / (HAND_CIRCLE_CENTER_OFFSET_Y + HAND_CARD_HEIGHT),
) *
0.9;
// 接下来计算每一张手卡
......
......@@ -61,7 +61,7 @@ export const Menu = () => {
phase: PhaseType,
label: string,
response: number,
show: boolean
show: boolean,
][] = [
[PhaseType.DRAW, "抽卡阶段", -1, true],
[PhaseType.STANDBY, "准备阶段", -1, true],
......@@ -122,7 +122,7 @@ export const Menu = () => {
onClick: () => {
matStore.chainSetting = key;
},
})
}),
);
const surrenderMenuItems: MenuProps["items"] = [
......@@ -176,7 +176,7 @@ export const Menu = () => {
};
const DropdownWithTitle: React.FC<DropdownProps & { title?: string }> = (
props
props,
) => {
const { token } = useToken();
const contentStyle = {
......
export const groupBy = <K, V extends Record<string, any>>(
array: readonly V[],
getKey: (cur: V, idx: number, src: readonly V[]) => K
getKey: (cur: V, idx: number, src: readonly V[]) => K,
): [K, V[]][] =>
Array.from(
array.reduce((map, cur, idx, src) => {
......@@ -9,5 +9,5 @@ export const groupBy = <K, V extends Record<string, any>>(
if (list) list.push(cur);
else map.set(key, [cur]);
return map;
}, new Map<K, V[]>())
}, new Map<K, V[]>()),
);
......@@ -43,7 +43,7 @@ const Icon: React.FC<{ type: string; size?: number }> = ({
export function interactTypeToIcon(
t: InteractType,
position?: CardPosition
position?: CardPosition,
): JSX.Element {
switch (t) {
case InteractType.POS_CHANGE:
......
export function zip<S1, S2>(
firstCollection: Array<S1>,
lastCollection: Array<S2>
lastCollection: Array<S2>,
): Array<[S1, S2]> {
const length = Math.min(firstCollection.length, lastCollection.length);
const zipped: Array<[S1, S2]> = [];
......
......@@ -33,7 +33,7 @@ export const MatchModal: React.FC = ({}) => {
const [player, setPlayer] = useState(user?.name ?? defaultPlayer);
const [passwd, setPasswd] = useState(defaultPassword);
const [server, setServer] = useState(
`${serverConfig[0].ip}:${serverConfig[0].port}`
`${serverConfig[0].ip}:${serverConfig[0].port}`,
);
const [confirmLoading, setConfirmLoading] = useState(false);
const navigate = useNavigate();
......
......@@ -18,7 +18,7 @@ const NeosConfig = useConfig();
export const Component: React.FC = () => {
const serverList = NeosConfig.servers;
const [server, setServer] = useState(
`${serverList[0].ip}:${serverList[0].port}`
`${serverList[0].ip}:${serverList[0].port}`,
);
const { decks } = useSnapshot(deckStore);
const [deck, setDeck] = useState<IDeck>(JSON.parse(JSON.stringify(decks[0])));
......
......@@ -5,7 +5,7 @@ import styles from "./index.module.scss";
/** HOC: 将组件发射到body下 */
export const withPortalToBody = <P extends object>(
WrappedComponent: React.ComponentType<P>
WrappedComponent: React.ComponentType<P>,
) => {
return (props: P) => {
useEffect(() => {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment