From 0125e2ca3ef25f9764ece3eb35e3fc31dd857b46 Mon Sep 17 00:00:00 2001 From: "R.Eugenio" Date: Wed, 31 Dec 2025 21:02:16 +0100 Subject: [PATCH] =?UTF-8?q?feat(idle=5Fcompanion):=20Aparici=C3=B3n=20alea?= =?UTF-8?q?toria=2045s-3min?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Tiempo de aparici贸n ahora es aleatorio entre 45s y 3 minutos - Cada aparici贸n genera nuevo umbral para la siguiente - Mantiene el efecto sorpresa 馃 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/widgets/idle_companion.zig | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/widgets/idle_companion.zig b/src/widgets/idle_companion.zig index 7a5585b..783bcf2 100644 --- a/src/widgets/idle_companion.zig +++ b/src/widgets/idle_companion.zig @@ -32,12 +32,18 @@ //! //! ## Personalizaci贸n //! Los tiempos son configurables mediante constantes en State: -//! - IDLE_THRESHOLD_MS: Tiempo de inactividad para aparecer (15s) +//! - IDLE_MIN_MS: Tiempo M脥NIMO de inactividad para aparecer (45s) +//! - IDLE_RANDOM_MAX_MS: Tiempo adicional aleatorio (0-135s, total 45s-3min) //! - PEEK_DURATION_MS: Duraci贸n del asomarse (4s) //! - WATCH_DURATION_MS: Duraci贸n mirando alrededor (3s) //! - HIDE_DURATION_MS: Duraci贸n al esconderse (1s) //! - PANIC_HIDE_DURATION_MS: Duraci贸n del salto de p谩nico (0.2s) //! - RELOCATE_DELAY_MS: Pausa antes de reaparecer (5s) +//! +//! ## Comportamiento de sorpresa +//! El gatito aparece de forma impredecible entre 45 segundos y 3 minutos +//! de inactividad. Cada aparici贸n genera un nuevo tiempo aleatorio para +//! la siguiente, manteniendo el efecto sorpresa. const std = @import("std"); const Context = @import("../core/context.zig").Context; @@ -96,11 +102,18 @@ pub const State = struct { /// Semilla para n煤meros pseudo-aleatorios (LCG simple) random_seed: u32 = 12345, + /// Tiempo de inactividad necesario para la pr贸xima aparici贸n (aleatorio) + next_appear_threshold: i64 = 45_000, + // ========================================================================= // Constantes de tiempo (personalizables) // ========================================================================= - /// Tiempo de inactividad para aparecer (ms) + /// Tiempo M脥NIMO de inactividad para aparecer (ms) + pub const IDLE_MIN_MS: i64 = 45_000; // 45 segundos + /// Tiempo M脕XIMO adicional aleatorio (ms) + pub const IDLE_RANDOM_MAX_MS: i64 = 135_000; // +0 a 135s = total 45s-3min + /// Tiempo de inactividad para aparecer (ms) - LEGACY, ahora aleatorio pub const IDLE_THRESHOLD_MS: i64 = 15_000; /// Duraci贸n del estado peeking (ms) pub const PEEK_DURATION_MS: i64 = 4_000; @@ -124,6 +137,13 @@ pub const State = struct { return @as(f32, @floatFromInt(self.nextRandom() % 10000)) / 10000.0; } + /// Genera el pr贸ximo tiempo de inactividad necesario para aparecer + /// Resultado: entre IDLE_MIN_MS y IDLE_MIN_MS + IDLE_RANDOM_MAX_MS + fn generateNextAppearThreshold(self: *State) void { + const random_extra = self.nextRandom() % @as(u32, @intCast(IDLE_RANDOM_MAX_MS)); + self.next_appear_threshold = IDLE_MIN_MS + @as(i64, random_extra); + } + /// Elige un panel y posici贸n aleatorios fn pickRandomLocation(self: *State, num_panels: usize) void { if (num_panels == 0) return; @@ -164,7 +184,8 @@ pub const State = struct { // M谩quina de estados switch (self.anim_state) { .hidden => { - if (idle_time >= IDLE_THRESHOLD_MS and num_panels > 0) { + // Aparici贸n aleatoria: usa threshold variable (45s - 3min) + if (idle_time >= self.next_appear_threshold and num_panels > 0) { self.pickRandomLocation(num_panels); self.anim_state = .peeking; self.state_start_time = now; @@ -231,6 +252,8 @@ pub const State = struct { self.state_start_time = now + RELOCATE_DELAY_MS; self.appear_progress = 0; self.panic_jump = false; + // Generar nuevo tiempo aleatorio para pr贸xima aparici贸n + self.generateNextAppearThreshold(); } }, }