From e9a018462eaa81137f21cfecd886d488830d002c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 29 Dec 2025 00:47:03 +0000 Subject: [PATCH] Fix DREAD_Log undefined error by attaching logging functions to DREAD object The Katspeak runtime was unable to resolve DREAD_Log, DREAD_LogError, and DREAD_LogDebug functions because they were defined with 'let' (local scope) and closures don't capture outer scope variables properly in Catspeak. Fix: Move logging functions to be methods on the DREAD object itself: - DREAD_Log() -> DREAD.Log() - DREAD_LogError() -> DREAD.LogError() - DREAD_LogDebug() -> DREAD.LogDebug() This ensures the functions are globally accessible wherever the DREAD object is accessible, fixing the runtime error at line 1400. --- DREAD.catspeak | 133 +++++++++++++++++----------------- src/main.catspeak | 46 ++++++------ src/spawns/forest.catspeak | 10 +-- src/spawns/zones.catspeak | 2 +- src/systems/invasion.catspeak | 10 +-- src/systems/spawning.catspeak | 16 ++-- src/utils/archetypes.catspeak | 2 +- src/utils/config.catspeak | 14 ++-- src/utils/core.catspeak | 35 ++++----- workshop/DREAD/init.script | 133 +++++++++++++++++----------------- 10 files changed, 203 insertions(+), 198 deletions(-) diff --git a/DREAD.catspeak b/DREAD.catspeak index baaf4c1..62b25fa 100644 --- a/DREAD.catspeak +++ b/DREAD.catspeak @@ -25,28 +25,31 @@ let DREAD = { version: "0.2.1", debug: false, initialized: false, - config: {} -}; + config: {}, --- ============================================================================= --- LOGGING SYSTEM --- ============================================================================= + -- Logging functions attached to DREAD object for global accessibility + Log: func(message) { + if (DREAD.debug) { + ShowMessage("[DREAD] " + String(message)); + } + }, + + LogError: func(message) { + ShowMessage("[DREAD ERROR] " + String(message)); + }, -let DREAD_Log = func(message) { - if (DREAD.debug) { - ShowMessage("[DREAD] " + String(message)); + LogDebug: func(category, message) { + if (DREAD.debug) { + ShowMessage("[DREAD:" + category + "] " + String(message)); + } } }; -let DREAD_LogError = func(message) { - ShowMessage("[DREAD ERROR] " + String(message)); -}; +-- ============================================================================= +-- LOGGING SYSTEM (Convenience aliases for backwards compatibility) +-- ============================================================================= -let DREAD_LogDebug = func(category, message) { - if (DREAD.debug) { - ShowMessage("[DREAD:" + category + "] " + String(message)); - } -}; +-- Aliases removed - use DREAD.Log, DREAD.LogError, DREAD.LogDebug directly -- ============================================================================= -- RANDOM UTILITIES @@ -293,15 +296,15 @@ let DREAD_SafeGet = func(obj, key, default_val) { }; let DREAD_LoadConfig = func() { - DREAD_LogDebug("Config", "Loading configuration..."); + DREAD.LogDebug("Config", "Loading configuration..."); let loaded_config = FileDataRead("dread_config.json"); if (loaded_config != undefined) { - DREAD_Log("Configuration loaded from file"); + DREAD.Log("Configuration loaded from file"); DREAD.config = loaded_config; } else { - DREAD_Log("Using default configuration"); + DREAD.Log("Using default configuration"); DREAD.config = DREAD_DEFAULT_CONFIG; } @@ -360,7 +363,7 @@ let DREAD_ApplyDifficultyPreset = func(preset_name) { let preset = DREAD_SafeGet(presets, preset_name, undefined); if (preset == undefined) { - DREAD_LogError("Unknown difficulty preset: " + preset_name); + DREAD.LogError("Unknown difficulty preset: " + preset_name); return false; } @@ -372,13 +375,13 @@ let DREAD_ApplyDifficultyPreset = func(preset_name) { DREAD.config.chaos_mode.enabled = preset.chaos_mode; } - DREAD_Log("Applied difficulty preset: " + preset_name); + DREAD.Log("Applied difficulty preset: " + preset_name); return true; }; let DREAD_SaveConfig = func() { FileDataWrite("dread_config.json", DREAD.config); - DREAD_Log("Configuration saved"); + DREAD.Log("Configuration saved"); }; -- ############################################################################# @@ -533,7 +536,7 @@ let DREAD_ApplyArchetypeToNpc = func(npc_id, archetype_name, faction) { let modified_recoil = base_recoil * archetype.recoil_modifier; NpcSetRecoilAimRadius(npc_id, modified_recoil); - DREAD_LogDebug("Archetype", "Applied " + archetype.name + " to " + npc_id); + DREAD.LogDebug("Archetype", "Applied " + archetype.name + " to " + npc_id); return archetype; }; @@ -603,14 +606,14 @@ let DREAD_SpawnStats = { let DREAD_SpawnEnemy = func(enemy_type, x, y) { if (!DREAD_IsValidSpawnPosition(x, y)) { - DREAD_LogDebug("Spawn", "Invalid position: " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Invalid position: " + String(x) + "," + String(y)); return undefined; } InstanceCreate(x, y, enemy_type); DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned enemy at " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Spawned enemy at " + String(x) + "," + String(y)); return true; }; @@ -618,14 +621,14 @@ let DREAD_SpawnNearPlayer = func(enemy_type, count, chase) { NpcObjectSpawnNearPlayer(enemy_type, count, chase); DREAD_SpawnStats.total_spawned += count; - DREAD_LogDebug("Spawn", "Spawned " + String(count) + " near player"); + DREAD.LogDebug("Spawn", "Spawned " + String(count) + " near player"); return true; }; let DREAD_SpawnHuman = func(faction, x, y, archetype_override) { let pos = DREAD_FindValidSpawnPosition(x, y, 30, 5); if (pos.valid == false) { - DREAD_LogDebug("Spawn", "Could not find valid position near " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Could not find valid position near " + String(x) + "," + String(y)); return undefined; } @@ -647,7 +650,7 @@ let DREAD_SpawnHuman = func(faction, x, y, archetype_override) { DREAD_SpawnStats.humans_spawned += 1; DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned " + archetype + " " + faction + " at " + String(pos.x) + "," + String(pos.y)); + DREAD.LogDebug("Spawn", "Spawned " + archetype + " " + faction + " at " + String(pos.x) + "," + String(pos.y)); return { npc_id: npc_id, @@ -676,7 +679,7 @@ let DREAD_SpawnMutant = func(mutant_type, x, y) { DREAD_SpawnStats.mutants_spawned += 1; DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned " + mutant_type + " at " + String(pos.x) + "," + String(pos.y)); + DREAD.LogDebug("Spawn", "Spawned " + mutant_type + " at " + String(pos.x) + "," + String(pos.y)); return { type: mutant_type, x: pos.x, y: pos.y }; }; @@ -731,7 +734,7 @@ let DREAD_SpawnSquad = func(faction, center_x, center_y, size, with_leader) { DREAD_SpawnStats.squads_spawned += 1; - DREAD_LogDebug("Squad", "Spawned squad of " + String(ArrayLength(squad_members)) + " " + faction); + DREAD.LogDebug("Squad", "Spawned squad of " + String(ArrayLength(squad_members)) + " " + faction); return { faction: faction, @@ -814,7 +817,7 @@ let DREAD_ProcessSpawnPoint = func(spawn_point) { return spawned; } else { - DREAD_LogError("Unknown spawn point type: " + spawn_point.type); + DREAD.LogError("Unknown spawn point type: " + spawn_point.type); return undefined; } } @@ -933,7 +936,7 @@ let DREAD_SpawnWave = func(zone) { count = 1; } - DREAD_Log("Invasion wave " + String(DREAD_Invasion.wave_count + 1) + ": Spawning " + String(count) + " enemies"); + DREAD.Log("Invasion wave " + String(DREAD_Invasion.wave_count + 1) + ": Spawning " + String(count) + " enemies"); let i = 0; while (i < count) { @@ -955,7 +958,7 @@ let DREAD_SpawnChaosWave = func() { let count = DREAD_RandomRange(1, 3); - DREAD_Log("Chaos wave: Spawning " + String(count) + " anomalous enemies"); + DREAD.Log("Chaos wave: Spawning " + String(count) + " anomalous enemies"); let i = 0; while (i < count) { @@ -983,7 +986,7 @@ let DREAD_InitInvasion = func() { let first_delay = DREAD_SafeGet(inv_cfg, "first_wave_delay_seconds", 120); DREAD_Invasion.next_wave_time = first_delay * 60; - DREAD_Log("Invasion system initialized. First wave in " + String(first_delay) + " seconds"); + DREAD.Log("Invasion system initialized. First wave in " + String(first_delay) + " seconds"); }; let DREAD_UpdateInvasion = func() { @@ -995,7 +998,7 @@ let DREAD_UpdateInvasion = func() { let max_waves = DREAD_SafeGet(inv_cfg, "max_waves", 3); if (DREAD_Invasion.wave_count >= max_waves) { DREAD_Invasion.active = false; - DREAD_Log("Invasion complete. Spawned " + String(DREAD_Invasion.enemies_this_raid) + " enemies across " + String(DREAD_Invasion.wave_count) + " waves"); + DREAD.Log("Invasion complete. Spawned " + String(DREAD_Invasion.enemies_this_raid) + " enemies across " + String(DREAD_Invasion.wave_count) + " waves"); return; } @@ -1016,7 +1019,7 @@ let DREAD_UpdateInvasion = func() { let DREAD_StopInvasion = func() { DREAD_Invasion.active = false; - DREAD_Log("Invasion stopped"); + DREAD.Log("Invasion stopped"); }; let DREAD_GetInvasionStatus = func() { @@ -1226,7 +1229,7 @@ let DREAD_ExecuteZoneSpawnsTemplate = func(zone_name) { i += 1; } - DREAD_Log(zone_name + " spawning complete. Total: " + String(spawned_count)); + DREAD.Log(zone_name + " spawning complete. Total: " + String(spawned_count)); return spawned_count; }; @@ -1297,11 +1300,11 @@ let FOREST_BOSS_SPAWNS = [ let DREAD_ExecuteForestSpawns = func() { if (!DREAD_IsZoneEnabled("forest")) { - DREAD_Log("Forest zone disabled in config"); + DREAD.Log("Forest zone disabled in config"); return 0; } - DREAD_Log("Executing Forest spawn points..."); + DREAD.Log("Executing Forest spawn points..."); let density = DREAD_GetZoneDensity("forest"); let spawned_count = 0; @@ -1342,13 +1345,13 @@ let DREAD_ExecuteForestSpawns = func() { } else { spawned_count += 1; } - DREAD_LogDebug("Forest", "Spawned at: " + point.name); + DREAD.LogDebug("Forest", "Spawned at: " + point.name); } i += 1; } - DREAD_Log("Forest spawning complete. Total: " + String(spawned_count)); + DREAD.Log("Forest spawning complete. Total: " + String(spawned_count)); return spawned_count; }; @@ -1358,7 +1361,7 @@ let DREAD_ExecuteForestBossSpawns = func() { let boss_point = FOREST_BOSS_SPAWNS[i]; if (DREAD_RandomFloat() < boss_point.chance) { - DREAD_Log("BOSS SPAWN: " + boss_point.name); + DREAD.Log("BOSS SPAWN: " + boss_point.name); InstanceCreate(boss_point.x, boss_point.y, DREAD_BOSS_OBJECTS[boss_point.boss]); @@ -1397,21 +1400,21 @@ let DREAD_GetForestChaosEnemy = func() { -- ############################################################################# let DREAD_Initialize = func() { - DREAD_Log("==========================================="); - DREAD_Log("DREAD v" + DREAD.version + " Initializing..."); - DREAD_Log("==========================================="); + DREAD.Log("==========================================="); + DREAD.Log("DREAD v" + DREAD.version + " Initializing..."); + DREAD.Log("==========================================="); DREAD_LoadConfig(); if (!DREAD_IsFeatureEnabled("mod")) { - DREAD_Log("DREAD is disabled in configuration"); + DREAD.Log("DREAD is disabled in configuration"); return false; } DREAD_ResetSpawnStats(); DREAD.initialized = true; - DREAD_Log("DREAD initialized successfully"); + DREAD.Log("DREAD initialized successfully"); return true; }; @@ -1425,9 +1428,9 @@ let DREAD_OnRaidStart = func() { let zone = DREAD_GetCurrentZone(); - DREAD_Log("==========================================="); - DREAD_Log("Raid started in zone: " + zone); - DREAD_Log("==========================================="); + DREAD.Log("==========================================="); + DREAD.Log("Raid started in zone: " + zone); + DREAD.Log("==========================================="); DREAD_ExecuteZoneSpawns(zone); @@ -1436,11 +1439,11 @@ let DREAD_OnRaidStart = func() { } let stats = DREAD_GetSpawnStats(); - DREAD_Log("Spawn complete. Total: " + String(stats.total_spawned)); - DREAD_Log(" Humans: " + String(stats.humans_spawned)); - DREAD_Log(" Mutants: " + String(stats.mutants_spawned)); - DREAD_Log(" Fauna: " + String(stats.fauna_spawned)); - DREAD_Log(" Squads: " + String(stats.squads_spawned)); + DREAD.Log("Spawn complete. Total: " + String(stats.total_spawned)); + DREAD.Log(" Humans: " + String(stats.humans_spawned)); + DREAD.Log(" Mutants: " + String(stats.mutants_spawned)); + DREAD.Log(" Fauna: " + String(stats.fauna_spawned)); + DREAD.Log(" Squads: " + String(stats.squads_spawned)); }; let DREAD_ExecuteZoneSpawns = func(zone) { @@ -1471,10 +1474,10 @@ let DREAD_ExecuteZoneSpawns = func(zone) { DREAD_ExecuteZoneSpawnsTemplate("cnpp"); } case "hub" { - DREAD_LogDebug("Zone", "In hub - no spawns"); + DREAD.LogDebug("Zone", "In hub - no spawns"); } else { - DREAD_LogDebug("Zone", "Unknown zone: " + zone); + DREAD.LogDebug("Zone", "Unknown zone: " + zone); } } @@ -1484,7 +1487,7 @@ let DREAD_ExecuteZoneSpawns = func(zone) { }; let DREAD_ExecuteChaosSpawns = func(zone) { - DREAD_Log("Chaos Mode active - spawning cross-zone enemies"); + DREAD.Log("Chaos Mode active - spawning cross-zone enemies"); let chaos_count = DREAD_RandomRange(1, 3); @@ -1493,7 +1496,7 @@ let DREAD_ExecuteChaosSpawns = func(zone) { let enemy = DREAD_GetChaosEnemyForZone(zone); if (enemy != undefined) { NpcObjectSpawnNearPlayer(enemy, 1, false); - DREAD_LogDebug("Chaos", "Spawned chaos enemy"); + DREAD.LogDebug("Chaos", "Spawned chaos enemy"); } i += 1; } @@ -1528,8 +1531,8 @@ EventAssignFunction("enter_hub", func() { DREAD_StopInvasion(); let stats = DREAD_GetSpawnStats(); - DREAD_Log("Returned to hub. Session stats:"); - DREAD_Log(" Total spawned: " + String(stats.total_spawned)); + DREAD.Log("Returned to hub. Session stats:"); + DREAD.Log(" Total spawned: " + String(stats.total_spawned)); } }); @@ -1539,7 +1542,7 @@ EventAssignFunction("enter_hub", func() { DREAD_Initialize(); -DREAD_Log("==========================================="); -DREAD_Log("DREAD v" + DREAD.version + " loaded"); -DREAD_Log("Ready for raids!"); -DREAD_Log("==========================================="); +DREAD.Log("==========================================="); +DREAD.Log("DREAD v" + DREAD.version + " loaded"); +DREAD.Log("Ready for raids!"); +DREAD.Log("==========================================="); diff --git a/src/main.catspeak b/src/main.catspeak index 57c701d..e348537 100644 --- a/src/main.catspeak +++ b/src/main.catspeak @@ -35,16 +35,16 @@ -- ============================================================================= let DREAD_Initialize = func() { - DREAD_Log("==========================================="); - DREAD_Log("DREAD v" + DREAD.version + " Initializing..."); - DREAD_Log("==========================================="); + DREAD.Log("==========================================="); + DREAD.Log("DREAD v" + DREAD.version + " Initializing..."); + DREAD.Log("==========================================="); -- Load configuration DREAD_LoadConfig(); -- Check if mod is enabled if (!DREAD_IsFeatureEnabled("mod")) { - DREAD_Log("DREAD is disabled in configuration"); + DREAD.Log("DREAD is disabled in configuration"); return false; } @@ -52,7 +52,7 @@ let DREAD_Initialize = func() { DREAD_ResetSpawnStats(); DREAD.initialized = true; - DREAD_Log("DREAD initialized successfully"); + DREAD.Log("DREAD initialized successfully"); return true; }; @@ -70,9 +70,9 @@ let DREAD_OnRaidStart = func() { let zone = DREAD_GetCurrentZone(); - DREAD_Log("==========================================="); - DREAD_Log("Raid started in zone: " + zone); - DREAD_Log("==========================================="); + DREAD.Log("==========================================="); + DREAD.Log("Raid started in zone: " + zone); + DREAD.Log("==========================================="); -- Execute zone-specific spawns DREAD_ExecuteZoneSpawns(zone); @@ -84,11 +84,11 @@ let DREAD_OnRaidStart = func() { -- Log final statistics let stats = DREAD_GetSpawnStats(); - DREAD_Log("Spawn complete. Total: " + String(stats.total_spawned)); - DREAD_Log(" Humans: " + String(stats.humans_spawned)); - DREAD_Log(" Mutants: " + String(stats.mutants_spawned)); - DREAD_Log(" Fauna: " + String(stats.fauna_spawned)); - DREAD_Log(" Squads: " + String(stats.squads_spawned)); + DREAD.Log("Spawn complete. Total: " + String(stats.total_spawned)); + DREAD.Log(" Humans: " + String(stats.humans_spawned)); + DREAD.Log(" Mutants: " + String(stats.mutants_spawned)); + DREAD.Log(" Fauna: " + String(stats.fauna_spawned)); + DREAD.Log(" Squads: " + String(stats.squads_spawned)); }; -- ============================================================================= @@ -124,10 +124,10 @@ let DREAD_ExecuteZoneSpawns = func(zone) { } case "hub" { -- Don't spawn in hub - DREAD_LogDebug("Zone", "In hub - no spawns"); + DREAD.LogDebug("Zone", "In hub - no spawns"); } else { - DREAD_LogDebug("Zone", "Unknown zone: " + zone); + DREAD.LogDebug("Zone", "Unknown zone: " + zone); } } @@ -142,7 +142,7 @@ let DREAD_ExecuteZoneSpawns = func(zone) { -- ============================================================================= let DREAD_ExecuteChaosSpawns = func(zone) { - DREAD_Log("Chaos Mode active - spawning cross-zone enemies"); + DREAD.Log("Chaos Mode active - spawning cross-zone enemies"); -- Spawn 1-3 chaos enemies at raid start let chaos_count = DREAD_RandomRange(1, 3); @@ -152,7 +152,7 @@ let DREAD_ExecuteChaosSpawns = func(zone) { let enemy = DREAD_GetChaosEnemyForZone(zone); if (enemy != undefined) { NpcObjectSpawnNearPlayer(enemy, 1, false); - DREAD_LogDebug("Chaos", "Spawned chaos enemy"); + DREAD.LogDebug("Chaos", "Spawned chaos enemy"); } i += 1; } @@ -201,8 +201,8 @@ EventAssignFunction("enter_hub", func() { -- Log session stats let stats = DREAD_GetSpawnStats(); - DREAD_Log("Returned to hub. Session stats:"); - DREAD_Log(" Total spawned: " + String(stats.total_spawned)); + DREAD.Log("Returned to hub. Session stats:"); + DREAD.Log(" Total spawned: " + String(stats.total_spawned)); } }); @@ -213,7 +213,7 @@ EventAssignFunction("enter_hub", func() { -- Initialize on mod load DREAD_Initialize(); -DREAD_Log("==========================================="); -DREAD_Log("DREAD v" + DREAD.version + " loaded"); -DREAD_Log("Ready for raids!"); -DREAD_Log("==========================================="); +DREAD.Log("==========================================="); +DREAD.Log("DREAD v" + DREAD.version + " loaded"); +DREAD.Log("Ready for raids!"); +DREAD.Log("==========================================="); diff --git a/src/spawns/forest.catspeak b/src/spawns/forest.catspeak index e50acda..dd5f281 100644 --- a/src/spawns/forest.catspeak +++ b/src/spawns/forest.catspeak @@ -213,11 +213,11 @@ let FOREST_BOSS_SPAWNS = [ -- Execute all Forest spawns let DREAD_ExecuteForestSpawns = func() { if (!DREAD_IsZoneEnabled("forest")) { - DREAD_Log("Forest zone disabled in config"); + DREAD.Log("Forest zone disabled in config"); return 0; } - DREAD_Log("Executing Forest spawn points..."); + DREAD.Log("Executing Forest spawn points..."); let density = DREAD_GetZoneDensity("forest"); let spawned_count = 0; @@ -263,13 +263,13 @@ let DREAD_ExecuteForestSpawns = func() { } else { spawned_count += 1; } - DREAD_LogDebug("Forest", "Spawned at: " + point.name); + DREAD.LogDebug("Forest", "Spawned at: " + point.name); } i += 1; } - DREAD_Log("Forest spawning complete. Total: " + String(spawned_count)); + DREAD.Log("Forest spawning complete. Total: " + String(spawned_count)); return spawned_count; }; @@ -280,7 +280,7 @@ let DREAD_ExecuteForestBossSpawns = func() { let boss_point = FOREST_BOSS_SPAWNS[i]; if (DREAD_RandomFloat() < boss_point.chance) { - DREAD_Log("BOSS SPAWN: " + boss_point.name); + DREAD.Log("BOSS SPAWN: " + boss_point.name); -- Spawn boss InstanceCreate(boss_point.x, boss_point.y, DREAD_BOSS_OBJECTS[boss_point.boss]); diff --git a/src/spawns/zones.catspeak b/src/spawns/zones.catspeak index cf37aaf..c590f88 100644 --- a/src/spawns/zones.catspeak +++ b/src/spawns/zones.catspeak @@ -214,7 +214,7 @@ let DREAD_ExecuteZoneSpawnsTemplate = func(zone_name) { i += 1; } - DREAD_Log(zone_name + " spawning complete. Total: " + String(spawned_count)); + DREAD.Log(zone_name + " spawning complete. Total: " + String(spawned_count)); return spawned_count; }; diff --git a/src/systems/invasion.catspeak b/src/systems/invasion.catspeak index cdc60b3..a89dd9e 100644 --- a/src/systems/invasion.catspeak +++ b/src/systems/invasion.catspeak @@ -117,7 +117,7 @@ let DREAD_SpawnWave = func(zone) { count = 1; } - DREAD_Log("Invasion wave " + String(DREAD_Invasion.wave_count + 1) + ": Spawning " + String(count) + " enemies"); + DREAD.Log("Invasion wave " + String(DREAD_Invasion.wave_count + 1) + ": Spawning " + String(count) + " enemies"); let i = 0; while (i < count) { @@ -144,7 +144,7 @@ let DREAD_SpawnChaosWave = func() { let count = DREAD_RandomRange(1, 3); - DREAD_Log("Chaos wave: Spawning " + String(count) + " anomalous enemies"); + DREAD.Log("Chaos wave: Spawning " + String(count) + " anomalous enemies"); let i = 0; while (i < count) { @@ -178,7 +178,7 @@ let DREAD_InitInvasion = func() { let first_delay = DREAD_ConfigGet("invasion_events.first_wave_delay_seconds", 120); DREAD_Invasion.next_wave_time = first_delay * 60; -- Convert to frames (60 fps) - DREAD_Log("Invasion system initialized. First wave in " + String(first_delay) + " seconds"); + DREAD.Log("Invasion system initialized. First wave in " + String(first_delay) + " seconds"); }; -- Update invasion system (call every frame) @@ -190,7 +190,7 @@ let DREAD_UpdateInvasion = func() { let max_waves = DREAD_ConfigGet("invasion_events.max_waves", 3); if (DREAD_Invasion.wave_count >= max_waves) { DREAD_Invasion.active = false; - DREAD_Log("Invasion complete. Spawned " + String(DREAD_Invasion.enemies_this_raid) + " enemies across " + String(DREAD_Invasion.wave_count) + " waves"); + DREAD.Log("Invasion complete. Spawned " + String(DREAD_Invasion.enemies_this_raid) + " enemies across " + String(DREAD_Invasion.wave_count) + " waves"); return; } @@ -216,7 +216,7 @@ let DREAD_UpdateInvasion = func() { -- Stop invasion let DREAD_StopInvasion = func() { DREAD_Invasion.active = false; - DREAD_Log("Invasion stopped"); + DREAD.Log("Invasion stopped"); }; -- ============================================================================= diff --git a/src/systems/spawning.catspeak b/src/systems/spawning.catspeak index 550fb55..83172d4 100644 --- a/src/systems/spawning.catspeak +++ b/src/systems/spawning.catspeak @@ -69,14 +69,14 @@ let DREAD_SpawnStats = { -- Spawn a single enemy at position let DREAD_SpawnEnemy = func(enemy_type, x, y) { if (!DREAD_IsValidSpawnPosition(x, y)) { - DREAD_LogDebug("Spawn", "Invalid position: " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Invalid position: " + String(x) + "," + String(y)); return undefined; } InstanceCreate(x, y, enemy_type); DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned enemy at " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Spawned enemy at " + String(x) + "," + String(y)); return true; }; @@ -85,7 +85,7 @@ let DREAD_SpawnNearPlayer = func(enemy_type, count, chase) { NpcObjectSpawnNearPlayer(enemy_type, count, chase); DREAD_SpawnStats.total_spawned += count; - DREAD_LogDebug("Spawn", "Spawned " + String(count) + " near player"); + DREAD.LogDebug("Spawn", "Spawned " + String(count) + " near player"); return true; }; @@ -98,7 +98,7 @@ let DREAD_SpawnHuman = func(faction, x, y, archetype_override) { -- Validate position let pos = DREAD_FindValidSpawnPosition(x, y, 30, 5); if (pos.valid == false) { - DREAD_LogDebug("Spawn", "Could not find valid position near " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Could not find valid position near " + String(x) + "," + String(y)); return undefined; } @@ -124,7 +124,7 @@ let DREAD_SpawnHuman = func(faction, x, y, archetype_override) { DREAD_SpawnStats.humans_spawned += 1; DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned " + archetype + " " + faction + " at " + String(pos.x) + "," + String(pos.y)); + DREAD.LogDebug("Spawn", "Spawned " + archetype + " " + faction + " at " + String(pos.x) + "," + String(pos.y)); return { npc_id: npc_id, @@ -158,7 +158,7 @@ let DREAD_SpawnMutant = func(mutant_type, x, y) { DREAD_SpawnStats.mutants_spawned += 1; DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned " + mutant_type + " at " + String(pos.x) + "," + String(pos.y)); + DREAD.LogDebug("Spawn", "Spawned " + mutant_type + " at " + String(pos.x) + "," + String(pos.y)); return { type: mutant_type, x: pos.x, y: pos.y }; }; @@ -224,7 +224,7 @@ let DREAD_SpawnSquad = func(faction, center_x, center_y, size, with_leader) { DREAD_SpawnStats.squads_spawned += 1; - DREAD_LogDebug("Squad", "Spawned squad of " + String(ArrayLength(squad_members)) + " " + faction); + DREAD.LogDebug("Squad", "Spawned squad of " + String(ArrayLength(squad_members)) + " " + faction); return { faction: faction, @@ -316,7 +316,7 @@ let DREAD_ProcessSpawnPoint = func(spawn_point) { return spawned; } else { - DREAD_LogError("Unknown spawn point type: " + spawn_point.type); + DREAD.LogError("Unknown spawn point type: " + spawn_point.type); return undefined; } } diff --git a/src/utils/archetypes.catspeak b/src/utils/archetypes.catspeak index 2335d0f..95ccddb 100644 --- a/src/utils/archetypes.catspeak +++ b/src/utils/archetypes.catspeak @@ -179,7 +179,7 @@ let DREAD_ApplyArchetypeToNpc = func(npc_id, archetype_name, faction) { let modified_recoil = base_recoil * archetype.recoil_modifier; NpcSetRecoilAimRadius(npc_id, modified_recoil); - DREAD_LogDebug("Archetype", "Applied " + archetype.name + " to " + npc_id); + DREAD.LogDebug("Archetype", "Applied " + archetype.name + " to " + npc_id); return archetype; }; diff --git a/src/utils/config.catspeak b/src/utils/config.catspeak index 5aa237e..9092ff1 100644 --- a/src/utils/config.catspeak +++ b/src/utils/config.catspeak @@ -52,16 +52,16 @@ let DREAD_DEFAULT_CONFIG = { -- ============================================================================= let DREAD_LoadConfig = func() { - DREAD_LogDebug("Config", "Loading configuration..."); + DREAD.LogDebug("Config", "Loading configuration..."); -- Try to load from file let loaded_config = FileDataRead("dread_config.json"); if (loaded_config != undefined) { - DREAD_Log("Configuration loaded from file"); + DREAD.Log("Configuration loaded from file"); DREAD.config = loaded_config; } else { - DREAD_Log("Using default configuration"); + DREAD.Log("Using default configuration"); DREAD.config = DREAD_DEFAULT_CONFIG; } @@ -144,7 +144,7 @@ let DREAD_ApplyDifficultyPreset = func(preset_name) { let preset = DREAD_ConfigGet("difficulty_presets." + preset_name, undefined); if (preset == undefined) { - DREAD_LogError("Unknown difficulty preset: " + preset_name); + DREAD.LogError("Unknown difficulty preset: " + preset_name); return false; } @@ -161,10 +161,10 @@ let DREAD_ApplyDifficultyPreset = func(preset_name) { -- Apply archetype weights if (preset.archetype_weights != undefined) { -- Would need to recalculate archetype spawn weights - DREAD_LogDebug("Config", "Applying archetype weights from preset"); + DREAD.LogDebug("Config", "Applying archetype weights from preset"); } - DREAD_Log("Applied difficulty preset: " + preset_name); + DREAD.Log("Applied difficulty preset: " + preset_name); return true; }; @@ -174,5 +174,5 @@ let DREAD_ApplyDifficultyPreset = func(preset_name) { let DREAD_SaveConfig = func() { FileDataWrite("dread_config.json", DREAD.config); - DREAD_Log("Configuration saved"); + DREAD.Log("Configuration saved"); }; diff --git a/src/utils/core.catspeak b/src/utils/core.catspeak index 1b5b191..6824bee 100644 --- a/src/utils/core.catspeak +++ b/src/utils/core.catspeak @@ -12,29 +12,30 @@ let DREAD = { version: "0.2.0", debug: true, initialized: false, - config: {} -}; - --- ============================================================================= --- LOGGING SYSTEM --- ============================================================================= + config: {}, -let DREAD_Log = func(message) { - if (DREAD.debug) { - ShowMessage("[DREAD] " + String(message)); - } -}; + -- Logging functions attached to DREAD object for global accessibility + Log: func(message) { + if (DREAD.debug) { + ShowMessage("[DREAD] " + String(message)); + } + }, -let DREAD_LogError = func(message) { - ShowMessage("[DREAD ERROR] " + String(message)); -}; + LogError: func(message) { + ShowMessage("[DREAD ERROR] " + String(message)); + }, -let DREAD_LogDebug = func(category, message) { - if (DREAD.debug) { - ShowMessage("[DREAD:" + category + "] " + String(message)); + LogDebug: func(category, message) { + if (DREAD.debug) { + ShowMessage("[DREAD:" + category + "] " + String(message)); + } } }; +-- ============================================================================= +-- LOGGING SYSTEM (use DREAD.Log, DREAD.LogError, DREAD.LogDebug directly) +-- ============================================================================= + -- ============================================================================= -- RANDOM UTILITIES -- ============================================================================= diff --git a/workshop/DREAD/init.script b/workshop/DREAD/init.script index baaf4c1..41842bc 100644 --- a/workshop/DREAD/init.script +++ b/workshop/DREAD/init.script @@ -25,29 +25,30 @@ let DREAD = { version: "0.2.1", debug: false, initialized: false, - config: {} -}; - --- ============================================================================= --- LOGGING SYSTEM --- ============================================================================= + config: {}, -let DREAD_Log = func(message) { - if (DREAD.debug) { - ShowMessage("[DREAD] " + String(message)); - } -}; + -- Logging functions attached to DREAD object for global accessibility + Log: func(message) { + if (DREAD.debug) { + ShowMessage("[DREAD] " + String(message)); + } + }, -let DREAD_LogError = func(message) { - ShowMessage("[DREAD ERROR] " + String(message)); -}; + LogError: func(message) { + ShowMessage("[DREAD ERROR] " + String(message)); + }, -let DREAD_LogDebug = func(category, message) { - if (DREAD.debug) { - ShowMessage("[DREAD:" + category + "] " + String(message)); + LogDebug: func(category, message) { + if (DREAD.debug) { + ShowMessage("[DREAD:" + category + "] " + String(message)); + } } }; +-- ============================================================================= +-- LOGGING SYSTEM (use DREAD.Log, DREAD.LogError, DREAD.LogDebug directly) +-- ============================================================================= + -- ============================================================================= -- RANDOM UTILITIES -- ============================================================================= @@ -293,15 +294,15 @@ let DREAD_SafeGet = func(obj, key, default_val) { }; let DREAD_LoadConfig = func() { - DREAD_LogDebug("Config", "Loading configuration..."); + DREAD.LogDebug("Config", "Loading configuration..."); let loaded_config = FileDataRead("dread_config.json"); if (loaded_config != undefined) { - DREAD_Log("Configuration loaded from file"); + DREAD.Log("Configuration loaded from file"); DREAD.config = loaded_config; } else { - DREAD_Log("Using default configuration"); + DREAD.Log("Using default configuration"); DREAD.config = DREAD_DEFAULT_CONFIG; } @@ -360,7 +361,7 @@ let DREAD_ApplyDifficultyPreset = func(preset_name) { let preset = DREAD_SafeGet(presets, preset_name, undefined); if (preset == undefined) { - DREAD_LogError("Unknown difficulty preset: " + preset_name); + DREAD.LogError("Unknown difficulty preset: " + preset_name); return false; } @@ -372,13 +373,13 @@ let DREAD_ApplyDifficultyPreset = func(preset_name) { DREAD.config.chaos_mode.enabled = preset.chaos_mode; } - DREAD_Log("Applied difficulty preset: " + preset_name); + DREAD.Log("Applied difficulty preset: " + preset_name); return true; }; let DREAD_SaveConfig = func() { FileDataWrite("dread_config.json", DREAD.config); - DREAD_Log("Configuration saved"); + DREAD.Log("Configuration saved"); }; -- ############################################################################# @@ -533,7 +534,7 @@ let DREAD_ApplyArchetypeToNpc = func(npc_id, archetype_name, faction) { let modified_recoil = base_recoil * archetype.recoil_modifier; NpcSetRecoilAimRadius(npc_id, modified_recoil); - DREAD_LogDebug("Archetype", "Applied " + archetype.name + " to " + npc_id); + DREAD.LogDebug("Archetype", "Applied " + archetype.name + " to " + npc_id); return archetype; }; @@ -603,14 +604,14 @@ let DREAD_SpawnStats = { let DREAD_SpawnEnemy = func(enemy_type, x, y) { if (!DREAD_IsValidSpawnPosition(x, y)) { - DREAD_LogDebug("Spawn", "Invalid position: " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Invalid position: " + String(x) + "," + String(y)); return undefined; } InstanceCreate(x, y, enemy_type); DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned enemy at " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Spawned enemy at " + String(x) + "," + String(y)); return true; }; @@ -618,14 +619,14 @@ let DREAD_SpawnNearPlayer = func(enemy_type, count, chase) { NpcObjectSpawnNearPlayer(enemy_type, count, chase); DREAD_SpawnStats.total_spawned += count; - DREAD_LogDebug("Spawn", "Spawned " + String(count) + " near player"); + DREAD.LogDebug("Spawn", "Spawned " + String(count) + " near player"); return true; }; let DREAD_SpawnHuman = func(faction, x, y, archetype_override) { let pos = DREAD_FindValidSpawnPosition(x, y, 30, 5); if (pos.valid == false) { - DREAD_LogDebug("Spawn", "Could not find valid position near " + String(x) + "," + String(y)); + DREAD.LogDebug("Spawn", "Could not find valid position near " + String(x) + "," + String(y)); return undefined; } @@ -647,7 +648,7 @@ let DREAD_SpawnHuman = func(faction, x, y, archetype_override) { DREAD_SpawnStats.humans_spawned += 1; DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned " + archetype + " " + faction + " at " + String(pos.x) + "," + String(pos.y)); + DREAD.LogDebug("Spawn", "Spawned " + archetype + " " + faction + " at " + String(pos.x) + "," + String(pos.y)); return { npc_id: npc_id, @@ -676,7 +677,7 @@ let DREAD_SpawnMutant = func(mutant_type, x, y) { DREAD_SpawnStats.mutants_spawned += 1; DREAD_SpawnStats.total_spawned += 1; - DREAD_LogDebug("Spawn", "Spawned " + mutant_type + " at " + String(pos.x) + "," + String(pos.y)); + DREAD.LogDebug("Spawn", "Spawned " + mutant_type + " at " + String(pos.x) + "," + String(pos.y)); return { type: mutant_type, x: pos.x, y: pos.y }; }; @@ -731,7 +732,7 @@ let DREAD_SpawnSquad = func(faction, center_x, center_y, size, with_leader) { DREAD_SpawnStats.squads_spawned += 1; - DREAD_LogDebug("Squad", "Spawned squad of " + String(ArrayLength(squad_members)) + " " + faction); + DREAD.LogDebug("Squad", "Spawned squad of " + String(ArrayLength(squad_members)) + " " + faction); return { faction: faction, @@ -814,7 +815,7 @@ let DREAD_ProcessSpawnPoint = func(spawn_point) { return spawned; } else { - DREAD_LogError("Unknown spawn point type: " + spawn_point.type); + DREAD.LogError("Unknown spawn point type: " + spawn_point.type); return undefined; } } @@ -933,7 +934,7 @@ let DREAD_SpawnWave = func(zone) { count = 1; } - DREAD_Log("Invasion wave " + String(DREAD_Invasion.wave_count + 1) + ": Spawning " + String(count) + " enemies"); + DREAD.Log("Invasion wave " + String(DREAD_Invasion.wave_count + 1) + ": Spawning " + String(count) + " enemies"); let i = 0; while (i < count) { @@ -955,7 +956,7 @@ let DREAD_SpawnChaosWave = func() { let count = DREAD_RandomRange(1, 3); - DREAD_Log("Chaos wave: Spawning " + String(count) + " anomalous enemies"); + DREAD.Log("Chaos wave: Spawning " + String(count) + " anomalous enemies"); let i = 0; while (i < count) { @@ -983,7 +984,7 @@ let DREAD_InitInvasion = func() { let first_delay = DREAD_SafeGet(inv_cfg, "first_wave_delay_seconds", 120); DREAD_Invasion.next_wave_time = first_delay * 60; - DREAD_Log("Invasion system initialized. First wave in " + String(first_delay) + " seconds"); + DREAD.Log("Invasion system initialized. First wave in " + String(first_delay) + " seconds"); }; let DREAD_UpdateInvasion = func() { @@ -995,7 +996,7 @@ let DREAD_UpdateInvasion = func() { let max_waves = DREAD_SafeGet(inv_cfg, "max_waves", 3); if (DREAD_Invasion.wave_count >= max_waves) { DREAD_Invasion.active = false; - DREAD_Log("Invasion complete. Spawned " + String(DREAD_Invasion.enemies_this_raid) + " enemies across " + String(DREAD_Invasion.wave_count) + " waves"); + DREAD.Log("Invasion complete. Spawned " + String(DREAD_Invasion.enemies_this_raid) + " enemies across " + String(DREAD_Invasion.wave_count) + " waves"); return; } @@ -1016,7 +1017,7 @@ let DREAD_UpdateInvasion = func() { let DREAD_StopInvasion = func() { DREAD_Invasion.active = false; - DREAD_Log("Invasion stopped"); + DREAD.Log("Invasion stopped"); }; let DREAD_GetInvasionStatus = func() { @@ -1226,7 +1227,7 @@ let DREAD_ExecuteZoneSpawnsTemplate = func(zone_name) { i += 1; } - DREAD_Log(zone_name + " spawning complete. Total: " + String(spawned_count)); + DREAD.Log(zone_name + " spawning complete. Total: " + String(spawned_count)); return spawned_count; }; @@ -1297,11 +1298,11 @@ let FOREST_BOSS_SPAWNS = [ let DREAD_ExecuteForestSpawns = func() { if (!DREAD_IsZoneEnabled("forest")) { - DREAD_Log("Forest zone disabled in config"); + DREAD.Log("Forest zone disabled in config"); return 0; } - DREAD_Log("Executing Forest spawn points..."); + DREAD.Log("Executing Forest spawn points..."); let density = DREAD_GetZoneDensity("forest"); let spawned_count = 0; @@ -1342,13 +1343,13 @@ let DREAD_ExecuteForestSpawns = func() { } else { spawned_count += 1; } - DREAD_LogDebug("Forest", "Spawned at: " + point.name); + DREAD.LogDebug("Forest", "Spawned at: " + point.name); } i += 1; } - DREAD_Log("Forest spawning complete. Total: " + String(spawned_count)); + DREAD.Log("Forest spawning complete. Total: " + String(spawned_count)); return spawned_count; }; @@ -1358,7 +1359,7 @@ let DREAD_ExecuteForestBossSpawns = func() { let boss_point = FOREST_BOSS_SPAWNS[i]; if (DREAD_RandomFloat() < boss_point.chance) { - DREAD_Log("BOSS SPAWN: " + boss_point.name); + DREAD.Log("BOSS SPAWN: " + boss_point.name); InstanceCreate(boss_point.x, boss_point.y, DREAD_BOSS_OBJECTS[boss_point.boss]); @@ -1397,21 +1398,21 @@ let DREAD_GetForestChaosEnemy = func() { -- ############################################################################# let DREAD_Initialize = func() { - DREAD_Log("==========================================="); - DREAD_Log("DREAD v" + DREAD.version + " Initializing..."); - DREAD_Log("==========================================="); + DREAD.Log("==========================================="); + DREAD.Log("DREAD v" + DREAD.version + " Initializing..."); + DREAD.Log("==========================================="); DREAD_LoadConfig(); if (!DREAD_IsFeatureEnabled("mod")) { - DREAD_Log("DREAD is disabled in configuration"); + DREAD.Log("DREAD is disabled in configuration"); return false; } DREAD_ResetSpawnStats(); DREAD.initialized = true; - DREAD_Log("DREAD initialized successfully"); + DREAD.Log("DREAD initialized successfully"); return true; }; @@ -1425,9 +1426,9 @@ let DREAD_OnRaidStart = func() { let zone = DREAD_GetCurrentZone(); - DREAD_Log("==========================================="); - DREAD_Log("Raid started in zone: " + zone); - DREAD_Log("==========================================="); + DREAD.Log("==========================================="); + DREAD.Log("Raid started in zone: " + zone); + DREAD.Log("==========================================="); DREAD_ExecuteZoneSpawns(zone); @@ -1436,11 +1437,11 @@ let DREAD_OnRaidStart = func() { } let stats = DREAD_GetSpawnStats(); - DREAD_Log("Spawn complete. Total: " + String(stats.total_spawned)); - DREAD_Log(" Humans: " + String(stats.humans_spawned)); - DREAD_Log(" Mutants: " + String(stats.mutants_spawned)); - DREAD_Log(" Fauna: " + String(stats.fauna_spawned)); - DREAD_Log(" Squads: " + String(stats.squads_spawned)); + DREAD.Log("Spawn complete. Total: " + String(stats.total_spawned)); + DREAD.Log(" Humans: " + String(stats.humans_spawned)); + DREAD.Log(" Mutants: " + String(stats.mutants_spawned)); + DREAD.Log(" Fauna: " + String(stats.fauna_spawned)); + DREAD.Log(" Squads: " + String(stats.squads_spawned)); }; let DREAD_ExecuteZoneSpawns = func(zone) { @@ -1471,10 +1472,10 @@ let DREAD_ExecuteZoneSpawns = func(zone) { DREAD_ExecuteZoneSpawnsTemplate("cnpp"); } case "hub" { - DREAD_LogDebug("Zone", "In hub - no spawns"); + DREAD.LogDebug("Zone", "In hub - no spawns"); } else { - DREAD_LogDebug("Zone", "Unknown zone: " + zone); + DREAD.LogDebug("Zone", "Unknown zone: " + zone); } } @@ -1484,7 +1485,7 @@ let DREAD_ExecuteZoneSpawns = func(zone) { }; let DREAD_ExecuteChaosSpawns = func(zone) { - DREAD_Log("Chaos Mode active - spawning cross-zone enemies"); + DREAD.Log("Chaos Mode active - spawning cross-zone enemies"); let chaos_count = DREAD_RandomRange(1, 3); @@ -1493,7 +1494,7 @@ let DREAD_ExecuteChaosSpawns = func(zone) { let enemy = DREAD_GetChaosEnemyForZone(zone); if (enemy != undefined) { NpcObjectSpawnNearPlayer(enemy, 1, false); - DREAD_LogDebug("Chaos", "Spawned chaos enemy"); + DREAD.LogDebug("Chaos", "Spawned chaos enemy"); } i += 1; } @@ -1528,8 +1529,8 @@ EventAssignFunction("enter_hub", func() { DREAD_StopInvasion(); let stats = DREAD_GetSpawnStats(); - DREAD_Log("Returned to hub. Session stats:"); - DREAD_Log(" Total spawned: " + String(stats.total_spawned)); + DREAD.Log("Returned to hub. Session stats:"); + DREAD.Log(" Total spawned: " + String(stats.total_spawned)); } }); @@ -1539,7 +1540,7 @@ EventAssignFunction("enter_hub", func() { DREAD_Initialize(); -DREAD_Log("==========================================="); -DREAD_Log("DREAD v" + DREAD.version + " loaded"); -DREAD_Log("Ready for raids!"); -DREAD_Log("==========================================="); +DREAD.Log("==========================================="); +DREAD.Log("DREAD v" + DREAD.version + " loaded"); +DREAD.Log("Ready for raids!"); +DREAD.Log("===========================================");