File size: 7,226 Bytes
7428b13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<script lang="ts">
  import type { PicletInstance } from '$lib/db/schema';
  import { db } from '$lib/db';
  import ActionButtons from './ActionButtons.svelte';
  
  export let currentMessage: string;
  export let battlePhase: 'intro' | 'main' | 'moveSelect' | 'picletSelect' | 'ended';
  export let processingTurn: boolean;
  export let battleEnded: boolean;
  export let isWildBattle: boolean;
  export let playerPiclet: PicletInstance;
  export let onAction: (action: string) => void;
  export let onMoveSelect: (move: any) => void;
  export let onPicletSelect: (piclet: PicletInstance) => void;
  export let onBack: () => void;
  
  let availablePiclets: PicletInstance[] = [];
  
  // Load player's roster
  async function loadRoster() {
    const roster = await db.picletInstances
      .where('isInRoster')
      .equals(1)
      .toArray();
    availablePiclets = roster.filter(p => p.currentHp > 0 && p.id !== playerPiclet.id);
  }
  
  $: if (battlePhase === 'picletSelect') {
    loadRoster();
  }
</script>

<div class="battle-controls">
  <!-- Message Bar -->
  <div class="message-bar {battleEnded ? 'special' : ''}">
    <p>{currentMessage}</p>
  </div>
  
  <!-- Action Area -->
  <div class="action-area">
    {#if battlePhase === 'main' && !processingTurn && !battleEnded}
      <ActionButtons 
        {isWildBattle}
        {onAction}
      />
    {:else if battlePhase === 'moveSelect'}
      <div class="move-select">
        <div class="section-header">
          <h3>Select a move</h3>
          <button class="back-btn" on:click={onBack}>← Back</button>
        </div>
        <div class="moves-grid">
          {#each playerPiclet.moves as move}
            <button 
              class="move-button"
              on:click={() => onMoveSelect(move)}
              disabled={move.currentPp <= 0}
            >
              <span class="move-name">{move.name}</span>
              <span class="move-type">{move.type}</span>
              <span class="move-pp">PP: {move.currentPp}/{move.pp}</span>
            </button>
          {/each}
        </div>
      </div>
    {:else if battlePhase === 'picletSelect'}
      <div class="piclet-select">
        <div class="section-header">
          <h3>Select a Piclet</h3>
          <button class="back-btn" on:click={onBack}>← Back</button>
        </div>
        <div class="piclets-list">
          {#if availablePiclets.length === 0}
            <p class="no-piclets">No other healthy Piclets available!</p>
          {:else}
            {#each availablePiclets as piclet}
              <button 
                class="piclet-option"
                on:click={() => onPicletSelect(piclet)}
              >
                <img 
                  src={piclet.imageUrl} 
                  alt={piclet.nickname}
                  on:error={(e) => e.currentTarget.src = 'https://via.placeholder.com/50x50?text=P'}
                />
                <div class="piclet-details">
                  <span class="piclet-name">{piclet.nickname}</span>
                  <span class="piclet-stats">Lv.{piclet.level} - HP: {piclet.currentHp}/{piclet.maxHp}</span>
                </div>
                <div class="hp-preview">
                  <div class="hp-preview-bar">
                    <div 
                      class="hp-preview-fill" 
                      style="width: {(piclet.currentHp / piclet.maxHp) * 100}%"
                    ></div>
                  </div>
                </div>
              </button>
            {/each}
          {/if}
        </div>
      </div>
    {:else if battleEnded}
      <div class="battle-end">
        <button class="continue-btn" on:click={() => window.history.back()}>
          Continue
        </button>
      </div>
    {/if}
  </div>
</div>

<style>
  .battle-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    border-top: 1px solid #e0e0e0;
  }
  
  .message-bar {
    padding: 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    text-align: center;
  }
  
  .message-bar.special {
    background: rgba(255, 152, 0, 0.1);
    border-color: rgba(255, 152, 0, 0.3);
  }
  
  .message-bar p {
    margin: 0;
    font-size: 1rem;
    color: #333;
  }
  
  .action-area {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
  }
  
  /* Move Selection */
  .move-select, .piclet-select {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  
  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
  }
  
  .section-header h3 {
    margin: 0;
    font-size: 1.125rem;
    color: #1a1a1a;
  }
  
  .back-btn {
    background: none;
    border: none;
    color: #007bff;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
  }
  
  .moves-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  
  .move-button {
    padding: 1rem;
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    transition: all 0.2s ease;
  }
  
  .move-button:hover:not(:disabled) {
    background: #e9ecef;
    border-color: #007bff;
  }
  
  .move-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  
  .move-name {
    font-weight: 600;
    color: #1a1a1a;
  }
  
  .move-type {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
  }
  
  .move-pp {
    font-size: 0.75rem;
    color: #999;
  }
  
  /* Piclet Selection */
  .piclets-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .no-piclets {
    text-align: center;
    color: #666;
    padding: 2rem;
  }
  
  .piclet-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
  }
  
  .piclet-option:hover {
    background: #e9ecef;
    border-color: #007bff;
  }
  
  .piclet-option img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
  }
  
  .piclet-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
  
  .piclet-name {
    font-weight: 600;
    color: #1a1a1a;
  }
  
  .piclet-stats {
    font-size: 0.75rem;
    color: #666;
  }
  
  .hp-preview {
    width: 80px;
  }
  
  .hp-preview-bar {
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
  }
  
  .hp-preview-fill {
    height: 100%;
    background: #4caf50;
    transition: width 0.3s ease;
  }
  
  /* Battle End */
  .battle-end {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
  }
  
  .continue-btn {
    padding: 1rem 2rem;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
  }
  
  .continue-btn:hover {
    background: #0056b3;
  }
</style>