Merge branch 'remove' into 'master'

Add `awards.remove(..)` util

See merge request rubenwardy/awards!96
This commit is contained in:
Zughy 2024-04-30 14:55:19 +00:00
commit 53fd1e22c3
2 changed files with 17 additions and 0 deletions

View File

@ -197,6 +197,8 @@ end
* return true to cancel HUD from appearing.
* `awards.unlock(player_name, award_name)`
* gives an award to a player
* `awards.remove(player_name, award_name)`
* removes an award from a player
* `awards.get_award_states(player_name)`
* Returns list of tables, sorted by `score`, each having the fields:

View File

@ -183,6 +183,21 @@ function awards.unlock(name, award)
end
end
function awards.remove(name, award)
local data = awards.player(name)
local awdef = awards.registered_awards[award]
assert(awdef, "Unable to remove an award which doesn't exist!")
if data.disabled or
(not data.unlocked[award]) then
return
end
minetest.log("action", "Award " .. award .." has been removed from ".. name)
data.unlocked[award] = nil
awards.save()
end
function awards.get_award_states(name)
local hash_is_unlocked = {}
local retval = {}