cave-story-randomizer/src/main.lua

88 lines
2.1 KiB
Lua
Raw Normal View History

2018-12-14 17:17:22 +00:00
require 'lib.strict'
VERSION = '0.6'
Class = require 'lib.classic'
_ = require 'lib.moses'
Serpent = require 'lib.serpent'
2018-12-16 02:14:48 +00:00
Terebi = require 'lib.terebi'
2018-12-14 17:17:22 +00:00
lf = love.filesystem
2018-12-16 02:14:48 +00:00
lg = love.graphics
2018-12-14 17:17:22 +00:00
U = require 'util'
local LOG_LEVEL, _logCounts, _logLines = 3, nil, nil
local function _log(level, prefix, text, ...)
if LOG_LEVEL >= level then
local text = prefix .. text
print(text, ...)
table.insert(_logLines, text)
2018-12-14 17:17:22 +00:00
end
_logCounts[level] = _logCounts[level] + 1
2018-12-14 17:17:22 +00:00
end
function logError(...) _log(1, 'ERROR: ', ...) end
function logWarning(...) _log(2, 'WARNING: ', ...) end
function logNotice(...) _log(3, 'NOTICE: ', ...) end
function logInfo(...) _log(4, 'INFO: ', ...) end
function logDebug(...) _log(5, 'DEBUG: ', ...) end
function countLogWarningsAndErrors()
return _logCounts[2], _logCounts[1]
end
function getLogText()
return table.concat(_logLines, "\n")
end
function resetLog()
_logCounts = {0, 0, 0, 0, 0}
_logLines = {}
end
resetLog()
2018-12-14 17:17:22 +00:00
2018-12-19 04:06:41 +00:00
local randomizer = require 'randomizer'()
2018-12-16 02:14:48 +00:00
local background
local font
local screen
local status
function love.load()
Terebi.initializeLoveDefaults()
screen = Terebi.newScreen(320, 240, 2)
background = lg.newImage('assets/background.png')
font = lg.newFont('assets/monogram_extended.ttf', 16)
font:setFilter('nearest', 'nearest', 1)
status = "Drag and drop your Cave Story folder here."
end
2018-12-14 17:17:22 +00:00
function love.directorydropped(path)
2018-12-19 04:06:41 +00:00
status = randomizer:randomize(path)
2018-12-14 17:17:22 +00:00
end
function love.keypressed(key)
if key == 'escape' then
love.event.push('quit')
end
end
2018-12-16 02:14:48 +00:00
local function _print(text, x, y, align)
align = align or 'center'
lg.setFont(font)
local limit = 320 - (x * 2)
lg.setColor(0, 0, 0)
lg.printf(text, x + 1, y + 1, limit, align)
lg.setColor(1, 1, 1)
lg.printf(text, x, y, limit, align)
end
local function _draw()
lg.draw(background, 0, 0)
_print('Cave Story Randomizer v' .. VERSION, 0, 10)
2018-12-16 02:14:48 +00:00
_print('by shru', 0, 22)
_print(status, 10, 65)
_print('shru.itch.io', 10, 220, 'left')
_print('@shruuu', 10, 220, 'right')
end
function love.draw()
screen:draw(_draw)
end