aboutsummaryrefslogtreecommitdiff
path: root/src/components/card_thumb.svelte
blob: 52fd1f36b2f817ccf03b6348409a287d783c8119 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<script lang="js">
    import { setLeftPanelCard, showMobileInfo } from '../left_panel';
    import { cardImageUrl } from '../utils';
    import { currentTranslations } from '../language';
    import { deckOps } from '../deck';
    import { getCardDb } from '../card_db';

    let {id, area, idx, limitNum} = $props();

    function onhover() {
        setLeftPanelCard(id, $currentTranslations.key); 
    }

    function onDragStart(e) {
        e.dataTransfer.setData('text', JSON.stringify({id, area, idx}))
    }

    function adjustCardCount(e) {
      e.preventDefault();

      if (area !== 'search') {
        deckOps.deleteCard(area, idx)
        return;
      }

      const cardDB = getCardDb();
      const isExtra = cardDB[id]?.isExtra;

      if (isExtra) {
        deckOps.add2extra(id, -1);
      } else {
        deckOps.add2main(id, -1);
      }
    }

    function thumbImage(id) {
        let url = cardImageUrl(id)
        if (url.includes('ygopro-super-pre')) {
            return url;
        }
        return url + '!thumb2';
    }
</script>

{#if id}
   <img
       style="margin:2px;"
       draggable="true"
       onmouseover={onhover}
       onfocus={onhover}
       ondragstart={onDragStart}
       onclick={()=>{onhover();showMobileInfo();}}
       oncontextmenu={adjustCardCount}
       height="100%"
       src={thumbImage(id)}
       alt="yugioh card {id}"
   />
   {#if limitNum > 0}
       <div class="overlay">{limitNum}</div>
   {:else if limitNum === 0}
       <div class="ban-overlay"></div>
   {/if}
{/if}

<style>
    .overlay {
        position: absolute;
        top: 0;
        left: 0;
        border: 3px solid red;
        border-radius: 50%;
        background-color: black;
        width: 20px;
        height: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: bold;
        color: yellow;
        font-size: 13px;
        font-family: Arial, sans-serif;
        box-sizing: border-box;
        pointer-events: none;
    }
    
    .ban-overlay {
        position: absolute;
        top: 0;
        left: 0;
        border: 3px solid red;
        border-radius: 50%;
        background-color: black;
        width: 20px;
        height: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: bold;
        color: yellow;
        font-size: 15px;
        font-family: Arial, sans-serif;
        box-sizing: border-box;
        pointer-events: none;
    }

    .ban-overlay::after {
        content: '';
        width: 15px;
        height: 3px;
        background-color: red;
        transform: rotate(45deg);
        position: absolute;
        pointer-events: none;
    }
</style>