Commit 5d7ae541 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/parse/deck' into 'main'

Fix/parse/deck

See merge request mycard/Neos!119
parents 7b006221 76900895
Pipeline #20495 passed with stages
in 5 minutes and 47 seconds
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
"react-scripts": "^2.1.3", "react-scripts": "^2.1.3",
"socket.io-client": "^4.5.1", "socket.io-client": "^4.5.1",
"sql.js": "^1.8.0", "sql.js": "^1.8.0",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4",
"ygopro-deck-encode": "^1.0.3"
}, },
"devDependencies": { "devDependencies": {
"@babylonjs/core": "^5.29.0", "@babylonjs/core": "^5.29.0",
...@@ -14013,6 +14014,11 @@ ...@@ -14013,6 +14014,11 @@
"node": ">=4.0.0" "node": ">=4.0.0"
} }
}, },
"node_modules/js-base64": {
"version": "3.7.5",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz",
"integrity": "sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA=="
},
"node_modules/js-levenshtein": { "node_modules/js-levenshtein": {
"version": "1.1.6", "version": "1.1.6",
"resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz",
...@@ -26817,6 +26823,14 @@ ...@@ -26817,6 +26823,14 @@
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.2.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.2.tgz",
"integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==" "integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ=="
}, },
"node_modules/ygopro-deck-encode": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/ygopro-deck-encode/-/ygopro-deck-encode-1.0.3.tgz",
"integrity": "sha512-5JpaAdrIO4d2VnQRm+6T9S3JEp8ByXrFmXumAtCScvGYSc/31ianjafe76XVIFA8nSDJJCO8bzJF+C6CBwUONg==",
"dependencies": {
"js-base64": "^3.7.5"
}
},
"node_modules/yocto-queue": { "node_modules/yocto-queue": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
...@@ -37574,6 +37588,11 @@ ...@@ -37574,6 +37588,11 @@
"topo": "2.x.x" "topo": "2.x.x"
} }
}, },
"js-base64": {
"version": "3.7.5",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz",
"integrity": "sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA=="
},
"js-levenshtein": { "js-levenshtein": {
"version": "1.1.6", "version": "1.1.6",
"resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz",
...@@ -47493,6 +47512,14 @@ ...@@ -47493,6 +47512,14 @@
} }
} }
}, },
"ygopro-deck-encode": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/ygopro-deck-encode/-/ygopro-deck-encode-1.0.3.tgz",
"integrity": "sha512-5JpaAdrIO4d2VnQRm+6T9S3JEp8ByXrFmXumAtCScvGYSc/31ianjafe76XVIFA8nSDJJCO8bzJF+C6CBwUONg==",
"requires": {
"js-base64": "^3.7.5"
}
},
"yocto-queue": { "yocto-queue": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
"react-scripts": "^2.1.3", "react-scripts": "^2.1.3",
"socket.io-client": "^4.5.1", "socket.io-client": "^4.5.1",
"sql.js": "^1.8.0", "sql.js": "^1.8.0",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4",
"ygopro-deck-encode": "^1.0.3"
}, },
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
......
...@@ -30,58 +30,3 @@ function _objToMap(object: any): Map<string, IDeck> { ...@@ -30,58 +30,3 @@ function _objToMap(object: any): Map<string, IDeck> {
return map; return map;
} }
export function parseYdk(text: string): IDeck | undefined {
const lineIter = text.split("\n");
const deck: { main: number[]; extra: number[]; side: number[] } = {
main: [],
extra: [],
side: [],
};
let flag = -1;
for (const line of lineIter) {
switch (line) {
case "#main\r": {
flag = 1;
break;
}
case "#extra\r": {
flag = 2;
break;
}
case "!side\r": {
flag = 3;
break;
}
default: {
let code = Number(line);
if (!isNaN(code)) {
if (code > 100) {
switch (flag) {
case 1: {
deck.main.push(code);
break;
}
case 2: {
deck.extra.push(code);
break;
}
case 3: {
deck.side.push(code);
break;
}
default: {
break;
}
}
}
}
break;
}
}
}
return deck.main.length == 0 ? undefined : deck;
}
...@@ -22,7 +22,7 @@ import { ...@@ -22,7 +22,7 @@ import {
import { useAppSelector } from "../hook"; import { useAppSelector } from "../hook";
import { selectJoined } from "../reducers/joinSlice"; import { selectJoined } from "../reducers/joinSlice";
import { selectChat } from "../reducers/chatSlice"; import { selectChat } from "../reducers/chatSlice";
import { fetchDeck, IDeck, parseYdk } from "../api/deck"; import { fetchDeck, IDeck } from "../api/deck";
import { import {
sendUpdateDeck, sendUpdateDeck,
sendHsReady, sendHsReady,
...@@ -43,6 +43,7 @@ import type { MenuProps, UploadProps } from "antd"; ...@@ -43,6 +43,7 @@ import type { MenuProps, UploadProps } from "antd";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { selectDuelStart } from "../reducers/moraSlice"; import { selectDuelStart } from "../reducers/moraSlice";
import NeosConfig from "../../neos.config.json"; import NeosConfig from "../../neos.config.json";
import YGOProDeck from "ygopro-deck-encode";
const READY_STATE = "ready"; const READY_STATE = "ready";
...@@ -109,9 +110,16 @@ const WaitRoom = () => { ...@@ -109,9 +110,16 @@ const WaitRoom = () => {
const reader = new FileReader(); const reader = new FileReader();
reader.readAsText(file); reader.readAsText(file);
reader.onload = (e) => { reader.onload = (e) => {
const text = e.target?.result as string; const ydk = e.target?.result as string;
const deck = parseYdk(text); const deck = YGOProDeck.fromYdkString(ydk);
if (deck) {
if (
!(
deck.main.length == 0 &&
deck.extra.length == 0 &&
deck.side.length == 0
)
) {
// YDK解析成功 // YDK解析成功
message.success(`${file.name}解析成功`); message.success(`${file.name}解析成功`);
......
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