summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-04-05 17:00:41 +0100
committerrubenwardy <rw@rubenwardy.com>2018-04-05 17:00:48 +0100
commite110bbbc7a8dea47b9ed536fcd31dc21169c6bd6 (patch)
tree841cf9f4087ce61619fb698ba627dcaf69ab4b8a
parent2f49d895ed9b9bea22e8937a4396560e2941d6de (diff)
Add award unlock requirements
Fixes #52
-rw-r--r--README.md42
-rw-r--r--api.lua19
-rw-r--r--gui.lua2
3 files changed, 43 insertions, 20 deletions
diff --git a/README.md b/README.md
index f43deac..47bb92d 100644
--- a/README.md
+++ b/README.md
@@ -12,11 +12,14 @@ Majority of awards are back ported from Calinou's old fork in Carbone, under sam
## Registering Achievements
```lua
-awards.register_achievement(name, {
+awards.register_achievement("mymod:myaward", {
description = "The title of the award",
-- Optional:
+ requires = { "amod:an_award" }, -- don't show this award or allow it to be unlocked
+ -- until required awards are unlocked
+
sound = {}, -- SimpleSoundSpec or false to play no sound
-- if not provided, uses default sound
image = "icon_image.png", -- uses default icon otherwise
@@ -25,7 +28,7 @@ awards.register_achievement(name, {
trigger = { -- is only unlocked by direct calls to awards.unlock() otherwise
type = "trigger_type",
-- see specific docs on the trigger to see what else goes here
- }
+ },
})
```
@@ -38,7 +41,7 @@ local trigger = awards.register_trigger(name, {
progress = "%2/%2"
auto_description = { "Mine: @2", "Mine: @1×@2" },
- on_register = function(self, def) end
+ on_register = function(self, def) end,
-- "counted_key" only, when no key is given (ie: a total)
auto_description_total = { "Mine @1 block.", "Mine @1 blocks." },
@@ -46,7 +49,7 @@ local trigger = awards.register_trigger(name, {
-- "counted_key" only, get key for particular award - return nil for a total
get_key = function(self, def)
return minetest.registered_aliases[def.trigger.node] or def.trigger.node
- end
+ end,
})
```
@@ -107,46 +110,47 @@ Callbacks (register a function to be run)
### dig
trigger = {
- type = "dig",
- node = "default:dirt",
- target = 50
+ type = "dig",
+ node = "default:dirt",
+ target = 50,
}
### place
trigger = {
- type = "place",
- node = "default:dirt",
- target = 50
+ type = "place",
+ node = "default:dirt",
+ target = 50,
}
### death
trigger = {
- type = "death",
- target = 5
+ type = "death",
+ reason = "fall",
+ target = 5,
}
### chat
trigger = {
- type = "chat",
- target = 100
+ type = "chat",
+ target = 100,
}
### join
trigger = {
- type = "join",
- target = 100
+ type = "join",
+ target = 100,
}
### eat
trigger = {
- type = "eat",
- item = "default:apple",
- target = 100
+ type = "eat",
+ item = "default:apple",
+ target = 100,
}
## Callbacks relating to triggers
diff --git a/api.lua b/api.lua
index 39f7f09..1cf05f9 100644
--- a/api.lua
+++ b/api.lua
@@ -296,6 +296,19 @@ function awards.register_achievement(name, def)
tdef:on_register(def)
end
+ function def:can_unlock(data)
+ if not self.requires then
+ return true
+ end
+
+ for i=1, #self.requires do
+ if not data.unlocked[self.requires[i]] then
+ return false
+ end
+ end
+ return true
+ end
+
-- Add Award
awards.registered_awards[name] = def
@@ -341,6 +354,12 @@ function awards.unlock(name, award)
return
end
+ if not awdef:can_unlock(data) then
+ minetest.log("warning", "can_unlock returned false in unlock of " ..
+ award .. " for " .. name)
+ return
+ end
+
-- Unlock Award
minetest.log("action", name.." has unlocked award "..name)
data.unlocked[award] = award
diff --git a/gui.lua b/gui.lua
index 198fa5a..9488eee 100644
--- a/gui.lua
+++ b/gui.lua
@@ -28,7 +28,7 @@ local function order_awards(name)
end
for _, def in pairs(awards.registered_awards) do
- if not hash_is_unlocked[def.name] then
+ if not hash_is_unlocked[def.name] and def:can_unlock(data) then
local started = false
local score
if def.secret then