From c700c8f53dd7d29cb26dcf8bb201b96781740a93 Mon Sep 17 00:00:00 2001
From: Mistivia <i@mistivia.com>
Date: Sat, 8 Feb 2025 17:41:07 +0800
Subject: fix up

---
 README.md                       |  2 +-
 index.html                      |  2 +-
 src/components/CardThumb.svelte |  3 ++-
 src/components/LeftPanel.svelte | 13 ++++++++-----
 src/control/deck.js             | 18 ++++++++++++++----
 src/utils.js                    | 10 +++++++++-
 vite.config.ts                  |  1 +
 7 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index f7a4094..d85b8b0 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 
 游戏王卡组编辑器
 
-Demo: [ygodeck.mistivia.com](https://ygodeck.mistivia.com)
+Demo: [raye.mistivia.com/ygodeck](https://raye.mistivia.com/ygodeck)
 
 ## 截图
 
diff --git a/index.html b/index.html
index ad4df1c..ecf7c0a 100644
--- a/index.html
+++ b/index.html
@@ -22,7 +22,7 @@
   </head>
   <body>
     <div id="app" class="container"></div>
-    <script type="module" src="/src/main.ts"></script>
+    <script type="module" src="./src/main.ts"></script>
   </body>
 </html>
 
diff --git a/src/components/CardThumb.svelte b/src/components/CardThumb.svelte
index 4c41f2d..be6af81 100644
--- a/src/components/CardThumb.svelte
+++ b/src/components/CardThumb.svelte
@@ -1,6 +1,7 @@
 <script lang="js">
 
     import {setLeftPanelCard} from '../control/left_panel';
+    import { cardImageUrl } from '../utils';
 
     let {id, area} = $props();
 
@@ -21,7 +22,7 @@
         onfocus={onhover}
         ondragstart={onDragStart}
         height="100%"
-        src="https://cdn.233.momobako.com/ygopro/pics/{id}.jpg"
+        src={cardImageUrl(id)}
         alt="yugioh card {id}"
     />
 {/if}
diff --git a/src/components/LeftPanel.svelte b/src/components/LeftPanel.svelte
index f5d2fa8..b2fe2b1 100644
--- a/src/components/LeftPanel.svelte
+++ b/src/components/LeftPanel.svelte
@@ -1,9 +1,12 @@
 <script lang="js">
 
-import {
-    leftPanelCardId,
-    leftPanelCardDesc,
-} from '../control/left_panel'
+    import {
+        leftPanelCardId,
+        leftPanelCardDesc,
+    } from '../control/left_panel';
+
+    import { cardImageUrl } from '../utils';
+
 
 </script>
 
@@ -11,7 +14,7 @@ import {
     <div class="card-preview">
         <div class="card-image-large">
             {#if $leftPanelCardId}
-                <img height="100%" src="https://cdn.233.momobako.com/ygopro/pics/{$leftPanelCardId}.jpg" alt="card img">
+                <img height="100%" src={cardImageUrl($leftPanelCardId)} alt="card img">
             {/if}
         </div>
         <div class="card-description">
diff --git a/src/control/deck.js b/src/control/deck.js
index d47b21c..ab46a02 100644
--- a/src/control/deck.js
+++ b/src/control/deck.js
@@ -5,7 +5,20 @@ import { cardDb } from '../data/cardDb';
 let deck = writable({main: [], extra: [], side: []});
 let deckState = {main: [], extra: [], side: []};
 
+function sanitizeDeck(deck) {
+    let ret = [];
+    for (let id of deck) {
+        if (cardDb[id] !== undefined) {
+            ret.push(id);
+        }
+    }
+    return ret;
+}
+
 function setDeck(d) {
+    d.main = sanitizeDeck(d.main);
+    d.side = sanitizeDeck(d.side);
+    d.extra = sanitizeDeck(d.extra);
     let sortFn = (a, b) => {return cardDb[a].cid - cardDb[b].cid;}
     d.main.sort(sortFn);
     d.extra.sort(sortFn);
@@ -15,9 +28,6 @@ function setDeck(d) {
     localStorage.setItem('cachedDeck', JSON.stringify(d));
 };
 
-const OK = 1;
-const FAIL = 0;
-
 function canAdd(d, id) {
     let count = 0;
     for (let c of d.main) {
@@ -113,7 +123,7 @@ function initDeck() {
         let deck = parseYdke(url[1]);
         if (deck.main.length > 0 || deck.extra.length > 0 || deck.extra.length > 0) {
             setDeck(deck);
-            window.location.replace("/");
+            window.location.href = url[0];
             return;
         }
     }
diff --git a/src/utils.js b/src/utils.js
index ba5d905..4efe862 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -28,7 +28,7 @@ function parseYdk(ydkContent) {
 }
 
 function genYdk(deck) {
-    let ydkContent = '#created by ygodeck.mistivia.com\n';
+    let ydkContent = '#created by mistivia.com\n';
 
     ydkContent += '#main\n';
     ydkContent += deck.main.join('\n') + '\n';
@@ -100,11 +100,19 @@ function genYdke(deck) {
     return `${mainEncoded}!${extraEncoded}!${sideEncoded}`;
 }
 
+function cardImageUrl(id) {
+    if (id.length <= 8) {
+        return "https://cdn.233.momobako.com/ygopro/pics/" + id + '.jpg';
+    }
+    return 'https://cdn02.moecube.com:444/ygopro-super-pre/data/pics/' + id + '.jpg';
+}
+
 export {
     parseYdk,
     genYdk,
     parseYdke,
     genYdke,
     downloadStringAsFile,
+    cardImageUrl,
 };
 
diff --git a/vite.config.ts b/vite.config.ts
index d32eba1..2f557a4 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -4,4 +4,5 @@ import { svelte } from '@sveltejs/vite-plugin-svelte'
 // https://vite.dev/config/
 export default defineConfig({
   plugins: [svelte()],
+  base: './',
 })
-- 
cgit v1.0

