File size: 13,992 Bytes
7428b13 4c208f2 7428b13 4c208f2 81b3c3b 7428b13 4c208f2 81b3c3b e40394b b1c7f35 9774b79 7428b13 9774b79 afa3e65 7428b13 5c9dd93 7428b13 4906999 7428b13 9774b79 4906999 5c9dd93 4906999 9774b79 4906999 5c9dd93 4906999 9774b79 7428b13 afa3e65 9774b79 7428b13 9774b79 5d91440 9774b79 5d91440 9774b79 afa3e65 4c208f2 afa3e65 bba35f8 afa3e65 748b3b3 afa3e65 b1c7f35 5207761 e40394b 5207761 4c208f2 afa3e65 7428b13 afa3e65 7428b13 afa3e65 bba35f8 748b3b3 afa3e65 b1c7f35 5207761 e40394b 5207761 4c208f2 afa3e65 7428b13 90a88fc 7428b13 afa3e65 7428b13 9774b79 bba35f8 9774b79 5d91440 9774b79 7428b13 afa3e65 7428b13 afa3e65 7428b13 afa3e65 7428b13 afa3e65 7428b13 afa3e65 7428b13 afa3e65 20436ef 7428b13 afa3e65 7428b13 afa3e65 20436ef afa3e65 686010d 748b3b3 15c1c68 190d7a5 7428b13 afa3e65 7428b13 afa3e65 90a88fc afa3e65 90a88fc afa3e65 90a88fc afa3e65 90a88fc afa3e65 b16a79f 90a88fc afa3e65 190d7a5 afa3e65 190d7a5 748b3b3 15c1c68 190d7a5 afa3e65 20436ef 748b3b3 afa3e65 190d7a5 748b3b3 afa3e65 15c1c68 afa3e65 90a88fc 4c208f2 bba35f8 b1c7f35 bba35f8 b1c7f35 bba35f8 b1c7f35 bba35f8 b1c7f35 bba35f8 b1c7f35 bba35f8 7428b13 afa3e65 20436ef 7428b13 afa3e65 01069ac afa3e65 01069ac 7428b13 afa3e65 01069ac 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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
<script lang="ts">
import { onMount } from 'svelte';
import { fade } from 'svelte/transition';
import type { PicletInstance } from '$lib/db/schema';
import type { BattleState } from '$lib/battle-engine/types';
import PicletInfo from './PicletInfo.svelte';
import StatusEffectIndicator from './StatusEffectIndicator.svelte';
import FieldEffectIndicator from './FieldEffectIndicator.svelte';
import BattleEffects from './BattleEffects.svelte';
export let playerPiclet: PicletInstance;
export let enemyPiclet: PicletInstance;
export let playerHpPercentage: number;
export let enemyHpPercentage: number;
export let showIntro: boolean = false;
export let battleState: BattleState | undefined = undefined;
export let playerEffects: Array<{type: string, emoji: string, duration: number}> = [];
export let enemyEffects: Array<{type: string, emoji: string, duration: number}> = [];
export let playerFlash: boolean = false;
export let enemyFlash: boolean = false;
export let playerFaint: boolean = false;
export let enemyFaint: boolean = false;
export let playerLunge: boolean = false;
export let enemyLunge: boolean = false;
export let isWildBattle: boolean = true;
export let showWhiteFlash: boolean = false;
export let playerTrainerVisible: boolean = false;
export let enemyTrainerVisible: boolean = false;
export let playerTrainerSlideOut: boolean = false;
export let enemyTrainerSlideOut: boolean = false;
// Animation states
let playerVisible = false;
let enemyVisible = false;
// Trainer animation states
let playerTrainerSliding = false;
let enemyTrainerSliding = false;
onMount(() => {
if (!showIntro) {
// Skip intro - show everything immediately
playerVisible = true;
enemyVisible = true;
} else {
// In wild battles, enemy Piclet should be visible from start
if (isWildBattle) {
enemyVisible = true;
}
// For trainer battles, enemy will appear when enemyTrainerSlideOut triggers
// For all battles, player will appear when playerTrainerSlideOut triggers
}
});
// Watch for trainer slide-out triggers
$: if (playerTrainerSlideOut && !playerTrainerSliding) {
playerTrainerSliding = true;
// Show trainer and let CSS handle slide-out animation
playerTrainerVisible = true;
// After slide animation completes, hide trainer and show Piclet
setTimeout(() => {
playerTrainerVisible = false;
// Trigger white flash then show player monster
showWhiteFlash = true;
setTimeout(() => {
showWhiteFlash = false;
playerVisible = true;
}, 300);
}, 600); // Time for slide-out animation
}
$: if (enemyTrainerSlideOut && !enemyTrainerSliding) {
enemyTrainerSliding = true;
// Show trainer and let CSS handle slide-out animation
enemyTrainerVisible = true;
// After slide animation completes, hide trainer and show Piclet
setTimeout(() => {
enemyTrainerVisible = false;
// Trigger white flash then show enemy monster
showWhiteFlash = true;
setTimeout(() => {
showWhiteFlash = false;
enemyVisible = true;
}, 300);
}, 600); // Time for slide-out animation
}
</script>
<div class="battle-field">
<!-- White flash overlay -->
{#if showWhiteFlash}
<div class="white-flash" transition:fade={{ duration: 300 }}></div>
{/if}
<!-- Player Trainer -->
{#if playerTrainerVisible}
<div class="player-trainer" class:slide-out-left={playerTrainerSlideOut}>
<img src="/assets/default_trainer.png" alt="Player Trainer" />
</div>
{/if}
<!-- Enemy Trainer (only for trainer battles) -->
{#if !isWildBattle && enemyTrainerVisible}
<div class="enemy-trainer" class:slide-out-right={enemyTrainerSlideOut}>
<img src="/assets/default_trainer.png" alt="Enemy Trainer" />
</div>
{/if}
<div class="battle-content">
<!-- Field Effects Display -->
{#if battleState?.fieldEffects}
<FieldEffectIndicator fieldEffects={battleState.fieldEffects} />
{/if}
<!-- Enemy Row -->
<div class="enemy-row">
<div class="enemy-stack" class:intro-animations={showIntro}>
<PicletInfo
piclet={enemyPiclet}
hpPercentage={enemyHpPercentage}
isPlayer={false}
/>
<!-- Static Enemy Platform (always visible) -->
<img
class="platform enemy-platform"
src="/assets/grass.PNG"
alt="Platform"
on:error={(e) => {
const target = e.currentTarget as HTMLImageElement;
const nextSibling = target.nextElementSibling as HTMLElement;
target.style.display = 'none';
if (nextSibling) nextSibling.style.display = 'block';
}}
/>
<div class="platform-fallback enemy-platform-fallback" style="display: none;"></div>
{#if enemyVisible}
<div class="enemy-piclet-wrapper" class:animate-in={showIntro} class:lunge={enemyLunge}>
<!-- Enemy Battle Effects wrap the image for flicker animation -->
<BattleEffects effects={enemyEffects} flash={enemyFlash} faint={enemyFaint}>
<img
class="piclet-image enemy-image"
src={enemyPiclet.imageData || enemyPiclet.imageUrl}
alt={enemyPiclet.nickname}
on:error={(e) => {
const target = e.currentTarget as HTMLImageElement;
target.src = 'https://via.placeholder.com/120x120?text=Piclet';
}}
/>
</BattleEffects>
<!-- Enemy Status Effects -->
{#if battleState?.opponentPiclet?.statusEffects}
<div class="enemy-status-effects">
<StatusEffectIndicator statusEffects={battleState.opponentPiclet.statusEffects.map(effect => ({ type: effect, turnsLeft: 3 }))} />
</div>
{/if}
</div>
{/if}
</div>
</div>
<div class="spacer"></div>
<!-- Player Row -->
<div class="player-row">
<div class="player-stack" class:intro-animations={showIntro}>
<!-- Static Player Platform (always visible) -->
<img
class="platform player-platform"
src="/assets/grass.PNG"
alt="Platform"
on:error={(e) => {
const target = e.currentTarget as HTMLImageElement;
const nextSibling = target.nextElementSibling as HTMLElement;
target.style.display = 'none';
if (nextSibling) nextSibling.style.display = 'block';
}}
/>
<div class="platform-fallback player-platform-fallback" style="display: none;"></div>
{#if playerVisible}
<div class="player-piclet-wrapper" class:animate-in={showIntro} class:lunge={playerLunge}>
<!-- Player Battle Effects wrap the image for flicker animation -->
<BattleEffects effects={playerEffects} flash={playerFlash} faint={playerFaint}>
<img
class="piclet-image player-image"
src={playerPiclet.imageData || playerPiclet.imageUrl}
alt={playerPiclet.nickname}
on:error={(e) => {
const target = e.currentTarget as HTMLImageElement;
target.src = 'https://via.placeholder.com/120x120?text=Piclet';
}}
/>
</BattleEffects>
<!-- Player Status Effects -->
{#if battleState?.playerPiclet?.statusEffects}
<div class="player-status-effects">
<StatusEffectIndicator statusEffects={battleState.playerPiclet.statusEffects.map(effect => ({ type: effect, turnsLeft: 3 }))} />
</div>
{/if}
</div>
{/if}
<PicletInfo
piclet={playerPiclet}
hpPercentage={playerHpPercentage}
isPlayer={true}
/>
</div>
</div>
</div>
</div>
<style>
.battle-field {
height: 280px;
position: relative;
overflow: hidden;
background: repeating-linear-gradient(
to bottom,
rgba(76, 175, 80, 0.2) 0px,
rgba(76, 175, 80, 0.2) 5px,
rgba(76, 175, 80, 0.1) 5px,
rgba(76, 175, 80, 0.1) 10px
);
}
.white-flash {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: white;
z-index: 50;
}
.player-trainer {
position: absolute;
bottom: 20px;
left: 20px;
z-index: 10;
transition: transform 0.6s ease-in-out;
}
.player-trainer img {
width: 120px;
height: auto;
/* Remove horizontal flip - trainer should face naturally */
}
.player-trainer.slide-out-left {
transform: translateX(-200px);
}
.enemy-trainer {
position: absolute;
top: 20px;
right: 20px;
z-index: 10;
transition: transform 0.6s ease-in-out;
}
.enemy-trainer img {
width: 120px;
height: auto;
}
.enemy-trainer.slide-out-right {
transform: translateX(200px);
}
.battle-content {
display: flex;
flex-direction: column;
height: 100%;
}
/* Enemy Row */
.enemy-row {
flex: 1;
position: relative;
}
.enemy-stack {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
.enemy-piclet-wrapper {
position: absolute;
right: 40px;
top: 0;
}
.enemy-image {
width: 120px;
height: 120px;
object-fit: contain;
display: block;
}
.enemy-platform {
width: 160px;
height: 160px;
position: absolute;
bottom: -60px;
right: 20px; /* Align with enemy-piclet-wrapper position */
z-index: 0;
object-fit: cover;
}
/* Player Row */
.player-row {
height: 140px;
position: relative;
}
.player-stack {
position: relative;
width: 100%;
height: 100%;
}
.player-piclet-wrapper {
position: absolute;
left: 40px;
bottom: 0;
}
.player-image {
width: 120px;
height: 120px;
object-fit: contain;
display: block;
transform: scaleX(-1);
}
.player-platform {
width: 160px;
height: 160px;
position: absolute;
bottom: -80px;
left: 20px; /* Align with player-piclet-wrapper position */
z-index: 0;
object-fit: cover;
}
/* Platform fallbacks */
.platform-fallback {
position: absolute;
background: rgba(76, 175, 80, 0.3);
border-radius: 50%;
}
.enemy-platform-fallback {
width: 160px;
height: 160px;
bottom: -60px;
right: 20px;
}
.player-platform-fallback {
width: 160px;
height: 160px;
bottom: -80px;
left: 20px;
}
/* Piclet images */
.piclet-image {
image-rendering: auto;
filter: drop-shadow(-2px 0 4px rgba(0, 0, 0, 0.1));
position: relative;
z-index: 1;
}
.spacer {
flex: 1;
}
/* Status Effects Positioning */
.enemy-status-effects {
position: absolute;
top: -10px;
right: -10px;
z-index: 5;
}
.player-status-effects {
position: absolute;
bottom: -10px;
left: -10px;
z-index: 5;
}
/* Animations */
.enemy-piclet-wrapper {
animation-fill-mode: both;
transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.enemy-piclet-wrapper.animate-in {
animation: enemySlideIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.enemy-piclet-wrapper.lunge {
animation: enemyLunge 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.player-piclet-wrapper {
animation-fill-mode: both;
transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.player-piclet-wrapper.animate-in {
animation: playerSlideIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.player-piclet-wrapper.lunge {
animation: playerLunge 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
@keyframes enemySlideIn {
0% {
transform: translateX(150px) translateY(-50px) scale(1.5);
opacity: 0;
}
50% {
opacity: 1;
}
100% {
transform: translateX(0) translateY(0) scale(1);
opacity: 1;
}
}
@keyframes playerSlideIn {
0% {
transform: translateX(-150px) translateY(50px) scale(0.5);
opacity: 0;
}
50% {
opacity: 1;
}
100% {
transform: translateX(0) translateY(0) scale(1);
opacity: 1;
}
}
@keyframes enemyLunge {
0% {
transform: translateX(0) translateY(0) scale(1);
}
40% {
transform: translateX(-60px) translateY(10px) scale(1.1);
}
100% {
transform: translateX(0) translateY(0) scale(1);
}
}
@keyframes playerLunge {
0% {
transform: translateX(0) translateY(0) scale(1);
}
40% {
transform: translateX(60px) translateY(-10px) scale(1.1);
}
100% {
transform: translateX(0) translateY(0) scale(1);
}
}
/* Info box animations */
.enemy-stack.intro-animations :global(.piclet-info-wrapper) {
animation: fadeSlideDown 0.5s ease-out 0.3s both;
}
.player-stack.intro-animations :global(.piclet-info-wrapper) {
animation: fadeSlideUp 0.5s ease-out 0.3s both;
}
@keyframes fadeSlideDown {
0% {
opacity: 0;
transform: translateY(-20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeSlideUp {
0% {
opacity: 0;
transform: translateY(20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 768px) {
.enemy-image {
width: 120px;
height: 120px;
}
.player-image {
width: 120px;
height: 120px;
}
.enemy-piclet-wrapper {
right: 40px;
}
.player-piclet-wrapper {
left: 40px;
}
}
</style> |