feat: Enhance player and weapon logging for better debugging and tracking

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-19 17:32:45 +01:00
parent 7e1855ebda
commit 7b1ec777d3
3 changed files with 30 additions and 7 deletions

View File

@@ -102,6 +102,8 @@ class Player {
pendingWeaponType = weaponType;
switchState = WeaponSwitchState.lowering;
print("[PLAYER] Requesting weapon switch to ${weaponType.name}.");
}
// --- Health & Damage ---
@@ -114,16 +116,16 @@ class Player {
damageFlash = math.min(1.0, damageFlash + (damage * 0.05));
if (health <= 0) {
print("YOU DIED!");
print("[PLAYER] Died! Final Score: $score");
} else {
print("Ouch! ($health)");
print("[PLAYER] Took $damage damage ($health)");
}
}
void heal(int amount) {
final int newHealth = math.min(100, health + amount);
if (health < 100) {
print("Feelin' better. ($newHealth)");
print("[PLAYER] Healed for $amount ($health -> $newHealth)");
}
health = newHealth;
}
@@ -131,13 +133,14 @@ class Player {
void addAmmo(int amount) {
final int newAmmo = math.min(99, ammo + amount);
if (ammo < 99) {
print("Hell yeah. ($newAmmo)");
print("[PLAYER] Picked up ammo $amount ($ammo -> $newAmmo)");
}
ammo = newAmmo;
}
void addLives(int amount) {
lives = math.min(9, lives + amount);
print("[PLAYER] Adding $amount extra lives (Total Lives: $lives)");
}
/// Attempts to collect [item] and returns the SFX to play.
@@ -157,6 +160,8 @@ class Player {
);
if (effect == null) return null;
print("[PLAYER] Collected ${item.runtimeType} - Effect: $effect");
if (effect.healthToRestore > 0) {
heal(effect.healthToRestore);
}
@@ -166,6 +171,8 @@ class Player {
}
if (effect.scoreToAdd > 0) {
print("[PLAYER] Adding ${effect.scoreToAdd} score.");
score += effect.scoreToAdd;
}
@@ -174,10 +181,12 @@ class Player {
}
if (effect.grantGoldKey) {
print("[PLAYER] Collected Gold Key.");
hasGoldKey = true;
}
if (effect.grantSilverKey) {
print("[PLAYER] Collected Silver Key.");
hasSilverKey = true;
}
@@ -193,6 +202,8 @@ class Player {
if (weaponType == WeaponType.machineGun) hasMachineGun = true;
if (weaponType == WeaponType.chainGun) hasChainGun = true;
print("[PLAYER] Collected ${weaponType.name}.");
}
if (effect.requestWeaponSwitch case final weaponType?) {
@@ -242,7 +253,7 @@ class Player {
onEnemyKilled: (Enemy killedEnemy) {
score += killedEnemy.scoreValue;
print(
"Killed ${killedEnemy.runtimeType}! +${killedEnemy.scoreValue} (Score: $score)",
"[PLAYER] Killed ${killedEnemy.runtimeType}! +${killedEnemy.scoreValue} (Score: $score)",
);
},
);
@@ -251,6 +262,7 @@ class Player {
if (currentWeapon.state == WeaponState.idle &&
ammo <= 0 &&
currentWeapon.type != WeaponType.knife) {
print("[PLAYER] Out of ammo, switching to knife.");
requestWeaponSwitch(WeaponType.knife);
}
}