starting to add data
This commit is contained in:
1 parent
a67e04ba4c
commit
97b9205954
7 files changed
+279
-16
No files matched your search
@@ -0,0 +1,32 @@
|
||||
local constants = require "data.constants"
|
||||
local utility = require "lib.utility"
|
||||
|
||||
local classes = utility.load_data("classes.json")
|
||||
|
||||
-- TODO abstract out since this is shared between classes and races
|
||||
for name, data in pairs(classes) do
|
||||
if type(data.tasks) == "string" then
|
||||
data.tasks = { data.tasks }
|
||||
elseif not data.tasks then
|
||||
data.tasks = {}
|
||||
end
|
||||
|
||||
local tasks = data.tasks
|
||||
for index, task in ipairs(tasks) do
|
||||
if type(task) == "string" then
|
||||
local time = #task * constants.reading_time_multiplier
|
||||
-- TODO decide on a random amount of extra time to add
|
||||
tasks[index] = {time, time, task}
|
||||
if #task == 1 then
|
||||
local time = #task[1] * constants.reading_time_multiplier
|
||||
-- TODO decide on a random amount of extra time to add
|
||||
tasks[index] = {time, time, task[1]}
|
||||
elseif #task == 2 then
|
||||
local time = tasks[1]
|
||||
-- TODO decide on a random amount of extra time to add
|
||||
tasks[index] = {time, time, task[2]}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return classes
|
||||
@@ -0,0 +1,4 @@
|
||||
return {
|
||||
progress_bar_height = 30,
|
||||
reading_time_multiplier = 1 / 12,
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
local constants = require "data.constants"
|
||||
local utility = require "lib.utility"
|
||||
|
||||
local races = utility.load_data("races.json")
|
||||
|
||||
-- TODO abstract out since this is shared between classes and races
|
||||
for name, data in pairs(races) do
|
||||
if type(data.tasks) == "string" then
|
||||
data.tasks = { data.tasks }
|
||||
elseif not data.tasks then
|
||||
data.tasks = {}
|
||||
end
|
||||
|
||||
local tasks = data.tasks
|
||||
for index, task in ipairs(tasks) do
|
||||
if type(task) == "string" then
|
||||
local time = #task * constants.reading_time_multiplier
|
||||
-- TODO decide on a random amount of extra time to add
|
||||
tasks[index] = {time, time, task}
|
||||
if #task == 1 then
|
||||
local time = #task[1] * constants.reading_time_multiplier
|
||||
-- TODO decide on a random amount of extra time to add
|
||||
tasks[index] = {time, time, task[1]}
|
||||
elseif #task == 2 then
|
||||
local time = tasks[1]
|
||||
-- TODO decide on a random amount of extra time to add
|
||||
tasks[index] = {time, time, task[2]}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return races
|
||||
+20
-16
@@ -10,20 +10,20 @@ log{
|
||||
testing = true,
|
||||
}
|
||||
|
||||
-- local json_load_test = utility.load_data("test.json")
|
||||
-- utility.print_table(json_load_test)
|
||||
local constants = requrie "data.constants"
|
||||
local classes = require "data.classes"
|
||||
local races = require "data.races"
|
||||
|
||||
-- test progress_bar
|
||||
local window_width, window_height = love.graphics.getDimensions()
|
||||
local progress_bar_height = 30 -- TODO should not be hardcoded
|
||||
local test_bar = progress_bar(0, window_height - progress_bar_height * 2, window_width, progress_bar_height)
|
||||
local test_bar = progress_bar(0, window_height - constants.progress_bar_height * 2, window_width, constants.progress_bar_height)
|
||||
|
||||
local test_message = "This is a test text string of significant length. It exists to test printing over a progress bar."
|
||||
log("testing", #test_message)
|
||||
test_bar:set_text(test_message)
|
||||
-- test:set_progress(math.random())
|
||||
|
||||
local test_timer = timer.every(#test_message / 12, function() log("testing", "The timer completed.") end) -- TODO consider making timer not need a function; cause I don't here!
|
||||
local test_timer = timer.every(#test_message * constants.reading_time_multiplier, function() log("testing", "The timer completed.") end) -- TODO consider making timer not need a function; cause I don't here!
|
||||
|
||||
local task_queue
|
||||
task_queue = {
|
||||
@@ -32,34 +32,38 @@ task_queue = {
|
||||
end,
|
||||
}
|
||||
|
||||
local total_pages = 500
|
||||
local current_page = 0
|
||||
local pages_progress_bar = progress_bar(0, window_height - progress_bar_height, window_width, progress_bar_height, total_pages / current_page)
|
||||
local update_pages_progress_bar = function(increment)
|
||||
current_page = current_page + (increment or 0)
|
||||
pages_progress_bar:set_progress(current_page / total_pages)
|
||||
pages_progress_bar:set_text("Reading: Page " .. current_page .. "/" .. total_pages .. " (" .. math.floor(current_page / total_pages * 100 * 10) / 10 .. "%)")
|
||||
|
||||
|
||||
local book = utility.load_data("book.json")
|
||||
local book_progress = progress_bar(0, window_height - constants.progress_bar_height, window_width, constants.progress_bar_height)
|
||||
local update_book_progress = function(increment)
|
||||
book.current_page = book.current_page + (increment or 0)
|
||||
book_progress:set_progress(book.current_page / book.total_pages)
|
||||
book_progress:set_text("Reading: Page " .. book.current_page .. "/" .. book.total_pages .. " (" .. math.floor(book.current_page / book.total_pages * 100 * 10) / 10 .. "%)")
|
||||
end
|
||||
update_pages_progress_bar()
|
||||
update_book_progress()
|
||||
|
||||
love.update = function(dt)
|
||||
lovebird.update()
|
||||
timer.update(dt)
|
||||
|
||||
test_bar:set_progress(test_timer.run_time / test_timer:get_interval())
|
||||
end
|
||||
|
||||
love.draw = function()
|
||||
test_bar:draw()
|
||||
pages_progress_bar:draw()
|
||||
|
||||
book_progress:draw()
|
||||
end
|
||||
|
||||
love.keypressed = function(key)
|
||||
if key == "escape" then
|
||||
-- TODO save any remaining log
|
||||
utility.save_data(book)
|
||||
love.event.quit()
|
||||
elseif key == "left" then
|
||||
update_pages_progress_bar(-1)
|
||||
update_book_progress(-1)
|
||||
elseif key == "right" then
|
||||
update_pages_progress_bar(1)
|
||||
update_book_progress(1)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user