2022-03-07 20:28:05 +00:00
|
|
|
local common = require('scripts.omw.settings.common')
|
|
|
|
local register = require('scripts.omw.settings.register')
|
2022-04-18 06:42:02 +00:00
|
|
|
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,
|
2022-04-18 06:42:02 +00:00
|
|
|
group = common.group,
|
2022-03-07 20:28:05 +00:00
|
|
|
registerGroup = register.registerGroup,
|
|
|
|
},
|
|
|
|
engineHandlers = {
|
|
|
|
onLoad = function(saved)
|
2022-04-18 06:42:02 +00:00
|
|
|
common.groups():reset()
|
|
|
|
common.loadScope(common.SCOPE.SaveGlobal, saved)
|
2022-03-07 20:28:05 +00:00
|
|
|
end,
|
|
|
|
onSave = function()
|
2022-04-18 06:42:02 +00:00
|
|
|
common.saveScope(common.SCOPE.SaveGlobal)
|
2022-03-07 20:28:05 +00:00
|
|
|
end,
|
|
|
|
onPlayerAdded = register.onPlayerAdded,
|
|
|
|
},
|
|
|
|
eventHandlers = {
|
2022-04-18 06:42:02 +00:00
|
|
|
[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,
|
2022-04-18 06:42:02 +00:00
|
|
|
[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,
|
2022-04-18 06:42:02 +00:00
|
|
|
[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
|
|
|
}
|