Shorten up library name
parent
0ce7306ed5
commit
2a3a22d083
14
DOCS.md
14
DOCS.md
|
@ -24,20 +24,20 @@ The table is _not_ saved into the storage, only players progress is.
|
|||
|
||||
## 2. Registering and unlocking achievements
|
||||
In order to register the achievements of a mod, do:
|
||||
`achievements_lib.register_achievements(mod, mod_achievements)`
|
||||
`achvmt_lib.register_achievements(mod, mod_achievements)`
|
||||
where `mod` is the mod name and `mod_achievements` a table containing whatever value you want.
|
||||
|
||||
On the contrary, to unlock an achievement:
|
||||
`achievements_lib.unlock_achievement(p_name, mod, achvmt_ID)`
|
||||
`achvmt_lib.unlock_achievement(p_name, mod, achvmt_ID)`
|
||||
|
||||
### 2.1 Utils
|
||||
`achievements_lib.has_player_achievement(p_name, mod, achvmt_ID)`: check whether a player has unlocked an achievement
|
||||
`achievements_lib.is_player_in_storage(p_name, mod)`: check whether a player has connected after a new mod supporting achievements_lib has been added
|
||||
`achievements_lib.add_player_to_storage(p_name, mod)`: for internal use only
|
||||
`achvmt_lib.has_player_achievement(p_name, mod, achvmt_ID)`: check whether a player has unlocked an achievement
|
||||
`achvmt_lib.is_player_in_storage(p_name, mod)`: check whether a player has connected after a new mod supporting achievements_lib has been added
|
||||
`achvmt_lib.add_player_to_storage(p_name, mod)`: for internal use only
|
||||
|
||||
### 2.2 Getters
|
||||
`achievements_lib.get_achievement(mod, achvmt_ID)`: returns the value assigned to the achievement at the corresponding `achvmt_ID`, if any
|
||||
`achievements_lib.get_player_achievements(p_name, mod)`: returns a table containing all the achievements unlocked by `p_name`, where entries are in the format `ID = true`
|
||||
`achvmt_lib.get_achievement(mod, achvmt_ID)`: returns the value assigned to the achievement at the corresponding `achvmt_ID`, if any
|
||||
`achvmt_lib.get_player_achievements(p_name, mod)`: returns a table containing all the achievements unlocked by `p_name`, where entries are in the format `ID = true`
|
||||
|
||||
## 3 About the author
|
||||
I'm Zughy (Marco), a professional Italian pixel artist who fights for FOSS and digital ethics. If this library spared you a lot of time and you want to support me somehow, please consider donating on [LiberaPay](https://liberapay.com/Zughy/).
|
||||
|
|
24
api.lua
24
api.lua
|
@ -1,4 +1,4 @@
|
|||
achievements_lib = {}
|
||||
achvmt_lib = {}
|
||||
|
||||
|
||||
|
||||
|
@ -25,14 +25,14 @@ end
|
|||
-------------------CORPO----------------------
|
||||
----------------------------------------------
|
||||
|
||||
function achievements_lib.register_achievements(mod, mod_achievements)
|
||||
function achvmt_lib.register_achievements(mod, mod_achievements)
|
||||
assert(achievements[mod] == nil, "[ACHIEVEMENTS_LIB] There was an attempt to register the mod " .. mod .. " more than once! Be sure you didn't call this function twice and you didn't install any suspicious mod")
|
||||
achievements[mod] = mod_achievements
|
||||
end
|
||||
|
||||
|
||||
|
||||
function achievements_lib.unlock_achievement(p_name, mod, achvmt_ID)
|
||||
function achvmt_lib.unlock_achievement(p_name, mod, achvmt_ID)
|
||||
|
||||
local achievement = achievements[mod][achvmt_ID]
|
||||
|
||||
|
@ -52,13 +52,13 @@ end
|
|||
--------------------UTILS---------------------
|
||||
----------------------------------------------
|
||||
|
||||
function achievements_lib.has_player_achievement(p_name, mod, achvmt_ID)
|
||||
function achvmt_lib.has_player_achievement(p_name, mod, achvmt_ID)
|
||||
return p_achievements[p_name][mod][achvmt_ID] ~= nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
function achievements_lib.is_player_in_storage(p_name, mod)
|
||||
function achvmt_lib.is_player_in_storage(p_name, mod)
|
||||
if p_achievements[p_name] then
|
||||
if mod and p_achievements[p_name][mod] then
|
||||
return true
|
||||
|
@ -72,7 +72,7 @@ end
|
|||
|
||||
|
||||
|
||||
function achievements_lib.add_player_to_storage(p_name)
|
||||
function achvmt_lib.add_player_to_storage(p_name)
|
||||
|
||||
if not minetest.get_player_by_name(p_name) then
|
||||
minetest.log("Warning", "[ACHIEVEMENTS_LIB] Player " .. p_name .. " must be online in order to be added to the storage!")
|
||||
|
@ -85,7 +85,7 @@ function achievements_lib.add_player_to_storage(p_name)
|
|||
local update_storage = false
|
||||
|
||||
for mod, _ in pairs(achievements) do
|
||||
if not achievements_lib.is_player_in_storage(p_name, mod) then
|
||||
if not achvmt_lib.is_player_in_storage(p_name, mod) then
|
||||
p_achievements[p_name][mod] = {}
|
||||
update_storage = true
|
||||
end
|
||||
|
@ -104,13 +104,13 @@ end
|
|||
-----------------GETTERS----------------------
|
||||
----------------------------------------------
|
||||
|
||||
function achievements_lib.get_achievement(mod, achvmt_ID)
|
||||
function achvmt_lib.get_achievement(mod, achvmt_ID)
|
||||
return achievements[mod][achvmt_ID]
|
||||
end
|
||||
|
||||
|
||||
|
||||
function achievements_lib.get_player_achievements(p_name, mod)
|
||||
function achvmt_lib.get_player_achievements(p_name, mod)
|
||||
return p_achievements[p_name][mod]
|
||||
end
|
||||
|
||||
|
@ -134,7 +134,7 @@ end
|
|||
------------------DEPRECATED------------------
|
||||
----------------------------------------------
|
||||
|
||||
function achievements_lib.add_achievement(p_name, mod, achvmt_ID)
|
||||
minetest.log("warning", "[ACHIEVEMENTS_LIB] (" .. mod .. ") achievements_lib.add_achievement is deprecated: use unlock_achievement instead")
|
||||
achievements_lib.unlock_achievement(p_name, mod, achvmt_ID)
|
||||
function achvmt_lib.add_achievement(p_name, mod, achvmt_ID)
|
||||
minetest.log("warning", "[ACHIEVEMENTS_LIB] (" .. mod .. ") achvmt_lib.add_achievement is deprecated: use unlock_achievement instead")
|
||||
achvmt_lib.unlock_achievement(p_name, mod, achvmt_ID)
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
minetest.register_on_joinplayer(function(player)
|
||||
achievements_lib.add_player_to_storage(player:get_player_name())
|
||||
achvmt_lib.add_player_to_storage(player:get_player_name())
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue