Add charge text to infotext

This commit is contained in:
Evert Prants 2018-06-18 12:54:06 +03:00
parent baff673cb8
commit 9e8a1967f2
No known key found for this signature in database
GPG Key ID: 1688DA83D222D0B5
5 changed files with 18 additions and 9 deletions

@ -44,11 +44,13 @@ function elepm.register_crafter(nodename, nodedef)
if not result then
meta:set_string("formspec", ele.formspec.get_crafter_formspec(craft_type, pow_percent))
meta:set_int("src_time", 0)
meta:set_string("infotext", ("%s Idle"):format(nodedef.description))
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage))
else
local pct = math.floor((ele.helpers.round(result.time * 10) / meta:get_int("src_time")) * 100)
meta:set_string("formspec", ele.formspec.get_crafter_formspec(craft_type, pow_percent, pct))
meta:set_string("infotext", ("%s Out of Power!"):format(nodedef.description))
meta:set_string("infotext", ("%s Out of Power!"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage))
end
break
@ -60,7 +62,8 @@ function elepm.register_crafter(nodename, nodedef)
meta:set_int("storage", storage - usage)
pow_percent = math.floor((storage / capacity) * 100)
meta:set_int("src_time", meta:get_int("src_time") + ele.helpers.round(machine_speed * 10))
meta:set_string("infotext", ("%s Active"):format(nodedef.description))
meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage))
if nodedef.ele_active_node then
local active_node = nodename.."_active"
@ -100,7 +103,8 @@ function elepm.register_crafter(nodename, nodedef)
ele.helpers.swap_node(pos, machine_node)
meta:set_string("formspec", ele.formspec.get_crafter_formspec(craft_type, pow_percent))
meta:set_int("src_time", ele.helpers.round(result.time*10))
meta:set_string("infotext", ("%s Output Full!"):format(nodedef.description))
meta:set_string("infotext", ("%s Output Full!"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage))
break
end

@ -57,7 +57,8 @@ function elepm.register_fuel_generator(nodename, nodedef)
end
else
meta:set_string("formspec", ele.formspec.get_generator_formspec(pow_percent, 0))
meta:set_string("infotext", ("%s Idle"):format(nodedef.description))
meta:set_string("infotext", ("%s Idle"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage))
ele.helpers.swap_node(pos, nodename)
return false
end
@ -66,7 +67,8 @@ function elepm.register_fuel_generator(nodename, nodedef)
local percent = math.floor((burn_time / burn_totaltime) * 100)
meta:set_string("formspec", ele.formspec.get_generator_formspec(pow_percent, percent))
meta:set_string("infotext", ("%s Active"):format(nodedef.description))
meta:set_string("infotext", ("%s Active"):format(nodedef.description) ..
"\n" .. ele.capacity_text(capacity, storage))
return true
end

@ -27,7 +27,7 @@ function elepm.register_storage(nodename, nodedef)
ele.helpers.swap_node(pos, nodename .. "_" .. level)
meta:set_string("formspec", ele.formspec.get_storage_formspec(rounded))
meta:set_string("infotext", ("%s Active"):format(nodedef.description))
meta:set_string("infotext", ("%s Active"):format(nodedef.description) .. "\n" .. ele.capacity_text(capacity, storage))
local inv = meta:get_inventory()

@ -110,6 +110,10 @@ local function retrieve_metadata(pos, placer, itemstack, pointed_thing)
return false
end
function ele.capacity_text(capacity, storage)
return "Charge: " .. storage .. "/" .. capacity .. " " ..ele.unit
end
-- Register a base device
function ele.register_base_device(nodename, nodedef)
-- Override construct callback

@ -43,8 +43,7 @@ function ele.tools.update_tool_wear(itemstack)
local percent = storage / capacity
local wear = math.floor((1-percent) * 65535)
meta:set_string("description", itemdef.description .. "\nCharge: " ..
storage .. "/" .. capacity .. " " .. ele.unit)
meta:set_string("description", itemdef.description .. "\n" .. ele.capacity_text(capacity, storage))
itemstack:set_wear(wear)
itemstack = ele.tools.groupcaps(itemstack)