Archaeology feature

This commit is contained in:
Pyrex 2024-02-11 17:28:41 -08:00
parent 21d0ed432d
commit 4a61d8afd3
5 changed files with 99 additions and 6 deletions

View File

@ -17,6 +17,25 @@ end
function completion_tracker:advance_completion_level(clevel) function completion_tracker:advance_completion_level(clevel)
dset(0,max(dget(0), clevel)) dset(0,max(dget(0), clevel))
end end
-- TODO: Bitfield instead
function completion_tracker:mark_seen(text_id)
local ix,bit=self:_unpack_text_id(text_id)
dset(ix,dget(ix)|bit)
end
function completion_tracker:was_seen(text_id)
local ix,bit=self:_unpack_text_id(text_id)
return dget(ix)&bit !=0
end
function completion_tracker:_unpack_text_id(text_id)
assert(text_id>0)
assert(text_id<120) -- max 120 texts for now
-- using bytes 1 through 15
local ix,bit=1+text_id\8,text_id%8
assert(ix<16)
return ix,1<<bit
end
function completion_tracker:should_show_tutorial() function completion_tracker:should_show_tutorial()
return self:get_completion_level() < tutorial.completion_stage return self:get_completion_level() < tutorial.completion_stage

View File

@ -1,9 +1,7 @@
liturgy={ liturgy={
holy_book=gsv[[ holy_book=gsv[[rood 1`1,2
rood 1`1,2
rood 2`3,4,5,6 rood 2`3,4,5,6
rood 3`7,8,9,10 rood 3`7,8,9,10]],
]],
sacred_text_lines=gsv sacred_text_lines=gsv
[[1`come into this thicket. [[1`come into this thicket.
1`i, o man, have a bright wreath. 1`i, o man, have a bright wreath.
@ -76,5 +74,5 @@ function liturgy:suggest_verse(ruleset,card)
local meta=ruleset.deck.cards[card] local meta=ruleset.deck.cards[card]
local i=2+meta.rank local i=2+meta.rank
if (meta.suit!="a") i=ruleset.preferred_verse or i if (meta.suit!="a") i=ruleset.preferred_verse or i
return unpack(liturgy.annotated_verses[i]) return i, unpack(liturgy.annotated_verses[i])
end end

View File

@ -19,6 +19,7 @@ __lua__
#include progression.lua #include progression.lua
#include seed_constants.lua #include seed_constants.lua
#include seeds.lua #include seeds.lua
#include state_archaeology.lua
#include state_excavate_menu.lua #include state_excavate_menu.lua
#include state_manager.lua #include state_manager.lua
#include state_menu.lua #include state_menu.lua

74
state_archaeology.lua Normal file
View File

@ -0,0 +1,74 @@
state_archaeology=klass()
function state_archaeology:init()
self.n_holy_books=#liturgy.holy_book
self:select_book(1)
end
function state_archaeology:enter() end
function state_archaeology:exit(new_top) end
function state_archaeology:reenter() end
function state_archaeology:suspend() end
function state_archaeology:select_book(n)
self.selection=n
local lines={}
local hb=liturgy.holy_book[self.selection]
self.title=hb[1]
printh()
for source in all(split(hb[2])) do
for line in all(liturgy.sacred_text_lines) do
if (line[1]==source) add(lines,self:_censor(source,line[2]))
end
end
self.full_text=""
for i=1,#lines do
if (i>1) self.full_text..="\n"
self.full_text..=lines[i]
end
end
function state_archaeology:_censor(src,line)
if (completion_tracker:was_seen(src)) return line
local line2=""
for i=1,#line do
local c=sub(line,i,i)
if ("a"<=c and c<="z") c="?"
line2..=c
end
return "\f6"..line2.."\ff"
end
function state_archaeology:update()
local vel=0
if (btnp(0)) vel-=1
if (btnp(1)) vel+=1
if (btnp(5)) self.done=true
if (vel!=0) self:select_book((self.selection+vel-1)%self.n_holy_books+1)
end
function state_archaeology:draw()
local fullw,fullh=measure_text(self.full_text)
local total_height=fullh+16
cls(13)
local y=64-total_height\2
local tw=measure_text(self.title)-1
local x=64-tw\2
local tx=x
print(self.title,x,y,15)
y+=6
line(x,y,x+tw-1,y,15)
y+=3
local x=64-fullw\2
rectfill(x-1,y-1,x+fullw,y+fullh-1,4)
print(self.full_text,x,y,15)
y+=fullh+1
line(tx,y,tx+tw-1,y,15)
y+=2
print("⬅️",tx,y)
print("➡️",tx+tw-7,y)
print("❎ go back",1,122,15)
end

View File

@ -5,9 +5,10 @@ function state_wonround:init(board)
self.frames=30 self.frames=30
self.progress=0.0 self.progress=0.0
self.card=self.board:get_endgame_card() self.card=self.board:get_endgame_card()
self.verse_name,self.verse=liturgy:suggest_verse(self.board.ruleset,self.card) self.verse_id,self.verse_name,self.verse=liturgy:suggest_verse(self.board.ruleset,self.card)
end end
function state_wonround:enter() function state_wonround:enter()
completion_tracker:mark_seen(self.verse_id)
completion_tracker:advance_completion_level(self.board:get_completion_level()) completion_tracker:advance_completion_level(self.board:get_completion_level())
end end
function state_wonround:exit(new_top) end function state_wonround:exit(new_top) end