Skip to content

Commit

Permalink
Merge pull request #3 from stanleyqubit/feature/volumeSave
Browse files Browse the repository at this point in the history
New feature: volumeSave
  • Loading branch information
tewlwolow committed Apr 16, 2023
2 parents 650b595 + 34ac003 commit dc577e7
Show file tree
Hide file tree
Showing 35 changed files with 1,058 additions and 552 deletions.
9 changes: 4 additions & 5 deletions 00 Core/MWSE/mods/tew/AURA/Ambient/Interior/interiorMain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local config = require("tew.AURA.config")
local sounds = require("tew.AURA.sounds")
local common = require("tew.AURA.common")
local findWholeWords = common.findWholeWords
local intVol = config.intVol / 200
local interiorMusic = config.interiorMusic

local played = false
Expand Down Expand Up @@ -162,7 +161,7 @@ local function cellCheck()
local typeCell = getTypeCell(5, cell)
if typeCell ~= nil then
debugLog("Found appropriate cell. Playing interior ambient sound.")
sounds.playImmediate { module = moduleName, type = typeCell, volume = intVol }
sounds.playImmediate { module = moduleName, type = typeCell }
return
end

Expand All @@ -172,7 +171,7 @@ local function cellCheck()
for _, pattern in ipairs(taverns) do
if string.find(cell.name, pattern) then
debugLog("Found appropriate tavern. Playing interior ambient sound for race type: " .. race)
sounds.playImmediate { module = moduleName, race = race, volume = intVol }
sounds.playImmediate { module = moduleName, race = race }
return
end
end
Expand All @@ -186,7 +185,7 @@ local function cellCheck()
for _, pattern in pairs(nameTable) do
if findWholeWords(cell.name, pattern) then
debugLog("Found appropriate cell. Playing interior ambient sound for interior type: " .. cellType)
sounds.playImmediate { module = moduleName, type = cellType, volume = intVol }
sounds.playImmediate { module = moduleName, type = cellType }
return
end
end
Expand All @@ -208,7 +207,7 @@ local function cellCheck()
race = string.sub(race, 1, 3):lower()
debugLog("Found appropriate tavern. Playing interior ambient sound for race type: " .. race)

sounds.playImmediate { module = moduleName, race = race, volume = intVol }
sounds.playImmediate { module = moduleName, race = race }
return
end
end
Expand Down
104 changes: 32 additions & 72 deletions 00 Core/MWSE/mods/tew/AURA/Ambient/Outdoor/outdoorMain.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
local cellData = require("tew.AURA.cellData")
local climates = require("tew.AURA.Ambient.Outdoor.outdoorClimates")
local config = require("tew.AURA.config")
local common = require("tew.AURA.common")
local defaults = require("tew.AURA.defaults")
local sounds = require("tew.AURA.sounds")

local isOpenPlaza = common.isOpenPlaza

local moduleAmbientOutdoor = config.moduleAmbientOutdoor
local moduleInteriorWeather = config.moduleInteriorWeather
local playSplash = config.playSplash
local OAvol = config.OAvol / 200
local splashVol = config.splashVol / 200
local playInteriorAmbient = config.playInteriorAmbient
local OAvol, bigMult, smaMult

local moduleName = "outdoor"

local climateLast, weatherLast, timeLast
local climateNow, weatherNow, timeNow
local windoors, interiorTimer
local interiorTimer
local cell, cellLast
local WtC

Expand All @@ -33,8 +33,7 @@ local function updateConditions(resetTimerFlag)
if resetTimerFlag
and interiorTimer
and cell.isInterior
and windoors
and not table.empty(windoors) then
and not table.empty(cellData.windoors) then
interiorTimer:reset()
end
timeLast = timeNow
Expand All @@ -44,36 +43,36 @@ local function updateConditions(resetTimerFlag)
end

local function stopWindoors()
if windoors and not table.empty(windoors) then
for _, windoor in ipairs(windoors) do
if not table.empty(cellData.windoors) then
for _, windoor in ipairs(cellData.windoors) do
sounds.removeImmediate { module = moduleName, reference = windoor }
end
end
end

