From 13eb5dcdaefebbbef3b73fe5350752ed89e19a3f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 30 Aug 2016 14:08:19 +0200 Subject: [PATCH] Add optional default description for triggers --- api.lua | 5 ++++ triggers.lua | 72 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/api.lua b/api.lua index 3dc9620..1d47014 100644 --- a/api.lua +++ b/api.lua @@ -140,6 +140,11 @@ function awards.register_achievement(name, def) -- Add Award awards.def[name] = def + + local tdef = awards.def[name] + if def.description == nil and tdef.getDefaultDescription then + def.description = tdef:getDefaultDescription() + end end function awards.enable(name) diff --git a/triggers.lua b/triggers.lua index 3bffae0..e16b4ee 100644 --- a/triggers.lua +++ b/triggers.lua @@ -26,7 +26,7 @@ awards.register_trigger("dig", function(def) local tmp = { award = def.name, node = def.trigger.node, - target = def.trigger.target + target = def.trigger.target, } table.insert(awards.on.dig, tmp) def.getProgress = function(self, data) @@ -36,13 +36,25 @@ awards.register_trigger("dig", function(def) label = string.format(S("%d/%d dug"), itemcount, tmp.target) } end + def.getDefaultDescription = function(self) + local nname = minetest.registered_nodes[self.trigger.node].description + if nname == nil then + nname = self.trigger.node + end + local ddesc + if self.trigger.target ~= 1 then + return string.format(S("Mine blocks: %d×%s"), self.trigger.target, nname) + else + return string.format(S("Mine a block: %s"), nname) + end + end end) awards.register_trigger("place", function(def) local tmp = { award = def.name, node = def.trigger.node, - target = def.trigger.target + target = def.trigger.target, } table.insert(awards.on.place, tmp) def.getProgress = function(self, data) @@ -52,12 +64,23 @@ awards.register_trigger("place", function(def) label = string.format(S("%d/%d placed"), itemcount, tmp.target) } end + def.getDefaultDescription = function(self) + local nname = minetest.registered_nodes[self.trigger.node].description + if nname == nil then + nname = self.trigger.node + end + if self.trigger.target ~= 1 then + return string.format(S("Place blocks: %d×%s"), self.trigger.target, nname) + else + return string.format(S("Place a block: %s"), nname) + end + end end) awards.register_trigger("death", function(def) local tmp = { award = def.name, - target = def.trigger.target + target = def.trigger.target, } table.insert(awards.on.death, tmp) def.getProgress = function(self, data) @@ -67,30 +90,43 @@ awards.register_trigger("death", function(def) label = string.format(S("%d/%d deaths"), itemcount, tmp.target) } end + def.getDefaultDescription = function(self) + if self.trigger.target ~= 1 then + return string.format(S("Die %d times."), self.trigger.target) + else + return S("Die.") + end + end end) awards.register_trigger("chat", function(def) local tmp = { award = def.name, - target = def.trigger.target + target = def.trigger.target, } table.insert(awards.on.chat, tmp) def.getProgress = function(self, data) local itemcount = data.chats or 0 return { perc = itemcount / tmp.target, - label = string.format(S("%d/%d lines of chat"), itemcount, tmp.target) + label = string.format(S("%d/%d chat messages"), itemcount, tmp.target) } end + def.getDefaultDescription = function(self) + if self.trigger.target ~= 1 then + return string.format(S("Write %d chat messages."), self.trigger.target) + else + return S("Write something in chat.") + end + end end) awards.register_trigger("join", function(def) local tmp = { award = def.name, - target = def.trigger.target + target = def.trigger.target, } table.insert(awards.on.join, tmp) - def.getProgress = function(self, data) local itemcount = data.joins or 0 return { @@ -98,13 +134,20 @@ awards.register_trigger("join", function(def) label = string.format(S("%d/%d game joins"), itemcount, tmp.target) } end + def.getDefaultDescription = function(self) + if self.trigger.target ~= 1 then + return string.format(S("Join the game %d times."), self.trigger.target) + else + return S("Join the game.") + end + end end) awards.register_trigger("craft", function(def) local tmp = { award = def.name, - item = def.trigger.item, - target = def.trigger.target + item = def.trigger.item, + target = def.trigger.target, } table.insert(awards.on.craft, tmp) def.getProgress = function(self, data) @@ -114,6 +157,17 @@ awards.register_trigger("craft", function(def) label = string.format(S("%d/%d crafted"), itemcount, tmp.target) } end + def.getDefaultDescription = function(self) + local iname = minetest.registered_items[self.trigger.item].description + if iname == nil then + iname = self.trigger.item + end + if self.trigger.target ~= 1 then + return string.format(S("Craft: %d×%s"), self.trigger.target, iname) + else + return string.format(S("Craft: %s"), iname) + end + end end) -- Backwards compatibility