From 1b8c7f730d87eb833c79d32d5e1e1a3abee4c87f Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 14 May 2026 01:21:22 +0200 Subject: [PATCH] refactor: power-up effects applied centrally in GameBootstrap --- .../Infrastructure/Unity/GameBootstrap.cs | 17 +++++++--- .../Unity/PowerUpViewAdapter.cs | 31 +++---------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs b/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs index 68f8f12..75a74dc 100644 --- a/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs +++ b/Assets/Scripts/Infrastructure/Unity/GameBootstrap.cs @@ -1,5 +1,6 @@ using System.Collections; using Core.Domain; +using Core.Domain.Status.Effects; using Core.Ports; using TMPro; using UnityEngine; @@ -370,14 +371,22 @@ namespace Infrastructure.Unity instance.Configure(type); - instance.OnCollected += (t) => + instance.OnCollected += (t, dur) => { cameraController?.Shake(0.2f, 0.15f); rumbleManager?.PulseMedium(); - - if (t == PowerUpType.TimeSlow) + + switch (t) { - _gameSession.ActivateTimeSlow(10f); + case PowerUpType.TimeSlow: + _gameSession.ActivateTimeSlow(dur); + break; + case PowerUpType.LightFooted: + _playerInstance?.Status.AddEffect(new LightFootedEffect(dur)); + break; + case PowerUpType.SpeedBoost: + _playerInstance?.Status.AddEffect(new SpeedBoostEffect(dur)); + break; } }; } diff --git a/Assets/Scripts/Infrastructure/Unity/PowerUpViewAdapter.cs b/Assets/Scripts/Infrastructure/Unity/PowerUpViewAdapter.cs index 6cbe8e2..90fb152 100644 --- a/Assets/Scripts/Infrastructure/Unity/PowerUpViewAdapter.cs +++ b/Assets/Scripts/Infrastructure/Unity/PowerUpViewAdapter.cs @@ -1,6 +1,5 @@ using System; using Core.Domain; -using Core.Domain.Status.Effects; using KBCore.Refs; using UnityEngine; @@ -17,7 +16,7 @@ namespace Infrastructure.Unity private MaterialPropertyBlock _propBlock; private static readonly int ColorProperty = Shader.PropertyToID("_BaseColor"); - public event Action OnCollected; + public event Action OnCollected; private void Awake() { @@ -45,20 +44,16 @@ namespace Infrastructure.Unity private void OnTriggerEnter(Collider other) { - if (other.TryGetComponent(out var player)) + if (other.TryGetComponent(out _)) { - ApplyEffect(player); - OnCollected?.Invoke(type); + OnCollected?.Invoke(type, duration); if (pickupVfx) { var vfx = Instantiate(pickupVfx, transform.position, Quaternion.identity); var main = vfx.main; - meshRenderer.GetPropertyBlock(_propBlock); - var currentColor = _propBlock.GetColor(ColorProperty); - main.startColor = currentColor; - + main.startColor = _propBlock.GetColor(ColorProperty); Destroy(vfx.gameObject, 2f); } @@ -66,24 +61,6 @@ namespace Infrastructure.Unity } } - private void ApplyEffect(PlayerController player) - { - switch (type) - { - case PowerUpType.LightFooted: - player.Status.AddEffect(new LightFootedEffect(duration)); - break; - case PowerUpType.SpeedBoost: - player.Status.AddEffect(new SpeedBoostEffect(duration, 1.5f)); - break; - case PowerUpType.TimeSlow: - // Handled globally - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - public void Configure(PowerUpType newType) { type = newType;