Use updated awards API (#31)

* Use updated awards API

* Fix dig/place incrementing

* Use awards.player() in crates

* Use new 'dig' incrementor for digtron packing

* Only initialize tables if they dont exist

* Fix typo

* Remove init function, use checks instead
This commit is contained in:
Alex 2018-12-13 23:48:41 -08:00 committed by FaceDeer
parent 1011901938
commit bcc2f64c2e
5 changed files with 72 additions and 63 deletions

@ -1,8 +1,8 @@
if not minetest.get_modpath("awards") then if not minetest.get_modpath("awards") then
digtron.award_item_dug = function (items, player, count) end digtron.award_item_dug = function (items, name, count) end
digtron.award_layout = function (layout, player) end digtron.award_layout = function (layout, name) end
digtron.award_item_built = function(item_name, player) end digtron.award_item_built = function(item_name, name) end
digtron.award_crate = function (layout, player) end digtron.award_crate = function (layout, name) end
return return
end end
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@ -11,18 +11,24 @@ end
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S, NS = dofile(MP.."/intllib.lua")
digtron.award_item_dug = function (items_dropped, player) digtron.award_item_dug = function (items_dropped, name)
if table.getn(items_dropped) == 0 then if table.getn(items_dropped) == 0 or not name or name == "" then
return return
end end
local data = awards.players[player] local data = awards.player(name)
if not data.digtron_dug_groups then
data.digtron_dug_groups = {
tree = 0,
dirt = 0,
grass = 0,
}
end
if not data.digtron_dug then
data.digtron_dug = {}
end
awards.tbv(data, "digtron_dug_groups")
awards.tbv(data["digtron_dug_groups"], "tree", 0)
awards.tbv(data["digtron_dug_groups"], "dirt", 0)
awards.tbv(data["digtron_dug_groups"], "grass", 0)
for _, item in pairs(items_dropped) do for _, item in pairs(items_dropped) do
awards.increment_item_counter(data, "digtron_dug", item) awards.increment_item_counter(data, "digtron_dug", item)
if minetest.get_item_group(item, "tree") > 0 then if minetest.get_item_group(item, "tree") > 0 then
@ -37,111 +43,118 @@ digtron.award_item_dug = function (items_dropped, player)
end end
if awards.get_item_count(data, "digtron_dug", "default:mese_crystal") > 100 then if awards.get_item_count(data, "digtron_dug", "default:mese_crystal") > 100 then
awards.unlock(player, "digtron_100mese_dug") awards.unlock(name, "digtron_100mese_dug")
end end
if awards.get_item_count(data, "digtron_dug", "default:diamond") > 100 then if awards.get_item_count(data, "digtron_dug", "default:diamond") > 100 then
awards.unlock(player, "digtron_100diamond_dug") awards.unlock(name, "digtron_100diamond_dug")
end end
if awards.get_item_count(data, "digtron_dug", "default:coal_lump") > 1000 then if awards.get_item_count(data, "digtron_dug", "default:coal_lump") > 1000 then
awards.unlock(player, "digtron_1000coal_dug") awards.unlock(name, "digtron_1000coal_dug")
if awards.get_item_count(data, "digtron_dug", "default:coal_lump") > 10000 then if awards.get_item_count(data, "digtron_dug", "default:coal_lump") > 10000 then
awards.unlock(player, "digtron_10000coal_dug") awards.unlock(name, "digtron_10000coal_dug")
end end
end end
if awards.get_item_count(data, "digtron_dug", "default:iron_lump") > 1000 then if awards.get_item_count(data, "digtron_dug", "default:iron_lump") > 1000 then
awards.unlock(player, "digtron_1000iron_dug") awards.unlock(name, "digtron_1000iron_dug")
end end
if awards.get_item_count(data, "digtron_dug", "default:copper_lump") > 1000 then if awards.get_item_count(data, "digtron_dug", "default:copper_lump") > 1000 then
awards.unlock(player, "digtron_1000copper_dug") awards.unlock(name, "digtron_1000copper_dug")
end end
if awards.get_item_count(data, "digtron_dug", "default:gold_lump") > 100 then if awards.get_item_count(data, "digtron_dug", "default:gold_lump") > 100 then
awards.unlock(player, "digtron_100gold_dug") awards.unlock(name, "digtron_100gold_dug")
end end
local total_count = awards.get_total_item_count(data, "digtron_dug") local total_count = awards.get_total_keyed_count(data, "digtron_dug")
if total_count > 1000 then if total_count > 1000 then
awards.unlock(player, "digtron_1000_dug") awards.unlock(name, "digtron_1000_dug")
if total_count > 10000 then if total_count > 10000 then
awards.unlock(player, "digtron_10000_dug") awards.unlock(name, "digtron_10000_dug")
if total_count > 100000 then if total_count > 100000 then
awards.unlock(player, "digtron_100000_dug") awards.unlock(name, "digtron_100000_dug")
if total_count > 1000000 then if total_count > 1000000 then
awards.unlock(player, "digtron_1000000_dug") awards.unlock(name, "digtron_1000000_dug")
end end
end end
end end
end end
if data["digtron_dug_groups"]["tree"] > 1000 then if data["digtron_dug_groups"]["tree"] > 1000 then
awards.unlock(player, "digtron_1000wood_dug") awards.unlock(name, "digtron_1000wood_dug")
if data["digtron_dug_groups"]["tree"] > 10000 then if data["digtron_dug_groups"]["tree"] > 10000 then
awards.unlock(player, "digtron_10000wood_dug") awards.unlock(name, "digtron_10000wood_dug")
end end
end end
if data["digtron_dug_groups"]["dirt"] > 1000 then if data["digtron_dug_groups"]["dirt"] > 1000 then
awards.unlock(player, "digtron_1000dirt_dug") awards.unlock(name, "digtron_1000dirt_dug")
end end
if data["digtron_dug_groups"]["grass"] > 1000 then if data["digtron_dug_groups"]["grass"] > 1000 then
awards.unlock(player, "digtron_1000grass_dug") awards.unlock(name, "digtron_1000grass_dug")
end end
end end
digtron.award_item_built = function(item_name, player) digtron.award_item_built = function(item_name, name)
local data = awards.players[player] if not name or name == "" then
return
end
local data = awards.player(name)
if not data.digtron_built then
data.digtron_built = {}
end
awards.increment_item_counter(data, "digtron_built", item_name) awards.increment_item_counter(data, "digtron_built", item_name)
local total_count = awards.get_total_item_count(data, "digtron_built") local total_count = awards.get_total_keyed_count(data, "digtron_built")
if total_count > 1000 then if total_count > 1000 then
awards.unlock(player, "digtron_1000_built") awards.unlock(name, "digtron_1000_built")
if total_count > 10000 then if total_count > 10000 then
awards.unlock(player, "digtron_10000_built") awards.unlock(name, "digtron_10000_built")
end end
end end
end end
digtron.award_layout = function (layout, player) digtron.award_layout = function(layout, name)
if layout == nil or player == nil or player == "" then if layout == nil or not name or name == "" then
return return
end end
if layout.water_touching then if layout.water_touching then
awards.unlock(player, "digtron_water") awards.unlock(name, "digtron_water")
end end
if layout.lava_touching then if layout.lava_touching then
awards.unlock(player, "digtron_lava") awards.unlock(name, "digtron_lava")
end end
if table.getn(layout.all) > 9 then if table.getn(layout.all) > 9 then
awards.unlock(player, "digtron_size10") awards.unlock(name, "digtron_size10")
if table.getn(layout.all) > 99 then if table.getn(layout.all) > 99 then
awards.unlock(player, "digtron_size100") awards.unlock(name, "digtron_size100")
end end
end end
if table.getn(layout.diggers) > 24 then if table.getn(layout.diggers) > 24 then
awards.unlock(player, "digtron_digger25") awards.unlock(name, "digtron_digger25")
end end
if table.getn(layout.builders) > 24 then if table.getn(layout.builders) > 24 then
awards.unlock(player, "digtron_builder25") awards.unlock(name, "digtron_builder25")
end end
if layout.controller.y > 100 then if layout.controller.y > 100 then
awards.unlock(player, "digtron_height100") awards.unlock(name, "digtron_height100")
if layout.controller.y > 1000 then if layout.controller.y > 1000 then
awards.unlock(player, "digtron_height1000") awards.unlock(name, "digtron_height1000")
end end
elseif layout.controller.y < -100 then elseif layout.controller.y < -100 then
awards.unlock(player, "digtron_depth100") awards.unlock(name, "digtron_depth100")
if layout.controller.y < -1000 then if layout.controller.y < -1000 then
awards.unlock(player, "digtron_depth1000") awards.unlock(name, "digtron_depth1000")
if layout.controller.y < -2000 then if layout.controller.y < -2000 then
awards.unlock(player, "digtron_depth2000") awards.unlock(name, "digtron_depth2000")
if layout.controller.y < -4000 then if layout.controller.y < -4000 then
awards.unlock(player, "digtron_depth4000") awards.unlock(name, "digtron_depth4000")
if layout.controller.y < -8000 then if layout.controller.y < -8000 then
awards.unlock(player, "digtron_depth8000") awards.unlock(name, "digtron_depth8000")
if layout.controller.y < -16000 then if layout.controller.y < -16000 then
awards.unlock(player, "digtron_depth16000") awards.unlock(name, "digtron_depth16000")
if layout.controller.y < -30000 then if layout.controller.y < -30000 then
awards.unlock(player, "digtron_depth30000") awards.unlock(name, "digtron_depth30000")
end end
end end
end end
@ -151,16 +164,16 @@ digtron.award_layout = function (layout, player)
end end
end end
digtron.award_crate = function (layout, player) digtron.award_crate = function(layout, name)
if layout == nil or player == nil or player == "" then if layout == nil or not name or name == "" then
return return
end end
-- Note that we're testing >10 rather than >9 because this layout includes the crate node -- Note that we're testing >10 rather than >9 because this layout includes the crate node
if table.getn(layout.all) > 10 then if table.getn(layout.all) > 10 then
awards.unlock(player, "digtron_crate10") awards.unlock(name, "digtron_crate10")
if table.getn(layout.all) > 100 then if table.getn(layout.all) > 100 then
awards.unlock(player, "digtron_crate100") awards.unlock(name, "digtron_crate100")
end end
end end
end end
@ -401,4 +414,4 @@ awards.register_achievement("digtron_crate100",{
description = S("Stored 100 or more Digtron blocks in one crate."), description = S("Stored 100 or more Digtron blocks in one crate."),
background = "awards_bg_mining.png", background = "awards_bg_mining.png",
icon = "digtron_plate.png^digtron_crate.png", -- TODO: Visually distinguish this from Bigtron icon = "digtron_plate.png^digtron_crate.png", -- TODO: Visually distinguish this from Bigtron
}) })

