Started working on dialogue
This commit is contained in:
@@ -62,6 +62,7 @@ dropped you into the sea. Last thing you heard before you hit the water was happ
|
||||
}
|
||||
]]--
|
||||
local narrator = require('narrator.narrator')
|
||||
local json = require('json.json')
|
||||
|
||||
function dump(o)
|
||||
if type(o) == 'table' then
|
||||
@@ -657,26 +658,90 @@ setup_handler(function(event, trigger_entity, what_entity)
|
||||
end)
|
||||
|
||||
setup_action_handler("talk", {
|
||||
count = 0,
|
||||
activate = function(this)
|
||||
this._narration("Booo!! Lua...", {"One", "Two", "Three"})
|
||||
local book = narrator.parse_file('stories.talk')
|
||||
this.story = narrator.init_story(book)
|
||||
local crash_bind = function()
|
||||
crash()
|
||||
end
|
||||
this.story:bind('crash', crash_bind)
|
||||
this.story:begin()
|
||||
this:narration_update()
|
||||
local props = this._get_properties()
|
||||
print(props)
|
||||
local json_data = json.decode(props)
|
||||
print(dump(json_data))
|
||||
crash()
|
||||
end,
|
||||
event = function(this, event)
|
||||
this.count = this.count + 1
|
||||
if event == "narration_progress" then
|
||||
this.count = this.count + 1
|
||||
this._narration("Booo!!!", {})
|
||||
this:narration_update()
|
||||
end
|
||||
if event == "narration_answered" then
|
||||
this.count = this.count + 1
|
||||
this._narration("Booo!!!_", {})
|
||||
end
|
||||
if this.count > 10 then
|
||||
this._finish()
|
||||
local answer = this._get_narration_answer()
|
||||
this.story:choose(answer)
|
||||
this:narration_update()
|
||||
end
|
||||
end,
|
||||
finish = function(this)
|
||||
this.count = 0
|
||||
end,
|
||||
narration_update = function(this)
|
||||
local ret = ""
|
||||
local choices = {}
|
||||
local have_choice = false
|
||||
local have_paragraph = false
|
||||
print("narration_update")
|
||||
if this.story:can_continue() then
|
||||
print("CAN continue")
|
||||
have_paragraph = true
|
||||
local paragraph = this.story:continue(1)
|
||||
print(dump(paragraph))
|
||||
local text = paragraph.text
|
||||
if paragraph.tags then
|
||||
-- text = text .. ' #' .. table.concat(paragraph.tags, ' #')
|
||||
for i, tag in ipairs(paragraph.tags) do
|
||||
if tag == 'discard' then
|
||||
text = ''
|
||||
elseif tag == 'crash' then
|
||||
print(text)
|
||||
crash()
|
||||
end
|
||||
this:handle_tag(tag)
|
||||
end
|
||||
end
|
||||
ret = text
|
||||
if this.story:can_choose() then
|
||||
have_choice = true
|
||||
local ch = this.story:get_choices()
|
||||
for i, choice in ipairs(ch) do
|
||||
table.insert(choices, choice.text)
|
||||
print(i, dump(choice))
|
||||
end
|
||||
if #choices == 1 and choices[1] == "Ascend" then
|
||||
this.story:choose(1)
|
||||
choices = {}
|
||||
end
|
||||
if #choices == 1 and choices[1] == "Continue" then
|
||||
this.story:choose(1)
|
||||
choices = {}
|
||||
end
|
||||
end
|
||||
else
|
||||
print("can NOT continue")
|
||||
end
|
||||
print(ret)
|
||||
if (#choices > 0) then
|
||||
print("choices!!!")
|
||||
this._narration(ret, choices)
|
||||
else
|
||||
this._narration(ret, {})
|
||||
end
|
||||
if not have_choice and not have_paragraph then
|
||||
this._finish()
|
||||
end
|
||||
end,
|
||||
handle_tag = function(this, tag)
|
||||
print("tag: " .. tag)
|
||||
end,
|
||||
})
|
||||
--[[
|
||||
|
||||
Reference in New Issue
Block a user