-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialogues.lua2p
40 lines (34 loc) · 1.04 KB
/
dialogues.lua2p
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
local Dialogues = {}
local DialoguesList = require("data.dialogues")
function Dialogues.get(main, sub)
@@assert(#main ~= 0 and type(main) == "string")
@@assert(#sub ~= 0 and type(sub) == "string")
@@assert(DialoguesList[main], "there is no " .. main .. " in dialogue table")
@@assert(DialoguesList[main][sub], "there is no " .. sub .. " in dialogue table")
return tablex.copy(DialoguesList[main][sub])
end
function Dialogues.check_signal(str)
@@assert(type(str) == "string")
local bool = stringx.starts_with(str, "_")
if not bool then
return false, "", true
end
local handle_self = not stringx.starts_with(str, "__")
local signal
if handle_self then
signal = str:sub(2, #str)
else
signal = str:sub(3, #str)
end
return bool, signal, handle_self
end
function Dialogues.validate(dialogue_t)
@@assert(type(dialogue_t) == "table")
if #dialogue_t == 0 then return true end
local bool = Dialogues.check_signal(dialogue_t[1])
if bool and #dialogue_t == 1 and dialogue_t.choices == nil then
return false
end
return true
end
return Dialogues