Lots of updates - lua, narrator, logic, models
This commit is contained in:
@@ -63,15 +63,6 @@ dropped you into the sea. Last thing you heard before you hit the water was happ
|
||||
]]--
|
||||
local narrator = require('narrator.narrator')
|
||||
|
||||
-- Parse a book from the Ink file.
|
||||
local book = narrator.parse_file('stories.game')
|
||||
|
||||
-- Init a story from the book
|
||||
local story = narrator.init_story(book)
|
||||
|
||||
-- Begin the story
|
||||
story:begin()
|
||||
|
||||
function dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
@@ -85,26 +76,45 @@ function dump(o)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
function _narration()
|
||||
local ret = ""
|
||||
local choices = {}
|
||||
if story:can_continue() then
|
||||
local paragraphs = story:continue()
|
||||
for _, paragraph in ipairs(paragraphs) do
|
||||
local text = paragraph.text
|
||||
if paragraph.tags then
|
||||
text = text .. ' #' .. table.concat(paragraph.tags, ' #')
|
||||
print("can continue")
|
||||
local paragraph = 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 == "mc_is_free" then
|
||||
ecs_character_set("player", "gravity", true)
|
||||
ecs_character_set("player", "buoyancy", true)
|
||||
end
|
||||
end
|
||||
ret = ret .. text
|
||||
end
|
||||
ret = text
|
||||
if story:can_choose() then
|
||||
local ch = 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
|
||||
story:choose(1)
|
||||
choices = {}
|
||||
end
|
||||
if #choices == 1 and choices[1] == "Continue" then
|
||||
story:choose(1)
|
||||
choices = {}
|
||||
end
|
||||
end
|
||||
else
|
||||
print("can NOT continue")
|
||||
end
|
||||
print(ret)
|
||||
if (#choices > 0) then
|
||||
print("choices!!!")
|
||||
narrate(ret, choices)
|
||||
@@ -112,9 +122,134 @@ function _narration()
|
||||
narrate(ret)
|
||||
end
|
||||
end
|
||||
]]--
|
||||
function Quest(name, book)
|
||||
local quest = {
|
||||
name = name,
|
||||
active = false,
|
||||
activate = function(this)
|
||||
this.active = true
|
||||
this.story:begin()
|
||||
this:_narration()
|
||||
end,
|
||||
event = function(this, event)
|
||||
if not this.active then
|
||||
return
|
||||
end
|
||||
if event == "narration_progress" then
|
||||
this:_narration()
|
||||
elseif event == "narration_answered" then
|
||||
local answer = narration_get_answer()
|
||||
this.story:choose(answer)
|
||||
print("answered:", answer)
|
||||
this:_narration()
|
||||
end
|
||||
end,
|
||||
_handle_tag = function(this, tag)
|
||||
if tag == "mc_is_free" then
|
||||
ecs_character_set("player", "gravity", true)
|
||||
ecs_character_set("player", "buoyancy", true)
|
||||
end
|
||||
end,
|
||||
_narration = function(this)
|
||||
local ret = ""
|
||||
local choices = {}
|
||||
local have_choice = false
|
||||
local have_paragraph = false
|
||||
if not this.active then
|
||||
return
|
||||
end
|
||||
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
|
||||
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
|
||||
if not have_choice and not have_paragraph then
|
||||
this:complete()
|
||||
this.active = false
|
||||
end
|
||||
print(ret)
|
||||
if (#choices > 0) then
|
||||
print("choices!!!")
|
||||
narrate(ret, choices)
|
||||
else
|
||||
narrate(ret)
|
||||
end
|
||||
end,
|
||||
complete = function(this)
|
||||
print(this.name .. 'complete')
|
||||
end,
|
||||
story = narrator.init_story(book)
|
||||
}
|
||||
|
||||
-- Begin the story
|
||||
|
||||
return quest
|
||||
end
|
||||
function StartGameQuest()
|
||||
-- Parse a book from the Ink file.
|
||||
local book = narrator.parse_file('stories.initiation')
|
||||
local quest = Quest('start game', book)
|
||||
quest.base = {}
|
||||
quest.base.activate = quest.activate
|
||||
quest.base.complete = quest.complete
|
||||
quest.boat = false
|
||||
quest.activate = function(this)
|
||||
print('activate...')
|
||||
local mc_is_free = function()
|
||||
ecs_character_params_set("player", "gravity", true)
|
||||
ecs_character_params_set("player", "buoyancy", true)
|
||||
end
|
||||
this.story:bind('mc_is_free', mc_is_free)
|
||||
this.base.activate(this)
|
||||
end
|
||||
quest.complete = function(this)
|
||||
this.base.complete(this)
|
||||
this.active = false
|
||||
if not this.boat then
|
||||
local boat = ecs_vehicle_set("boat", 0, 0, -20, 1.75)
|
||||
local trigger = ecs_child_character_trigger(boat, "entered_boat", 0, 0, 0, 3, 3)
|
||||
local npc = ecs_npc_set("normal-female.glb", 0, 2, -20, 1.75)
|
||||
this.boat = true
|
||||
end
|
||||
end
|
||||
return quest
|
||||
end
|
||||
quests = {}
|
||||
setup_handler(function(event)
|
||||
print(event)
|
||||
for k, v in pairs(quests) do
|
||||
if v.active then
|
||||
v:event(event)
|
||||
end
|
||||
end
|
||||
if event == "startup" then
|
||||
main_menu()
|
||||
elseif event == "narration_progress" then
|
||||
@@ -122,12 +257,16 @@ setup_handler(function(event)
|
||||
elseif event == "narration_answered" then
|
||||
local answer = narration_get_answer()
|
||||
story:choose(answer)
|
||||
print("answered:", answer)
|
||||
_narration()
|
||||
elseif event == "new_game" then
|
||||
local ret = ""
|
||||
story = narrator.init_story(book)
|
||||
story:begin()
|
||||
_narration()
|
||||
ecs_character_params_set("player", "gravity", true)
|
||||
ecs_character_params_set("player", "buoyancy", false)
|
||||
local quest = StartGameQuest()
|
||||
quests[quest.name] = quest
|
||||
for k, v in pairs(quests) do
|
||||
print(k, v.active)
|
||||
end
|
||||
quest:activate()
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user