summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-04-04 18:36:47 +0100
committerrubenwardy <rw@rubenwardy.com>2018-04-04 18:36:47 +0100
commitcca278024d2f665d60111192b744ef61c030088d (patch)
tree81482c4215630ec4b23d1200bc2bf0e937e5aab1
parenteaab883e716d5bbe3d38f7868e23f08a0964dc5a (diff)
Remove datakey and use trigger names instead
-rw-r--r--api.lua24
1 files changed, 11 insertions, 13 deletions
diff --git a/api.lua b/api.lua
index e235fd8..74a784e 100644
--- a/api.lua
+++ b/api.lua
@@ -74,8 +74,6 @@ function awards.register_trigger(tname, tdef)
tdef.name = tname
tdef.run_callbacks = run_trigger_callbacks
- local datakey = tname .. "s"
- tdef.data_key = datakey
if tdef.type == "counted" then
local old_reg = tdef.on_register
@@ -88,7 +86,7 @@ function awards.register_trigger(tname, tdef)
tdef.register(tmp)
function def.getProgress(_, data)
- local done = data[datakey] or 0
+ local done = data[tname] or 0
return {
perc = done / tmp.target,
label = S(tdef.progress, done, tmp.target),
@@ -112,8 +110,8 @@ function awards.register_trigger(tname, tdef)
print(dump(data))
-- Increment counter
- local currentVal = (data[datakey] or 0) + 1
- data[datakey] = currentVal
+ local currentVal = (data[tname] or 0) + 1
+ data[tname] = currentVal
tdef:run_callbacks(player, data, function(entry)
if entry.target and entry.award and currentVal and
@@ -137,11 +135,11 @@ function awards.register_trigger(tname, tdef)
function def.getProgress(_, data)
local done
- data[datakey] = data[datakey] or {}
+ data[tname] = data[tname] or {}
if tmp.key then
- done = data[datakey][tmp.key] or 0
+ done = data[tname][tmp.key] or 0
else
- done = data[datakey].__total or 0
+ done = data[tname].__total or 0
end
return {
perc = done / tmp.target,
@@ -175,17 +173,17 @@ function awards.register_trigger(tname, tdef)
print(dump(data))
-- Increment counter
- data[datakey] = data[datakey] or {}
- local currentVal = (data[datakey][key] or 0) + n
- data[datakey][key] = currentVal
- data[datakey].__total = (data[datakey].__total or 0) + n
+ data[tname] = data[tname] or {}
+ local currentVal = (data[tname][key] or 0) + n
+ data[tname][key] = currentVal
+ data[tname].__total = (data[tname].__total or 0) + n
tdef:run_callbacks(player, data, function(entry)
local current
if entry.key == key then
current = currentVal
elseif entry.key == nil then
- current = data[datakey].__total
+ current = data[tname].__total
else
return
end