diff options
| -rw-r--r-- | api.lua | 33 | ||||
| -rw-r--r-- | textures/awards_progress_gray.png | bin | 0 -> 146 bytes | |||
| -rw-r--r-- | textures/awards_progress_green.png | bin | 0 -> 177 bytes | |||
| -rw-r--r-- | triggers.lua | 43 | 
4 files changed, 76 insertions, 0 deletions
@@ -98,6 +98,23 @@ function awards.increment_item_counter(data, field, itemname, count)  	end  end +function awards.get_item_count(data, field, itemname) +	local name_split = string.split(itemname, ":") +	if #name_split ~= 2 then +		return false +	end +	local mod = name_split[1] +	local item = name_split[2] + +	if data and field and mod and item then +		awards.assertPlayer(data) +		awards.tbv(data, field) +		awards.tbv(data[field], mod) +		awards.tbv(data[field][mod], item, 0) +		return data[field][mod][item] +	end +end +  function awards.register_on_unlock(func)  	table.insert(awards.on_unlock, func)  end @@ -284,6 +301,7 @@ awards.give_achievement = awards.unlock  function awards.getFormspec(name, to, sid)  	local formspec = "size[11,5]"  	local listofawards = awards._order_awards(name) +	local playerdata = awards.players[name]  	-- Sidebar  	if sid then @@ -308,6 +326,21 @@ function awards.getFormspec(name, to, sid)  			if def and def.icon then  				formspec = formspec .. "image[1,0;3,3;" .. def.icon .. "]"  			end +			local barwidth = 4.6 +			local perc = nil +			local label = nil +			if def.getProgress and playerdata then +				local res = def:getProgress(playerdata) +				perc = res.perc +				label = res.label +			end +			if perc then +				formspec = formspec .. "background[0,4.80;" .. barwidth ..",0.25;awards_progress_gray.png]" +				formspec = formspec .. "background[0,4.80;" .. (barwidth * perc) ..",0.25;awards_progress_green.png]" +				if label then +					formspec = formspec .. "label[1.75,4.63;" .. label .. "]" +				end +			end  			if def and def.description then  				formspec = formspec	.. "label[0,3.25;"..def.description.."]"  			end diff --git a/textures/awards_progress_gray.png b/textures/awards_progress_gray.png Binary files differnew file mode 100644 index 0000000..a5fc6cb --- /dev/null +++ b/textures/awards_progress_gray.png diff --git a/textures/awards_progress_green.png b/textures/awards_progress_green.png Binary files differnew file mode 100644 index 0000000..54b4e5d --- /dev/null +++ b/textures/awards_progress_green.png diff --git a/triggers.lua b/triggers.lua index 1a4e355..68a1856 100644 --- a/triggers.lua +++ b/triggers.lua @@ -21,6 +21,13 @@ awards.register_trigger("dig", function(def)  		target = def.trigger.target  	}  	table.insert(awards.on.dig, tmp) +	def.getProgress = function(self, data) +		local itemcount = awards.get_item_count(data, "count", tmp.node) or 0 +		return { +			perc = itemcount / tmp.target, +			label = itemcount .. " / " .. tmp.target .. " dug"  -- TODO: translation +		} +	end  end)  awards.register_trigger("place", function(def) @@ -30,6 +37,13 @@ awards.register_trigger("place", function(def)  		target = def.trigger.target  	}  	table.insert(awards.on.place, tmp) +	def.getProgress = function(self, data) +		local itemcount = awards.get_item_count(data, "place", tmp.node) or 0 +		return { +			perc = itemcount / tmp.target, +			label = itemcount .. " / " .. tmp.target .. " placed"  -- TODO: translation +		} +	end  end)  awards.register_trigger("death", function(def) @@ -38,6 +52,13 @@ awards.register_trigger("death", function(def)  		target = def.trigger.target  	}  	table.insert(awards.on.death, tmp) +	def.getProgress = function(self, data) +		local itemcount = data.deaths or 0 +		return { +			perc = itemcount / tmp.target, +			label = itemcount .. " deaths, need " .. tmp.target  -- TODO: translation +		} +	end  end)  awards.register_trigger("chat", function(def) @@ -46,6 +67,13 @@ awards.register_trigger("chat", function(def)  		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 = itemcount .. " / " .. tmp.target .. " line of chat"  -- TODO: translation +		} +	end  end)  awards.register_trigger("join", function(def) @@ -54,6 +82,14 @@ awards.register_trigger("join", function(def)  		target = def.trigger.target  	}  	table.insert(awards.on.join, tmp) + +	def.getProgress = function(self, data) +		local itemcount = data.joins or 0 +		return { +			perc = itemcount / tmp.target, +			label = itemcount .. " game joins, need " .. tmp.target  -- TODO: translation +		} +	end  end)  awards.register_trigger("craft", function(def) @@ -63,6 +99,13 @@ awards.register_trigger("craft", function(def)  		target = def.trigger.target  	}  	table.insert(awards.on.craft, tmp) +	def.getProgress = function(self, data) +		local itemcount = awards.get_item_count(data, "craft", tmp.item) or 0 +		return { +			perc = itemcount / tmp.target, +			label = itemcount .. " / " .. tmp.target .. " crafted"  -- TODO: translation +		} +	end  end)  -- Backwards compatibility  | 
