add missing files

master
Pascal Abresch 2 months ago
parent 0ef7436318
commit 91fbc72297
  1. 23
      shared/asserts.lua
  2. 15
      shared/fonts.lua
  3. 96
      shared/utils.lua

@ -0,0 +1,23 @@
local asserts = {}
function asserts.number(name, count, ...)
local args = { ... }
for i = 1, count do
assert(args[i] ~= nil, "Argument " .. i .. " to " .. name .. " may not be nil and must be an int!")
assert(type(args[i]) == "number", "Argument " .. i .. " to " .. name .. " must be an int!")
assert(args[i] == args[i], "Argument " .. i .. " to " .. name .. " must not be NaN!")
end
end
function asserts.numberOrNil(name, count, ...)
local args = { ... }
for i = 1, count do
if (args[i] ~= nil) then
assert(type(args[i]) == "number", "Argument " .. i .. " to " .. name .. " can only be of type int!")
assert(args[i] == args[i], "Argument " .. i .. " to " .. name .. " may not be NaN!")
end
end
end
return asserts

@ -0,0 +1,15 @@
local fonts = {}
if love.filesystem.getInfo("fonts/font.ttf") then
fonts.smallFont = love.graphics.newFont("fonts/font.ttf", 14)
fonts.normalFont = love.graphics.newFont("fonts/font.ttf", 20)
fonts.headerFont = love.graphics.newFont("fonts/font.ttf", 25)
fonts.bigFont = love.graphics.newFont("fonts/font.ttf", 45)
else
fonts.smallFont = love.graphics.newFont(14)
fonts.normalFont = love.graphics.newFont(20)
fonts.headerFont = love.graphics.newFont(25)
fonts.bigFont = love.graphics.newFont(45)
end
return fonts

@ -0,0 +1,96 @@
local utils = {}
utils.recordSeperator = string.char(30)
utils.unitSeperator = string.char(31)
utils.colorstack = {}
-- Colors
function utils.color_push()
local colorstack = utils.colorstack
local depth = #utils.colorstack +1
colorstack[depth] = {}
colorstack[depth].r, colorstack[depth].g, colorstack[depth].b,
colorstack[depth].a = love.graphics.getColor()
end
function utils.color_pop()
local colorstack = utils.colorstack
love.graphics.setColor(colorstack[#colorstack].r, colorstack[#colorstack].g,
colorstack[#colorstack].b, colorstack[#colorstack].a)
table.remove(colorstack, #colorstack)
end
-- Network
function utils.record(...)
local args = { ... }
local string = args[1]
for i=2, #args do
string = string .. recordSeperator .. args[i]
end
return string
end
function utils.unit(...)
local args = { ... }
local string = args[1]
assert(string, "No args to unit!")
for i=2, #args do
--print(type(string) .. "with" .. type(args[i]))
string = string .. string.char(31) .. args[i]
end
return string
end
function utils.resolve(record)
local tTable = {}
for entry in record:gmatch("[^\31]+") do
table.insert(tTable, entry)
end
return tTable
end
function utils.clean(record)
assert(type(record) == "string")
return record:gsub("\31", "")
end
function utils.pprint(record)
local cleaned, _ = record:gsub("\31","|")
return cleaned
end
function utils.nextIntRecord(record)
local nextR = utils.clean(record:match("^.-\31"))
record = record:gsub("^.-\31","")
return tonumber(nextR), record
end
function utils.nextStringRecord(record)
local nextR = utils.clean(record:match("^.-\31"))
record = record:gsub("^.-\31","")
return nextR, record
end
function utils.getIntRecords(number, record)
local tTable = {}
local nextR
for i = 1, number -1 do
nextR, record = utils.nextIntRecord(record)
table.insert(tTable, nextR)
end
local last = utils.clean(record:gsub("^.-\31",""))
table.insert(tTable, tonumber(last))
return unpack(tTable)
end
return utils
Loading…
Cancel
Save