Vendor libs/hump, sfxrlua, json4lua, narrator as real files
These were committed as empty submodule gitlinks with no .gitmodules, so the folders were never populated and the game could not load (require of libs/hump/timer, libs/sfxrlua/sfxr, narrator.narrator). Checked out each at its pinned commit and vendored the files, matching the existing bundled-libs convention. Removed the junk libs/libs/ tree. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
e73f63b5d4
commit
03532d29e4
219 changed files with 20254 additions and 252 deletions
63
libs/narrator/bot.lua
Normal file
63
libs/narrator/bot.lua
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
--
|
||||
-- Bot for story playing
|
||||
|
||||
local bot = { }
|
||||
|
||||
--- Play a story by bot
|
||||
-- @param story Story: a story instance
|
||||
-- @param instructor function: function that will be return the answer index
|
||||
-- @param params.print boolean: print a game log to console or not, false by default
|
||||
-- @return string: a log of the game
|
||||
function bot.play(story, instructor, params)
|
||||
local params = params or { print = false }
|
||||
|
||||
local log = { }
|
||||
local step = 1
|
||||
|
||||
local function output(text)
|
||||
if params.print then print(text) end
|
||||
table.insert(log, text)
|
||||
end
|
||||
|
||||
story:begin()
|
||||
|
||||
while story:can_continue() or story:can_choose() do
|
||||
local paragraphs = story:continue()
|
||||
for _, paragraph in ipairs(paragraphs or { }) do
|
||||
local text = paragraph.text or ''
|
||||
if paragraph.tags then
|
||||
local hashtag = #text > 0 and ' #' or '#'
|
||||
text = text .. hashtag .. table.concat(paragraph.tags, ' #')
|
||||
end
|
||||
output(text)
|
||||
end
|
||||
|
||||
if not story:can_choose() then break end
|
||||
|
||||
local choices = story:get_choices()
|
||||
local answer = instructor(choices, step)
|
||||
step = step + 1
|
||||
|
||||
-- Check for a signal to emergency exit
|
||||
if answer == -1 then
|
||||
return nil
|
||||
end
|
||||
|
||||
output('')
|
||||
for i, choice in ipairs(choices) do
|
||||
local prefix = (i == answer and '>' or i) .. ') '
|
||||
local text = prefix .. choice.text
|
||||
if choice.tags then
|
||||
text = text .. ' #' .. table.concat(choice.tags, ' #')
|
||||
end
|
||||
output(text)
|
||||
end
|
||||
output('')
|
||||
|
||||
story:choose(answer)
|
||||
end
|
||||
|
||||
return table.concat(log, '\n')
|
||||
end
|
||||
|
||||
return bot
|
||||
Loading…
Add table
Add a link
Reference in a new issue