1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-08 09:37:53 +00:00
OpenMW/files/builtin_scripts/scripts/omw/settings/global.lua

44 lines
1.6 KiB
Lua
Raw Normal View History

2022-03-07 20:28:05 +00:00
local common = require('scripts.omw.settings.common')
local register = require('scripts.omw.settings.register')
local world = require('openmw.world')
local types = require('openmw.types')
2022-03-07 20:28:05 +00:00
return {
interfaceName = 'Settings',
interface = {
SCOPE = common.SCOPE,
group = common.group,
2022-03-07 20:28:05 +00:00
registerGroup = register.registerGroup,
},
engineHandlers = {
onLoad = function(saved)
common.groups():reset()
common.loadScope(common.SCOPE.SaveGlobal, saved)
2022-03-07 20:28:05 +00:00
end,
onSave = function()
common.saveScope(common.SCOPE.SaveGlobal)
2022-03-07 20:28:05 +00:00
end,
onPlayerAdded = register.onPlayerAdded,
},
eventHandlers = {
[common.EVENTS.SetValue] = function(event)
local group = common.group(event.groupKey)
group[event.settingKey] = event.value
2022-03-07 20:28:05 +00:00
end,
[common.EVENTS.RegisterGroup] = function(options)
if common.groups():get(options.key) then return end
register.registerGroup(options)
2022-03-07 20:28:05 +00:00
end,
[common.EVENTS.SettingChanged] = function(event)
local setting = common.groups():get(event.groupKey).settings[event.settingKey]
if common.isPlayerScope(setting.scope) then
for _, a in ipairs(world.activeActors) do
if a.type == types.Player and a:isValid() then
a:sendEvent(common.EVENTS.SettingChanged, event)
end
end
end
end,
[common.EVENTS.Subscribe] = common.handleSubscription,
},
2022-03-07 20:28:05 +00:00
}