Created
January 5, 2019 13:46
-
-
Save Tachytaenius/878bcad6e762615a63485f791298146a to your computer and use it in GitHub Desktop.
reeeeeeeeeeeeeeeeeeee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
love.graphics.setDefaultFilter("nearest", "nearest", 0) | |
love.graphics.setLineStyle("rough") | |
math = require("lib.mathsies") -- my maths lib | |
local assets = require("assets") --[=[ | |
-- it's a table of tables, an example being: | |
shaders = { | |
depth = {load = function(self) self.value = love.graphics.newShader("assets/shaders/depth.glsl") end} | |
} | |
]=] | |
local constants = require("constants") -- a table of categories, containing values | |
local settings = require("settings") -- a table with utilities for reading (and parsing the settings json according to a template table), writing and updating the screen according to the contents of settings.current | |
local paused, canvas, commands = false, love.graphics.newCanvas(constants.graphics.width, constants.graphics.height), {} | |
settings.read() | |
local function loadAssets(start) | |
start = start or assets | |
for _, v in pairs(start) do | |
if v.load then | |
v:load() | |
else | |
loadAssets(v) | |
end | |
end | |
end | |
loadAssets() | |
local args = love.arg.parseGameArguments(arg) -- must this be within love.run? | |
if not args[1] or args[1] == "new" then | |
local seed = args[2] or love.math.random(2 ^ 53) - 1 | |
-- game states. idk how to do them!! i'm worried about stuff like canvasses-- should i do classes and iaaguh | |
elseif args[1] == "load" then | |
local path = args[2] | |
else | |
knowledged.error("Invalid first argument: " .. args[1]) | |
end | |
function love.run() | |
love.timer.step() | |
return function() | |
love.event.pump() | |
for name, a, b, c, d, e, f in love.event.poll() do | |
if name == "quit" then | |
if not love.quit() then | |
return a or 0 | |
end | |
end | |
love.handlers[name](a, b, c, d, e, f) | |
end | |
if not paused then | |
-- update which state??! | |
end | |
if love.graphics.isActive() then | |
love.graphics.origin() | |
love.graphics.clear(love.graphics.getBackgroundColor()) | |
love.graphics.setFont(assets.images.misc.font.value) | |
if not paused then | |
love.graphics.setCanvas(canvas) | |
-- draw which state!!? | |
love.graphics.setCanvas() | |
end | |
-- just some post-processing | |
love.graphics.setShader(assets.shaders.depth.value) | |
love.graphics.draw(canvas, gameX, gameY, 0, settings.current.graphics.scale) | |
love.graphics.setShader() | |
if paused then | |
love.graphics.print("PAUSED", 0, 0, 0, settings.current.graphics.scale) | |
end | |
end | |
-- fixed timestep + draw performance? | |
local wait = constants.core.slowness - love.timer.step() | |
love.timer.sleep(math.max(wait, 0)) | |
if love.graphics.isActive() then | |
if settings.current.graphics.showPerformance then | |
local performance = wait / constants.core.slowness | |
love.graphics.setColor(1 - performance, performance, 0) | |
love.graphics.print((paused and "\n" or "") .. math.round(performance * 100) .. "%", 0, 0, 0, settings.current.graphics.scale) | |
love.graphics.setColor(1, 1, 1) | |
end | |
love.graphics.present() | |
end | |
love.timer.step() | |
love.timer.sleep(0.001) | |
end | |
end | |
function love.quit() | |
end | |
function love.keypressed(_, key) | |
local command = settings.current.buttons[key] | |
if command then | |
commands[command] = true | |
end | |
end | |
function love.keyreleased(_, key) | |
local command = settings.current.buttons[key] | |
if command == "pause" then | |
paused = not paused | |
elseif command == "takeScreenshot" then | |
local info = love.filesystem.getInfo("screenshots") | |
if info and info.type ~= "directory" then | |
print("There is already a non-folder item called screenshots. Rename it or move it to take a screenshot.") | |
return | |
elseif not info then | |
print("Couldn't find screenshots folder. Creating.") | |
love.filesystem.createDirectory("screenshots") | |
end | |
local current = 0 | |
for _, filename in pairs(love.filesystem.getDirectoryItems("screenshots")) do | |
local name = string.sub(filename, 1, -5) -- remove ".png" | |
if name then | |
local number = tonumber(name) | |
if number and number > current then current = number end | |
end | |
end | |
local data = canvas:newImageData() | |
data:mapPixel( | |
function(x, y, r, g, b, a) | |
return math.round(r, 15), math.round(g, 15), math.round(b, 15), 1 | |
end | |
) | |
data:encode("png", "screenshots/" .. current + 1 .. ".png") | |
elseif command == "scaleDown" then | |
if settings.current.graphics.scale > 1 then | |
settings.current.graphics.scale = settings.current.graphics.scale - 1 | |
gameX, gameY = settings.updateWindow() | |
settings.write() | |
end | |
elseif command == "scaleUp" then | |
settings.current.graphics.scale = settings.current.graphics.scale + 1 | |
gameX, gameY = settings.updateWindow() | |
settings.write() | |
elseif command == "toggleFullscreen" then | |
settings.current.graphics.fullscreen = not settings.current.graphics.fullscreen | |
gameX, gameY = settings.updateWindow() | |
settings.write() | |
elseif command == "toggleInfo" then | |
settings.current.graphics.showPerformance = not settings.current.graphics.showPerformance | |
settings.write() | |
elseif command then | |
commands[command] = nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment