Lua works; narrator works

This commit is contained in:
2025-09-17 18:08:26 +03:00
parent 1977a12d8b
commit cfd9ed8708
24 changed files with 4557 additions and 100 deletions

View File

@@ -36,6 +36,7 @@ function foo()
end
v = Vector3(0, 1, 2)
end
--[[
narration = {
position = 1,
narration_start = {
@@ -59,15 +60,74 @@ dropped you into the sea. Last thing you heard before you hit the water was happ
return ret
end,
}
]]--
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 = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(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, ' #')
end
ret = ret .. text
end
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
end
end
if (#choices > 0) then
print("choices!!!")
narrate(ret, choices)
else
narrate(ret)
end
end
setup_handler(function(event)
print(event)
if event == "startup" then
main_menu()
elseif event == "narration_progress" then
narrate(narration:progress())
_narration()
elseif event == "narration_answered" then
local answer = narration_get_answer()
story:choose(answer)
_narration()
elseif event == "new_game" then
narrate(narration:progress())
local ret = ""
story = narrator.init_story(book)
story:begin()
_narration()
end
end)