1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/Diggy/ScoreTable.lua

68 lines
1.1 KiB
Lua

-- dependencies
local Global = require 'utils.global'
-- this
local ScoreTable = {}
local scores = {}
Global.register({
scores = scores,
}, function (tbl)
scores = tbl.scores
end)
--[[--
Resets the score 0 for the given name
@param name String
]]
function ScoreTable.reset(name)
scores[name] = 0
end
--[[--
Adds score.
@param name String
@param value int amount to add
@return int the sum for the score added by name
]]
function ScoreTable.add(name, value)
local new = (scores[name] or 0) + value
scores[name] = new
return new
end
--[[--
Increments the score by 1 for name.
@param name String
@return int the sum for the score incremented by name
]]
function ScoreTable.increment(name)
return ScoreTable.add(name, 1)
end
--[[--
Returns the score for a single key.
@param
]]
function ScoreTable.get(name)
return scores[name] or 0
end
--[[--
Returns all scores.
@return table {[string] = int}
]]
function ScoreTable.all()
return scores
end
return ScoreTable