Files
novafarma/old_logic/src_backup_1768938138/ui/MemoryHeartUI.js
2026-01-21 01:08:21 +01:00

157 lines
4.0 KiB
JavaScript

/**
* 💙 MEMORY HEART UI
* Displays pulsating heart when Kai remembers family pet
*/
class MemoryHeartUI {
constructor(scene) {
this.scene = scene;
this.container = null;
this.heartIcon = null;
this.isActive = false;
this.createUI();
this.setupEventListeners();
}
createUI() {
const { width, height } = this.scene.cameras.main;
// Container positioned in top-left (near health/stats)
this.container = this.scene.add.container(80, 80);
this.container.setScrollFactor(0);
this.container.setDepth(9000);
this.container.setAlpha(0); // Start invisible
// Heart icon
this.heartIcon = this.scene.add.image(0, 0, 'heart_icon');
this.heartIcon.setScale(0.6);
// Optional: Memory text
this.memoryText = this.scene.add.text(40, 0, '', {
fontFamily: 'Verdana',
fontSize: '16px',
color: '#ff6b9d',
fontStyle: 'italic'
}).setOrigin(0, 0.5);
this.container.add([this.heartIcon, this.memoryText]);
}
setupEventListeners() {
// Listen for memory triggers
this.scene.events.on('animal:memory_triggered', this.show, this);
this.scene.events.on('animal:memory_ended', this.hide, this);
}
show(data) {
if (this.isActive) return;
this.isActive = true;
// Set memory text based on animal
if (data.type === 'domestic_dog') {
this.memoryText.setText('Spominjaš se...');
}
// Fade in container
this.scene.tweens.add({
targets: this.container,
alpha: 1,
duration: 500,
ease: 'Sine.easeIn'
});
// Start pulsating animation
this.startPulsating();
// Optional: Play heartbeat sound
if (this.scene.sound.get('heartbeat')) {
this.scene.sound.play('heartbeat', { volume: 0.3, loop: true });
}
}
hide() {
if (!this.isActive) return;
this.isActive = false;
// Stop pulsating
this.stopPulsating();
// Fade out container
this.scene.tweens.add({
targets: this.container,
alpha: 0,
duration: 800,
ease: 'Sine.easeOut'
});
// Stop heartbeat sound
if (this.scene.sound.get('heartbeat')) {
const heartbeat = this.scene.sound.get('heartbeat');
this.scene.tweens.add({
targets: heartbeat,
volume: 0,
duration: 500,
onComplete: () => {
heartbeat.stop();
}
});
}
}
startPulsating() {
// Gentle pulsating scale animation
this.pulseTween = this.scene.tweens.add({
targets: this.heartIcon,
scale: 0.7,
duration: 800,
yoyo: true,
repeat: -1,
ease: 'Sine.easeInOut'
});
// Subtle glow effect (tint)
this.glowTween = this.scene.tweens.add({
targets: this.heartIcon,
alpha: { from: 0.8, to: 1 },
duration: 600,
yoyo: true,
repeat: -1,
ease: 'Sine.easeInOut'
});
}
stopPulsating() {
if (this.pulseTween) {
this.pulseTween.stop();
this.pulseTween = null;
}
if (this.glowTween) {
this.glowTween.stop();
this.glowTween = null;
}
// Reset to default
this.scene.tweens.add({
targets: this.heartIcon,
scale: 0.6,
alpha: 1,
duration: 300
});
}
destroy() {
this.scene.events.off('animal:memory_triggered', this.show, this);
this.scene.events.off('animal:memory_ended', this.hide, this);
if (this.container) {
this.container.destroy();
}
}
}
export default MemoryHeartUI;