Slib can encrypt your save file! And if player don't have special key, and alghoritm for decryption, he can't change save file.
If you need, Slib can create more than one files. And in Slib you can manage encryption specal key yourself.
In benchmark I use not single table. I use table in table (for example).
View on GitHub:
https://github.com/Snuux/Slib
Download Slib (in .zip):
https://github.com/Snuux/Slib/archive/master.zip
Documentation:
- Function:
slib.init(name) - Description:
Initialize Slib. - Parameters:
name - name of Slib, that you use.
filename (optional) - your default save file name
enc (optional) - default key for encription - Return:
nothing
- Function:
slib.isFirst(filename) - Description:
Check, that save file is in folder. Use for first saving. - Parameters:
filename (optional) - your save file name - Return:
boolean - true, if it is first save
- Function:
slib.save(table, filename, drop, enc) - Description:
Save table without encryption (example: maps, names...). It's much faster. - Parameters:
table - table to save
filename (optional) - your save file name
drop (optional) - if you have custom userdata (like Image) in table
enc (optional) - key for encription - Return:
boolean - true while end saving
- Function:
slib.save(table, filename, drop, enc) - Description:
Save table with encryption (example: stats, money...). It's slow. - Parameters:
table - table to save
filename (optional) - your save file name
drop (optional) - if you have custom userdata (like Image) in table
enc (optional) - key for encription - Return:
boolean - true while end saving
- Function:
slib.load(filename, enc) - Description:
Load your table from file (can be encrypted, or not). - Parameters:
filename (optional) - your save file name
enc (optional) - key for encription - Return:
table - table that you save
boolean - true while end loading
- Function:
slib.clear(filename) - Description:
Delete save file. - Parameters:
filename (optional) - your save file name - Return:
boolean - true, if clear succsess
Simple example:
Code: Select all
--While you exit from app, data save. And while you will open this, data load
Slib = require "slib"
function love.load()
Slib.init("Slib") -- initialize slib
if Slib.isFirst() then --if there is no save
g = {} --char stats
g.hp = 50
g.dmg = 100
g.def = 10
else --if there is save file
g = Slib.load()
end
end
function love.update(dt)
if love.keyboard.isDown('g') then
g.hp = math.random(10, 5000) --generate new stats
g.dmg = math.random(10, 5000)
g.def = math.random(10, 5000)
Slib.saveE(g) --save stats
end
end
function love.draw()
--draw our stats:
love.graphics.print("HP: " .. g.hp .. " Dmg: " .. g.dmg .. " Def: " .. g.def, 10, 10)
love.graphics.print("Press G to generate random HP, Dmg, Def, and save them!", 10, 30)
end
Be careful! Slib can't save custom userdata. And if your table have some this:
Code: Select all
g = {} --char stats
g.hp = 50
g.dmg = 100
g.def = 10
g.img = love.graphics.newImage("Player.png")
g.body = love.physics.newBody(world, 10, 10, "Shape")
Code: Select all
--Parametes: table to save, save file, drop parameter
slib.saveE(g, "save", {"image", "body"})
It's very easy!
P.S. Please give me some advice with code, and may be new features.
1.2 Changelog:
- Add cute comments
- Add clear function
- Add default file name and encription code
- Add two parameters in init function
- Rename function isFirstSave to isFirst
- Fix small bug in pack function
- Fix saving non table values