mirror of https://github.com/OpenMW/openmw.git
Merge branch 'activation' into 'master'
Allow Lua scripts to extend or override standard activation mechanics See merge request OpenMW/openmw!29357344-support-launching-the-example-suite
commit
2a6e301925
@ -0,0 +1,6 @@
|
||||
Interface Activation
|
||||
====================
|
||||
|
||||
.. raw:: html
|
||||
:file: generated_html/scripts_omw_activationhandlers.html
|
||||
|
@ -1,9 +1,17 @@
|
||||
# UI framework
|
||||
PLAYER: scripts/omw/mwui/init.lua
|
||||
|
||||
# Settings framework
|
||||
GLOBAL: scripts/omw/settings/global.lua
|
||||
PLAYER: scripts/omw/settings/player.lua
|
||||
|
||||
# Mechanics
|
||||
GLOBAL: scripts/omw/activationhandlers.lua
|
||||
PLAYER: scripts/omw/playercontrols.lua
|
||||
PLAYER: scripts/omw/camera/camera.lua
|
||||
NPC,CREATURE: scripts/omw/ai.lua
|
||||
|
||||
# Lua console
|
||||
PLAYER: scripts/omw/console/player.lua
|
||||
GLOBAL: scripts/omw/console/global.lua
|
||||
CUSTOM: scripts/omw/console/local.lua
|
||||
|
@ -0,0 +1,68 @@
|
||||
local types = require('openmw.types')
|
||||
local world = require('openmw.world')
|
||||
|
||||
local handlersPerObject = {}
|
||||
local handlersPerType = {}
|
||||
|
||||
local function onActivate(obj, actor)
|
||||
local handlers = handlersPerObject[obj.id]
|
||||
if handlers then
|
||||
for i = #handlers, 1, -1 do
|
||||
if handlers[i](obj, actor) == false then
|
||||
return -- skip other handlers
|
||||
end
|
||||
end
|
||||
end
|
||||
handlers = handlersPerType[obj.type]
|
||||
if handlers then
|
||||
for i = #handlers, 1, -1 do
|
||||
if handlers[i](obj, actor) == false then
|
||||
return -- skip other handlers
|
||||
end
|
||||
end
|
||||
end
|
||||
world._runStandardActivationAction(obj, actor)
|
||||
end
|
||||
|
||||
return {
|
||||
interfaceName = 'Activation',
|
||||
---
|
||||
-- @module Activation
|
||||
-- @usage require('openmw.interfaces').Activation
|
||||
interface = {
|
||||
--- Interface version
|
||||
-- @field [parent=#Activation] #number version
|
||||
version = 0,
|
||||
|
||||
--- Add new activation handler for a specific object.
|
||||
-- If `handler(object, actor)` returns false, other handlers for
|
||||
-- the same object (including type handlers) will be skipped.
|
||||
-- @function [parent=#Activation] addHandlerForObject
|
||||
-- @param openmw.core#GameObject obj The object.
|
||||
-- @param #function handler The handler.
|
||||
addHandlerForObject = function(obj, handler)
|
||||
local handlers = handlersPerObject[obj.id]
|
||||
if handlers == nil then
|
||||
handlers = {}
|
||||
handlersPerObject[obj.id] = handlers
|
||||
end
|
||||
handlers[#handlers + 1] = handler
|
||||
end,
|
||||
|
||||
--- Add new activation handler for a type of objects.
|
||||
-- If `handler(object, actor)` returns false, other handlers for
|
||||
-- the same object (including type handlers) will be skipped.
|
||||
-- @function [parent=#Activation] addHandlerForType
|
||||
-- @param #userdata type A type from the `openmw.types` package.
|
||||
-- @param #function handler The handler.
|
||||
addHandlerForType = function(type, handler)
|
||||
local handlers = handlersPerType[type]
|
||||
if handlers == nil then
|
||||
handlers = {}
|
||||
handlersPerType[type] = handlers
|
||||
end
|
||||
handlers[#handlers + 1] = handler
|
||||
end,
|
||||
},
|
||||
engineHandlers = { onActivate = onActivate },
|
||||
}
|
Loading…
Reference in New Issue