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.
This commit is contained in:
Lilian Jónsdóttir 2020-08-04 21:09:34 -07:00
parent c87003de46
commit 313f391c73
3 changed files with 45 additions and 15 deletions

View file

@ -5,6 +5,7 @@ local defaultConfig = {
interiorExterior = common.cellTypes.match, interiorExterior = common.cellTypes.match,
wildernessCells = true, wildernessCells = true,
needDoor = true, needDoor = true,
keepRandomized = false,
debug = false, debug = false,
ignoredCells = {}, ignoredCells = {},
-- some of these aren't cell change doors but whatever -- some of these aren't cell change doors but whatever

View file

@ -4,6 +4,9 @@ local config = require("celediel.DoorRandomizer.config").getConfig()
local cells = {} local cells = {}
-- the door's original destination
local ogDestination
-- {{{ helper functions -- {{{ helper functions
local function log(...) if config.debug then mwse.log("[%s] %s", common.modName, string.format(...)) end end 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) local function isTypeMatch(ogCell, chosenCell)
return ((ogCell.isInterior and ogCell.behavesAsExterior) or not ogCell.isInterior) == 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 end
-- }}} -- }}}
@ -32,8 +35,8 @@ local function pickSpot(cell)
for cellDoor in cell:iterateReferences(tes3.objectType.door) do for cellDoor in cell:iterateReferences(tes3.objectType.door) do
if cellDoor.destination then -- only cell change doors 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 -- 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, log("Looking through door %s in %s leading to %s",
cell.id, cellDoor.destination.cell.id) cellDoor.name or cellDoor.id, cell.id, cellDoor.destination.cell.id)
for innerDoor in cellDoor.destination.cell:iterateReferences(tes3.objectType.door) do for innerDoor in cellDoor.destination.cell:iterateReferences(tes3.objectType.door) do
if innerDoor.destination and innerDoor.destination.cell.id == cell.id then 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 -- 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) 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 -- set the door's destination to the picked cell and position/orientation
tes3.setDestination({reference = door, cell = cell, position = spot.position, orientation = spot.orientation}) tes3.setDestination({reference = door, cell = cell, position = spot.position, orientation = spot.orientation})
end end
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) local function onInitialized(e)
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
log("found %s cells", #cells) log("found %s cells", #cells)
event.register("activate", onActivate) event.register("activate", onActivate)
event.register("cellChanged", onCellChanged)
end end
-- }}} -- }}}

View file

@ -1,9 +1,7 @@
local common = require("celediel.DoorRandomizer.common") local common = require("celediel.DoorRandomizer.common")
local config = require("celediel.DoorRandomizer.config").getConfig() local config = require("celediel.DoorRandomizer.config").getConfig()
local function createTableVar(id) local function createTableVar(id) return mwse.mcm.createTableVariable({id = id, table = config}) end
return mwse.mcm.createTableVariable({id = id, table = config})
end
local template = mwse.mcm.createTemplate({name = common.modName}) local template = mwse.mcm.createTemplate({name = common.modName})
template:saveOnClose(common.configPath, config) template:saveOnClose(common.configPath, config)
@ -15,10 +13,7 @@ local page = template:createSideBarPage({
local category = page:createCategory(common.modName) local category = page:createCategory(common.modName)
category:createYesNoButton({ category:createYesNoButton({label = "Pick wilderness cells?", variable = createTableVar("wildernessCells")})
label = "Pick wilderness cells?",
variable = createTableVar("wildernessCells")
})
category:createYesNoButton({ category:createYesNoButton({
label = "Pick only cells that place the player at doors?", label = "Pick only cells that place the player at doors?",
@ -47,10 +42,16 @@ category:createSlider({
}) })
category:createYesNoButton({ category:createYesNoButton({
label = "Debug logging", label = "Keep randomized destination?",
variable = createTableVar("debug") 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({ template:createExclusionsPage({
label = "Ignored cells", label = "Ignored cells",
description = "These cells will not even be considered when randomizing.", description = "These cells will not even be considered when randomizing.",
@ -61,9 +62,7 @@ template:createExclusionsPage({
label = "Cells", label = "Cells",
callback = function() callback = function()
local cells = {} local cells = {}
for cell, _ in pairs(tes3.dataHandler.nonDynamicData.cells) do for cell, _ in pairs(tes3.dataHandler.nonDynamicData.cells) do table.insert(cells, cell) end
table.insert(cells, cell)
end
return cells return cells
end end
} }