-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction_util.lua
More file actions
67 lines (58 loc) · 2.24 KB
/
action_util.lua
File metadata and controls
67 lines (58 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require('scripts/globals/interaction/actions/event')
require('scripts/globals/interaction/actions/message')
require('scripts/globals/interaction/actions/sequence')
actionUtil = actionUtil or {}
-- Parses out short-hand ways of writing quest actions, in order to avoid having to make function declarations for each simple interaction.
-- Some examples of things it can parse, and what the corresponding actions are:
--
-- Event examples:
-- { event = 123 } == quest:event(123)
-- { event = 123, progress = true } == quest:progressEvent(123)
-- { cutscene = 123 } == quest:cutscene(123)
-- { event = 123, options = { [2] = 555 } } == quest:event(123, { [2] = 555 })
--
-- Message examples:
-- { text = 456 } == quest:message(456)
-- { message = 456 } == quest:message(456)
--
-- Sequence example:
-- { { text = 11470, wait = 1000 }, { text = 11471, face = 82, wait = 2000 }, { face = 115 } }
function actionUtil.parseActionDef(actionDef)
if not actionDef or type(actionDef) ~= 'table' or actionDef.onTrigger or actionDef.onTrade then
return nil
end
-- Action definition is a fully fledged action
if actionDef.type then
return actionDef
end
-- Event or cutscene
local info = actionDef.event or actionDef.cutscene
if info then
local event = Event:new(info, actionDef.options)
if actionDef.cutscene then
event = event:cutscene()
end
if actionDef.progress then
event = event:progress()
end
return event
end
-- Message
info = actionDef.text or actionDef.message
if info then
local message = Message:new(info)
return message
end
if #actionDef > 0 and type(actionDef[1]) == "table" then
local sequence = Sequence:new(actionDef)
if sequence then
return sequence
end
end
end
-- Returns a string containing identification for a specific action
function actionUtil.getActionVarName(secondLevelKey, thirdLevelKey, suffix)
suffix = suffix or ""
return string.format("[Action][%s][%s]%s", secondLevelKey, thirdLevelKey, suffix)
end
return actionUtil