Mistivia 1 month ago
parent
commit
c700c8f53d
7 changed files with 36 additions and 13 deletions
  1. 1 1
      README.md
  2. 1 1
      index.html
  3. 2 1
      src/components/CardThumb.svelte
  4. 8 5
      src/components/LeftPanel.svelte
  5. 14 4
      src/control/deck.js
  6. 9 1
      src/utils.js
  7. 1 0
      vite.config.ts

+ 1 - 1
README.md

@@ -2,7 +2,7 @@
 
 游戏王卡组编辑器
 
-Demo: [ygodeck.mistivia.com](https://ygodeck.mistivia.com)
+Demo: [raye.mistivia.com/ygodeck](https://raye.mistivia.com/ygodeck)
 
 ## 截图
 

+ 1 - 1
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>
 

+ 2 - 1
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}

+ 8 - 5
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">

+ 14 - 4
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;
         }
     }

+ 9 - 1
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,
 };
 

+ 1 - 0
vite.config.ts

@@ -4,4 +4,5 @@ import { svelte } from '@sveltejs/vite-plugin-svelte'
 // https://vite.dev/config/
 export default defineConfig({
   plugins: [svelte()],
+  base: './',
 })