@ -335,8 +335,6 @@ local node_callbacks = function(dug_nodes, placed_nodes, player)
local old_node = dug_node[2] local old_node = dug_node[2]
local old_meta = dug_node[3] local old_meta = dug_node[3]
minetest.log("action", string.format("%s removes Digtron component %s at (%d, %d, %d)", player:get_player_name(), old_node.name, old_pos.x, old_pos.y, old_pos.z))
for _, callback in ipairs(minetest.registered_on_dignodes) do for _, callback in ipairs(minetest.registered_on_dignodes) do
-- Copy pos and node because callback can modify them -- Copy pos and node because callback can modify them
local pos_copy = {x=old_pos.x, y=old_pos.y, z=old_pos.z} local pos_copy = {x=old_pos.x, y=old_pos.y, z=old_pos.z}
@ -354,8 +352,6 @@ local node_callbacks = function(dug_nodes, placed_nodes, player)
local new_pos = placed_node[1] local new_pos = placed_node[1]
local new_node = placed_node[2] local new_node = placed_node[2]
local old_node = placed_node[3] local old_node = placed_node[3]
minetest.log("action", string.format("%s adds Digtron component %s at (%d, %d, %d)", player:get_player_name(), new_node.name, new_pos.x, new_pos.y, new_pos.z))
for _, callback in ipairs(minetest.registered_on_placenodes) do for _, callback in ipairs(minetest.registered_on_placenodes) do
-- Copy pos and node because callback can modify them -- Copy pos and node because callback can modify them

@ -305,4 +305,4 @@ minetest.register_node("digtron:builder", {
end end
return built_count return built_count
end, end,
}) })

@ -59,8 +59,8 @@ local store_digtron = function(pos, clicker, loaded_node_name, protected)
if modpath_awards then if modpath_awards then
-- We're about to tell the awards mod that we're digging a node, but we -- We're about to tell the awards mod that we're digging a node, but we
-- don't want it to count toward any actual awards. Pre-decrement. -- don't want it to count toward any actual awards. Pre-decrement.
local data = awards.players[clicker:get_player_name()] local data = awards.player(clicker:get_player_name())
awards.increment_item_counter(data, "count", old_node.name, -1) awards.increment_item_counter(data, "dig", old_node.name, -1)
end end
for _, callback in ipairs(minetest.registered_on_dignodes) do for _, callback in ipairs(minetest.registered_on_dignodes) do

@ -580,4 +580,4 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
node_to_dig, whether_to_dig = layout.nodes_dug:pop() node_to_dig, whether_to_dig = layout.nodes_dug:pop()
end end
return pos, status_text, 0 return pos, status_text, 0
end end