I created a collection of some useful libraries. They are:
1. Finder
This library can find game servers in local network through UDP broadcast.
Example:
Code: Select all
local finder = require('finder')
love.window.close()
print('1 - server, other - client')
if tonumber(io.read(1)) == 1 then
print('server')
local srv = finder.Server({
port = 8080,
handshake = '93203'
})
srv:on('connect', function(address)
return print(address .. " connected to server!")
end)
srv:on('disconnect', function(address)
return print(address .. " disconnected from server!")
end)
love.update = function(dt)
return srv:update()
end
else
print('client')
local cl = finder.Client({
port = 8080,
handshake = '93203'
})
cl:on('connect', function(address)
return print("Found server " .. address .. "!")
end)
cl:on('disconnect', function(address)
return print(address .. " disconnected!")
end)
love.update = function(dt)
return cl:update()
end
end
Localization library. The killer feature: it can get system locale!
Example:
main.lua:
Code: Select all
local locale = require('locale')
local lc = locale.new('en', 'ru')
-- get system locale, wow!
lc.current = locale.get()
-- more locales can be loaded later
-- lc:load('*')
-- export data from locale
local data = lc.values
local time = 0
local font = love.graphics.newFont('font.ttf', 50)
love.update = function(dt)
-- switch locales every second
time = time + dt
if time >= 1 then
time = 0
if lc.current == 'en' then
lc.current = 'ru'
else
lc.current = 'en'
end
end
end
love.draw = function()
love.graphics.setFont(font)
return love.graphics.print(data.hello, 100, 100)
end
Code: Select all
return {
language = 'en',
values = {
hello = 'Hello!'
}
}
Code: Select all
return {
language = 'ru',
values = {
hello = 'Привет!'
}
}
3. Asset
Async asset loader.
Example:
Code: Select all
local asset = require('asset')
local assets = {}
love.update = function()
assets = {
font = asset.font('font.ttf', 26),
shader = asset('shader.glsl'),
image = asset('image.jpg')
}
end
love.draw = function()
if assets.font then
love.graphics.setFont(assets.font)
love.graphics.print('SUPPORTS FONTS, SHADERS, IMAGES, AUDIOS AND VIDEOS')
end
if assets.shader then
love.graphics.setShader(assets.shader)
end
if assets.image then
love.graphics.draw(assets.image, 0, 55, nil, 0.14, 0.14)
end
if assets.shader then
love.graphics.setShader()
end
end