piclets / src /lib /components /Battle /PicletInfo.svelte
Fraser's picture
MORE
7428b13
raw
history blame
2.38 kB
<script lang="ts">
import type { PicletInstance } from '$lib/db/schema';
export let piclet: PicletInstance;
export let hpPercentage: number;
export let isPlayer: boolean;
$: hpColor = hpPercentage > 0.5 ? '#4caf50' : hpPercentage > 0.25 ? '#ffc107' : '#f44336';
$: displayHp = Math.max(0, Math.round(piclet.currentHp * hpPercentage));
</script>
<div class="piclet-info {isPlayer ? 'player-info' : 'enemy-info'}">
<div class="info-header">
<span class="piclet-name">{piclet.nickname}</span>
<span class="piclet-level">Lv.{piclet.level}</span>
</div>
<div class="hp-container">
<div class="hp-label">HP</div>
<div class="hp-bar-wrapper">
<div class="hp-bar-bg">
<div
class="hp-bar-fill"
style="width: {hpPercentage * 100}%; background-color: {hpColor}"
></div>
</div>
</div>
</div>
{#if isPlayer}
<div class="hp-text">
{displayHp} / {piclet.maxHp}
</div>
{/if}
</div>
<style>
.piclet-info {
background: rgba(255, 255, 255, 0.95);
border: 2px solid #333;
border-radius: 8px;
padding: 0.75rem 1rem;
min-width: 200px;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.player-info {
order: 2;
}
.enemy-info {
order: 1;
}
.info-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.5rem;
}
.piclet-name {
font-weight: 600;
font-size: 1rem;
color: #1a1a1a;
}
.piclet-level {
font-size: 0.875rem;
color: #666;
}
.hp-container {
display: flex;
align-items: center;
gap: 0.5rem;
}
.hp-label {
font-weight: 600;
font-size: 0.75rem;
color: #666;
}
.hp-bar-wrapper {
flex: 1;
}
.hp-bar-bg {
height: 8px;
background: #e0e0e0;
border-radius: 4px;
overflow: hidden;
position: relative;
}
.hp-bar-fill {
height: 100%;
transition: width 0.5s ease, background-color 0.3s ease;
border-radius: 4px;
}
.hp-text {
text-align: right;
font-size: 0.75rem;
color: #666;
margin-top: 0.25rem;
}
@media (max-width: 768px) {
.piclet-info {
min-width: 150px;
padding: 0.5rem 0.75rem;
}
.piclet-name {
font-size: 0.875rem;
}
.piclet-level {
font-size: 0.75rem;
}
}
</style>