-- Because MW engine will otherwise scrap the sound and not put it up again. Dumb thing --
local function playWindoors(useLast)
if not windoors or table.empty(windoors) then return end
if table.empty(cellData.windoors) then return end
debugLog("Updating interior doors and windows.")
local windoorVol = (0.25 * OAvol) - (0.005 * #windoors)
local windoorVol = (bigMult * OAvol) - (0.005 * #cellData.windoors)
local playerPos = tes3.player.position:copy()
local playLast
for i, windoor in ipairs(windoors) do
for i, windoor in ipairs(cellData.windoors) do
if windoor ~= nil and playerPos:distance(windoor.position:copy()) < 1800 then
if i == 1 then
playLast = useLast
else
playLast = true
end
sounds.play{
module = moduleName,
climate = climateNow,
time = timeNow,
volume = windoorVol,
pitch = 0.8,
reference = windoor,
last = playLast,
}
sounds.play{
module = moduleName,
climate = climateNow,
time = timeNow,
volume = windoorVol,
pitch = 0.8,
newRef = windoor,
last = playLast,
}
end
end
end
Expand All @@ -89,7 +88,6 @@ local function cellCheck(e)
end

debugLog("Cell changed or time check triggered. Running cell check.")
OAvol = config.OAvol / 200

cell = tes3.getPlayerCell()
if (not cell) then
Expand Down Expand Up @@ -118,7 +116,7 @@ local function cellCheck(e)
if blockedWeathers[weatherNow] then
debugLog("Uneligible weather detected. Removing sounds.")
stopWindoors()
sounds.remove { module = moduleName, volume = OAvol }
sounds.remove { module = moduleName }
updateConditions()
return
end
Expand Down Expand Up @@ -155,37 +153,28 @@ local function cellCheck(e)
debugLog("Time: " .. timeNow)

-- Randomising every time any of these change --
-- We could drop weather check if we don't want to randomise when weather changes, even if time and climate are the same --
-- Alternatively, we could add another elseif to the transition filter chunk below that suits our preferences.
local useLast = (timeNow == timeLast and weatherNow == weatherLast and climateNow == climateLast) or false

-- Transition filter chunk --
if timeNow == timeLast
and climateNow == climateLast
and weatherNow == weatherLast
and cell == cellLast then
if useLast and (cell == cellLast) then
debugLog("Found same cell, same conditions. Returning.")
updateConditions(true)
return
elseif timeNow ~= timeLast
and weatherNow == weatherLast
and (common.checkCellDiff(cell, cellLast) == false) then
debugLog("Time changed but weather didn't. Returning.")
updateConditions(true)
return
end
end

windoors = nil
config = mwse.loadConfig("AURA", defaults)
OAvol = config.volumes.modules[moduleName].volume / 100
bigMult = config.volumes.modules[moduleName].big
smaMult = config.volumes.modules[moduleName].sma

-- Exterior cells --
if (cell.isOrBehavesAsExterior and not isOpenPlaza(cell)) then
debugLog(string.format("Found exterior cell. useLast: %s", useLast))
if not useLast then sounds.remove { module = moduleName, volume = OAvol } end
if not useLast then sounds.remove { module = moduleName } end
sounds.play{
module = moduleName,
climate = climateNow,
time = timeNow,
volume = OAvol,
last = useLast,
}
-- Interior cells --
Expand All @@ -209,16 +198,15 @@ local function cellCheck(e)
module = moduleName,
climate = climateNow,
time = timeNow,
volume = 0.2 * OAvol,
volume = smaMult * OAvol,
pitch = 0.85,
last = useLast,
}
else
debugLog("Found big interior cell.")
if not moduleInteriorWeather then updateConditions() return end
windoors = common.getWindoors(cell)
if windoors and not table.empty(windoors) then
debugLog("Found " .. #windoors .. " windoor(s). Playing interior loops.")
if not table.empty(cellData.windoors) then
debugLog("Found " .. #cellData.windoors .. " windoor(s). Playing interior loops.")
playWindoors(useLast)
updateConditions(true)
return
Expand All @@ -236,32 +224,6 @@ local function onConditionChanged(e)
cellCheck(e)
end

-- To check whether we're underwater --
-- This doesn't work with water breathing (no UI element), so eventually will need to be migrated to a new method --
local function positionCheck(e)
local cell = tes3.getPlayerCell()
local element = e.element
debugLog("Player underwater. Stopping AURA sounds.")
if (not cell.isInterior) or (cell.behavesAsExterior) then
sounds.removeImmediate { module = moduleName }
sounds.playImmediate { module = moduleName, last = true, volume = 0.4 * OAvol, pitch = 0.5 }
end
if playSplash and moduleAmbientOutdoor then
tes3.playSound { sound = "splash_lrg", volume = 0.5 * splashVol, pitch = 0.6 }
end
element:registerAfter("destroy", function()
debugLog("Player above water level. Resetting AURA sounds.")
if (not cell.isInterior) or (cell.behavesAsExterior) then
sounds.removeImmediate { module = moduleName }
sounds.playImmediate { module = moduleName, last = true, volume = OAvol }
end
timer.start({ duration = 1, callback = onConditionChanged, type = timer.real })
if playSplash and moduleAmbientOutdoor then
tes3.playSound { sound = "splash_sml", volume = 0.6 * splashVol, pitch = 0.7 }
end
end)
end

-- After waiting/travelling --
local function waitCheck(e)
local element = e.element
Expand All @@ -278,19 +240,17 @@ end
local function runResetter()
climateLast, weatherLast, timeLast = nil, nil, nil
climateNow, weatherNow, timeNow = nil, nil, nil
windoors = {}
end

-- Check for time changes --
local function runHourTimer()
timer.start({ duration = 0.5, callback = cellCheck, iterations = -1, type = timer.game })
end

-- Run hour timer, init windoors, start and pause interiorTimer on loaded --
-- Run hour timer, start and pause interiorTimer on loaded --
local function onLoaded()
runHourTimer()
if moduleInteriorWeather then
windoors = {}
if not interiorTimer then
interiorTimer = timer.start{
duration = 1,
Expand Down Expand Up @@ -323,6 +283,6 @@ event.register("weatherTransitionStarted", transitionStartedWrapper, { priority
event.register("weatherTransitionFinished", onConditionChanged, { priority = -160 })
event.register("weatherTransitionImmediate", onConditionChanged, { priority = -160 })
event.register("weatherChangedImmediate", onConditionChanged, { priority = -160 })
event.register("uiActivated", positionCheck, { filter = "MenuSwimFillBar", priority = -5 })
event.register("AURA:aboveOrUnderwater", onConditionChanged, { priority = -160 })
event.register("uiActivated", waitCheck, { filter = "MenuTimePass", priority = -5 })
debugLog("Outdoor Ambient Sounds module initialised.")
33 changes: 20 additions & 13 deletions 00 Core/MWSE/mods/tew/AURA/Ambient/Populated/populatedMain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local data = require("tew.AURA.Ambient.Populated.populatedData")
local config = require("tew.AURA.config")
local sounds = require("tew.AURA.sounds")
local common = require("tew.AURA.common")
local popVol = config.popVol / 200
local isOpenPlaza = common.isOpenPlaza

local time, timeLast, typeCellLast, weatherNow, weatherLast
Expand Down Expand Up @@ -66,13 +65,13 @@ local function cellCheck()
-- If cell name is nil (different from editorName!) then it's wilderness --
if (not cell) or (not cell.name) then
debugLog("Player in the wilderness. Returning.")
sounds.remove { module = moduleName, volume = popVol }
sounds.remove { module = moduleName }
timeLast = nil
typeCellLast = nil
return
elseif not (cell.isOrBehavesAsExterior and not isOpenPlaza(cell)) then -- Bugger off if we're inside --
debugLog("Player in interior cell. Removing sounds immediately.")
sounds.removeImmediate { module = moduleName, volume = popVol }
sounds.removeImmediate { module = moduleName }
timeLast = nil
typeCellLast = nil
return
Expand All @@ -89,7 +88,7 @@ local function cellCheck()
-- No outside activity in ashstorms and that --
if (weatherNow >= 4 and weatherNow <= 7) or (weatherNow == 8) and weatherNow ~= weatherLast then
debugLog("Bad weather detected. Removing sounds.")
sounds.remove { module = moduleName, volume = popVol }
sounds.remove { module = moduleName }
timeLast = nil
typeCellLast = nil
return
Expand All @@ -110,7 +109,7 @@ local function cellCheck()

-- Otherwise reset and resolve --
debugLog("Different conditions. Removing sounds.")
sounds.remove { module = moduleName, volume = popVol }
sounds.remove { module = moduleName }
timeLast = nil

-- Check if the cell is populated and whether it's night or day --
Expand All @@ -119,14 +118,14 @@ local function cellCheck()
typeCell ~= "dwe" and
time == "night" then
debugLog("Found appropriate cell at night. Playing populated ambient night sound.")
sounds.play { module = moduleName, volume = popVol, type = "night" }
sounds.play { module = moduleName, type = "night" }
timeLast = time
typeCellLast = typeCell
weatherLast = weatherNow
return
elseif time == "day" then
debugLog("Found appropriate cell at day. Playing populated ambient day sound.")
sounds.play { module = moduleName, volume = popVol, type = "day", typeCell = typeCell }
sounds.play { module = moduleName, type = "day", typeCell = typeCell }
timeLast = time
typeCellLast = typeCell
weatherLast = weatherNow
Expand All @@ -147,10 +146,6 @@ local function populatedTimer()
timer.start({ duration = 0.5, callback = cellCheck, iterations = -1, type = timer.game })
end

local function onCOC()
cellCheck()
end

local function runResetter()
time, timeLast, typeCellLast, weatherNow, weatherLast = nil, nil, nil, nil, nil
timer.start {
Expand All @@ -171,10 +166,22 @@ local function waitCheck(e)
end)
end

-- Timer here so that sky textures can work ok --
local function transitionStartedWrapper(e)
timer.start {
duration = 1.5,
type = timer.simulate,
iterations = 1,
callback = cellCheck,
}
end

WtC = tes3.worldController.weatherController
event.register("cellChanged", cellCheck, { priority = -190 })
event.register("weatherTransitionImmediate", onCOC, { priority = -190 })
event.register("weatherChangedImmediate", onCOC, { priority = -190 })
event.register("weatherTransitionStarted", transitionStartedWrapper, { priority = -190 })
event.register("weatherTransitionFinished", cellCheck, { priority = -190 })
event.register("weatherChangedImmediate", cellCheck, { priority = -190 })
event.register("AURA:aboveOrUnderwater", cellCheck, { priority = -190 })
event.register("loaded", populatedTimer)
event.register("load", runResetter)
event.register("uiActivated", waitCheck, { filter = "MenuTimePass", priority = -5 })
Expand Down
4 changes: 2 additions & 2 deletions 00 Core/MWSE/mods/tew/AURA/Containers/containersMain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local function playOpenSound(e)
if not (e.target.object.objectType == tes3.objectType.container) or (e.target.object.objectType == tes3.objectType.npc) then return end

if not tes3.getLocked({ reference = e.target }) then
local Cvol = config.Cvol / 200
local Cvol = config.volumes.misc.Cvol / 100
local data = getContainerData(e.target.object.id:lower(), "open")
local sound = data.sound
local volume = (data.volume or 0.8) * Cvol
Expand All @@ -68,7 +68,7 @@ local function playCloseSound(e)
if not (e.reference.object.objectType == tes3.objectType.container) or (e.reference.object.objectType == tes3.objectType.npc) then return end
if flag == 1 then return end

local Cvol = config.Cvol / 200
local Cvol = config.volumes.misc.Cvol / 100
local data = getContainerData(e.reference.object.id:lower(), "close")
local sound = data.sound
local volume = (data.volume or 0.8) * Cvol
Expand Down
Loading

0 comments on commit dc577e7

Please sign in to comment.
  翻译: