From 313f391c73438c676cc6ab99a9dfe0fbf89a7993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Tue, 4 Aug 2020 21:09:34 -0700 Subject: [PATCH] option to keep door randomized (previous functionality) Previously, doors kept their randomized destination, thus altering the door permanently for that save (presumably). This commit fixes that, but keeps the "feature" there as an option for masochists. --- MWSE/mods/celediel/DoorRandomizer/config.lua | 1 + MWSE/mods/celediel/DoorRandomizer/main.lua | 36 ++++++++++++++++++-- MWSE/mods/celediel/DoorRandomizer/mcm.lua | 23 ++++++------- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/MWSE/mods/celediel/DoorRandomizer/config.lua b/MWSE/mods/celediel/DoorRandomizer/config.lua index b528aff..3034cae 100644 --- a/MWSE/mods/celediel/DoorRandomizer/config.lua +++ b/MWSE/mods/celediel/DoorRandomizer/config.lua @@ -5,6 +5,7 @@ local defaultConfig = { interiorExterior = common.cellTypes.match, wildernessCells = true, needDoor = true, + keepRandomized = false, debug = false, ignoredCells = {}, -- some of these aren't cell change doors but whatever diff --git a/MWSE/mods/celediel/DoorRandomizer/main.lua b/MWSE/mods/celediel/DoorRandomizer/main.lua index 78345e7..8af8fae 100644 --- a/MWSE/mods/celediel/DoorRandomizer/main.lua +++ b/MWSE/mods/celediel/DoorRandomizer/main.lua @@ -4,6 +4,9 @@ local config = require("celediel.DoorRandomizer.config").getConfig() local cells = {} +-- the door's original destination +local ogDestination + -- {{{ helper functions local function log(...) if config.debug then mwse.log("[%s] %s", common.modName, string.format(...)) end end @@ -18,7 +21,7 @@ end local function isTypeMatch(ogCell, chosenCell) return ((ogCell.isInterior and ogCell.behavesAsExterior) or not ogCell.isInterior) == - ((chosenCell.isInterior and chosenCell.behavesAsExterior) or not chosenCell.isInterior) + ((chosenCell.isInterior and chosenCell.behavesAsExterior) or not chosenCell.isInterior) end -- }}} @@ -32,8 +35,8 @@ local function pickSpot(cell) for cellDoor in cell:iterateReferences(tes3.objectType.door) do if cellDoor.destination then -- only cell change doors -- loop through doors in THAT cell to find the door that led us there in the first place - log("Looking through door %s in %s leading to %s", cellDoor.name or cellDoor.id, - cell.id, cellDoor.destination.cell.id) + log("Looking through door %s in %s leading to %s", + cellDoor.name or cellDoor.id, cell.id, cellDoor.destination.cell.id) for innerDoor in cellDoor.destination.cell:iterateReferences(tes3.objectType.door) do if innerDoor.destination and innerDoor.destination.cell.id == cell.id then -- found the door, now add where that door puts a player to our table @@ -132,17 +135,44 @@ local function onActivate(e) log("Picked %s at (%s) facing (%s)", cell.id, spot.position, spot.orientation) + -- store the original destination so that we can reset it later + if not config.keepRandomized and not ogDestination then + ogDestination = { + door = door, + cell = door.destination.cell, + position = door.destination.marker.position, + orientation = door.destination.marker.orientation + } + end + -- set the door's destination to the picked cell and position/orientation tes3.setDestination({reference = door, cell = cell, position = spot.position, orientation = spot.orientation}) end end +local function onCellChanged(e) + if not config.keepRandomized and ogDestination then + log("Resetting door to original destination") + + -- it's later + tes3.setDestination({ + reference = ogDestination.door, + cell = ogDestination.cell, + position = ogDestination.position, + orientation = ogDestination.orientation + }) + + timer.delayOneFrame(function() ogDestination = nil end) + end +end + local function onInitialized(e) for cell, _ in pairs(tes3.dataHandler.nonDynamicData.cells) do table.insert(cells, cell) end log("found %s cells", #cells) event.register("activate", onActivate) + event.register("cellChanged", onCellChanged) end -- }}} diff --git a/MWSE/mods/celediel/DoorRandomizer/mcm.lua b/MWSE/mods/celediel/DoorRandomizer/mcm.lua index 6a49b7c..18f1b64 100644 --- a/MWSE/mods/celediel/DoorRandomizer/mcm.lua +++ b/MWSE/mods/celediel/DoorRandomizer/mcm.lua @@ -1,9 +1,7 @@ local common = require("celediel.DoorRandomizer.common") local config = require("celediel.DoorRandomizer.config").getConfig() -local function createTableVar(id) - return mwse.mcm.createTableVariable({id = id, table = config}) -end +local function createTableVar(id) return mwse.mcm.createTableVariable({id = id, table = config}) end local template = mwse.mcm.createTemplate({name = common.modName}) template:saveOnClose(common.configPath, config) @@ -15,10 +13,7 @@ local page = template:createSideBarPage({ local category = page:createCategory(common.modName) -category:createYesNoButton({ - label = "Pick wilderness cells?", - variable = createTableVar("wildernessCells") -}) +category:createYesNoButton({label = "Pick wilderness cells?", variable = createTableVar("wildernessCells")}) category:createYesNoButton({ label = "Pick only cells that place the player at doors?", @@ -47,10 +42,16 @@ category:createSlider({ }) category:createYesNoButton({ - label = "Debug logging", - variable = createTableVar("debug") + label = "Keep randomized destination?", + description = "Doors keep the randomized destination, or get " .. + "reset to their original destination after cell change.\n\n" .. + "Warning! This (presumably) permanently alters the door's " .. + "destination for that save. Enable at your own peril!", + variable = createTableVar("keepRandomized") }) +category:createYesNoButton({label = "Debug logging", variable = createTableVar("debug")}) + template:createExclusionsPage({ label = "Ignored cells", description = "These cells will not even be considered when randomizing.", @@ -61,9 +62,7 @@ template:createExclusionsPage({ label = "Cells", callback = function() local cells = {} - for cell, _ in pairs(tes3.dataHandler.nonDynamicData.cells) do - table.insert(cells, cell) - end + for cell, _ in pairs(tes3.dataHandler.nonDynamicData.cells) do table.insert(cells, cell) end return cells end }