From 71d5a3bff2a201d2f43649647c9222d2236e2b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Sat, 10 Oct 2020 21:16:28 -0700 Subject: [PATCH] group NPC runtime data together --- MWSE/mods/celediel/NPCsGoHome/common.lua | 19 ++++---- .../NPCsGoHome/functions/processors.lua | 48 ++++++++++--------- MWSE/mods/celediel/NPCsGoHome/main.lua | 5 +- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/MWSE/mods/celediel/NPCsGoHome/common.lua b/MWSE/mods/celediel/NPCsGoHome/common.lua index 2d2d858..3cdd21c 100644 --- a/MWSE/mods/celediel/NPCsGoHome/common.lua +++ b/MWSE/mods/celediel/NPCsGoHome/common.lua @@ -39,14 +39,17 @@ this.runtimeData = { -- used for checking when entering wandering NPC's house, will probably remove byCell = {} }, - -- NPCs who have been moved - movedNPCs = {}, - -- NPCs who stick around in bad weather and have been moved - movedBadWeatherNPCs = {}, - -- NPCs who have been disabled - disabledNPCs = {}, - -- NPCs who stick around in bad weather and have been disabled - disabledBadWeatherNPCs = {}, + -- holder for all NPC data + NPCs = { + -- NPCs who have been moved + moved = {}, + -- NPCs who stick around in bad weather and have been moved + movedBadWeather = {}, + -- NPCs who have been disabled + disabled = {}, + -- NPCs who stick around in bad weather and have been disabled + disabledBadWeather = {} + }, -- positions that haven't been used positions = {}, -- player companions diff --git a/MWSE/mods/celediel/NPCsGoHome/functions/processors.lua b/MWSE/mods/celediel/NPCsGoHome/functions/processors.lua index 601a488..e8d0f5c 100644 --- a/MWSE/mods/celediel/NPCsGoHome/functions/processors.lua +++ b/MWSE/mods/celediel/NPCsGoHome/functions/processors.lua @@ -16,11 +16,12 @@ local function moveNPC(homeData) -- add to in memory table local badWeather = checks.isBadWeatherNPC(npc) if badWeather then - common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] = common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] or {} - common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName][npc.id] = homeData + common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] = + common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] or {} + common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName][npc.id] = homeData else - common.runtimeData.movedNPCs[homeData.ogPlaceName] = common.runtimeData.movedNPCs[homeData.ogPlaceName] or {} - common.runtimeData.movedNPCs[homeData.ogPlaceName][npc.id] = homeData + common.runtimeData.NPCs.moved[homeData.ogPlaceName] = common.runtimeData.NPCs.moved[homeData.ogPlaceName] or {} + common.runtimeData.NPCs.moved[homeData.ogPlaceName][npc.id] = homeData end -- set npc data, so we can move NPCs back after a load @@ -45,11 +46,11 @@ local function disableNPC(npc, cell) -- same thing as moveNPC, but disables instead -- add to runtimeData if checks.isBadWeatherNPC(npc) then - common.runtimeData.disabledBadWeatherNPCs[cell.id] = common.runtimeData.disabledBadWeatherNPCs[cell.id] or {} - common.runtimeData.disabledBadWeatherNPCs[cell.id][npc.id] = npc + common.runtimeData.NPCs.disabledBadWeather[cell.id] = common.runtimeData.NPCs.disabledBadWeather[cell.id] or {} + common.runtimeData.NPCs.disabledBadWeather[cell.id][npc.id] = npc else - common.runtimeData.disabledNPCs[cell.id] = common.runtimeData.disabledNPCs[cell.id] or {} - common.runtimeData.disabledNPCs[cell.id][npc.id] = npc + common.runtimeData.NPCs.disabled[cell.id] = common.runtimeData.NPCs.disabled[cell.id] or {} + common.runtimeData.NPCs.disabled[cell.id][npc.id] = npc end -- set NPC data npc.data.NPCsGoHome = {disabled = true} @@ -132,11 +133,12 @@ local function checkForMovedOrDisabledNPCs(cell) if npc.data.NPCsGoHome.disabled then -- disabled NPC if badWeather then - common.runtimeData.disabledBadWeatherNPCs[cell.id] = common.runtimeData.disabledBadWeatherNPCs[cell.id] or {} - common.runtimeData.disabledBadWeatherNPCs[cell.id][npc.id] = npc + common.runtimeData.NPCs.disabledBadWeather[cell.id] = + common.runtimeData.NPCs.disabledBadWeather[cell.id] or {} + common.runtimeData.NPCs.disabledBadWeather[cell.id][npc.id] = npc else - common.runtimeData.disabledNPCs[cell.id] = common.runtimeData.disabledNPCs[cell.id] or {} - common.runtimeData.disabledNPCs[cell.id][npc.id] = npc + common.runtimeData.NPCs.disabled[cell.id] = common.runtimeData.NPCs.disabled[cell.id] or {} + common.runtimeData.NPCs.disabled[cell.id][npc.id] = npc end else -- homed NPC @@ -147,11 +149,13 @@ local function checkForMovedOrDisabledNPCs(cell) -- add to in memory table if badWeather then - common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] = common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] or {} - common.runtimeData.movedBadWeatherNPCs[cell.id][npc.id] = homeData + common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] = + common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] or {} + common.runtimeData.NPCs.movedBadWeather[cell.id][npc.id] = homeData else - common.runtimeData.movedNPCs[homeData.ogPlaceName] = common.runtimeData.movedNPCs[homeData.ogPlaceName] or {} - common.runtimeData.movedNPCs[cell.id][npc.id] = homeData + common.runtimeData.NPCs.moved[homeData.ogPlaceName] = + common.runtimeData.NPCs.moved[homeData.ogPlaceName] or {} + common.runtimeData.NPCs.moved[cell.id][npc.id] = homeData end end end @@ -216,8 +220,8 @@ this.processNPCs = function(cell) -- LuaFormatter off -- check for bad weather NPCs that have been disabled, and re-enable them if config.keepBadWeatherNPCs then - if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs[cell.id]) end - if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs[cell.id]) end + if not common.isEmptyTable(common.runtimeData.NPCs.movedBadWeather[cell.id]) then putNPCsBack(common.runtimeData.NPCs.movedBadWeather[cell.id]) end + if not common.isEmptyTable(common.runtimeData.NPCs.disabledBadWeather[cell.id]) then reEnableNPCs(common.runtimeData.NPCs.disabledBadWeather[cell.id]) end end elseif night then log(common.logLevels.large, "[PROC] !!Good or bad weather and night!!") @@ -228,10 +232,10 @@ this.processNPCs = function(cell) else log(common.logLevels.large, "[PROC] !!Good weather and not night!!") -- put everyone back - if not common.isEmptyTable(common.runtimeData.movedNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedNPCs[cell.id]) end - if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs[cell.id]) end - if not common.isEmptyTable(common.runtimeData.disabledNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledNPCs[cell.id]) end - if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs[cell.id]) end + if not common.isEmptyTable(common.runtimeData.NPCs.moved[cell.id]) then putNPCsBack(common.runtimeData.NPCs.moved[cell.id]) end + if not common.isEmptyTable(common.runtimeData.NPCs.movedBadWeather[cell.id]) then putNPCsBack(common.runtimeData.NPCs.movedBadWeather[cell.id]) end + if not common.isEmptyTable(common.runtimeData.NPCs.disabled[cell.id]) then reEnableNPCs(common.runtimeData.NPCs.disabled[cell.id]) end + if not common.isEmptyTable(common.runtimeData.NPCs.disabledBadWeather[cell.id]) then reEnableNPCs(common.runtimeData.NPCs.disabledBadWeather[cell.id]) end -- LuaFormatter on end end diff --git a/MWSE/mods/celediel/NPCsGoHome/main.lua b/MWSE/mods/celediel/NPCsGoHome/main.lua index ecc8be3..43ca17a 100644 --- a/MWSE/mods/celediel/NPCsGoHome/main.lua +++ b/MWSE/mods/celediel/NPCsGoHome/main.lua @@ -101,9 +101,8 @@ local function updateCells() log(common.logLevels.large, "[MAIN] Applying changes to cell %s", cell.id) -- initialize runtime data if needed - for _, t in pairs({"movedNPCs", "movedBadWeatherNPCs", "disabledNPCs", "disabledBadWeatherNPCs"}) do - common.runtimeData[t][cell.id] = common.runtimeData[t][cell.id] or {} - end + for _, t in pairs(common.runtimeData.NPCs) do t[cell.id] = t[cell.id] or {} end + applyChanges(cell) end