your-own-drum/text.lua

72 lines
1.6 KiB
Lua

--Load poems.
local love = love
local feet = {}
local feetNL = {}
local words = {} --Sequence of tables.
local poem = {[0] = ""}
local poemLines = {[0] = 0}
local mt = { __index = function() return "linja" end }
local s = love.filesystem.read( "text/tok.txt" )
local smallFont = love.graphics.setNewFont( "text/linja-sike.ttf", 12 )
local largeFont = love.graphics.setNewFont( "text/linja-sike.ttf", 32 )
local i = 1
--Split string into feet.
for foot in s:gmatch( ".-%-") do
feet[i] = foot:gsub( "-", "" ):gsub( " $", "" ):gsub( "%c", "") --Remove hyphens, trailing spaces, newlines.
feetNL[i] = foot:gsub( "-", "" ):gsub(" ", "")--:gsub( "%.", " " ) --Remove hyphens, spaces, transform periods to spaces
poem[i] = poem[ i - 1 ]..feetNL[i]
poemLines[i] = poemLines[i - 1] + (feetNL[i]:match( "\n") and 1 or 0)
i = i + 1
end
--Split string into words.
i = 1
local isTe = true
for foot in s:gmatch( ".-%-" ) do
--Split foot into words.
local word = {}
local j = 1
for w in foot:gmatch( [["]] ) do
word[j] = isTe and "te" or "to"
isTe = not( isTe )
j = j + 1
end
for w in foot:gmatch( "%a+" ) do
word[j] = w
j = j + 1
end
words[i] = word
i = i + 1
end
local function Draw( beat )
local foot = feet[ beat ]
love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
love.graphics.printf(
foot,
0, (9/10) * love.graphics.getHeight(),
love.graphics.getWidth(),
"center")
love.graphics.setColor(1.0, 1.0, 1.0, 0.5)
love.graphics.print( poem[beat], 0, (3 - poemLines[beat]) * 32 )
end
local Reset = function() end
return { feet = feet, words = words, feetNL = feetNL, Reset = Reset, Draw = Draw }