From 3d1b4b0a97ebd0f92d4e18769f75fc91bcdf77fe Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 4 Dec 2016 01:41:47 +0100 Subject: [PATCH] Use minetest.conf settings system --- hbarmor.conf.example | 9 --------- init.lua | 15 +++++++++++---- settingtypes.txt | 7 +++++++ 3 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 hbarmor.conf.example create mode 100644 settingtypes.txt diff --git a/hbarmor.conf.example b/hbarmor.conf.example deleted file mode 100644 index 633a5d3..0000000 --- a/hbarmor.conf.example +++ /dev/null @@ -1,9 +0,0 @@ --- If true, automatically hides the armor when the player wears no armor. --- Otherwise, the armor bar shows “0%”. - ---hbarmor.autohide = true - --- Time difference in seconds between updates to the HUD armor bar. --- Increase this number for slow servers. - --- hbarmor.tick = 0.1 diff --git a/init.lua b/init.lua index 8f2dd4c..e1d190f 100644 --- a/init.lua +++ b/init.lua @@ -16,18 +16,25 @@ hbarmor.player_active = {} -- HUD item ids local armor_hud = {} +-- Time difference in seconds between updates to the HUD armor bar. +-- Increase this number for slow servers. hbarmor.tick = 0.1 -- If true, the armor bar is hidden when the player does not wear any armor hbarmor.autohide = true --load custom settings -local set = io.open(minetest.get_modpath("hbarmor").."/hbarmor.conf", "r") -if set then - dofile(minetest.get_modpath("hbarmor").."/hbarmor.conf") - set:close() +local set = minetest.setting_getbool("hbarmor_autohide") +if set ~= nil then + hbarmor.autohide = set end +set = minetest.setting_get("hbarmor_tick") +if tonumber(set) ~= nil then + hbarmor.tick = tonumber(set) +end + + local must_hide = function(playername, arm) return ((not armor.def[playername].count or armor.def[playername].count == 0) and arm == 0) end diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..8fc8522 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,7 @@ +#If true, automatically hides the armor HUD bar when the player wears no +#armor. Otherwise, the armor bar shows “0%”. +hbarmor_autohide (Automatically hide armor HUD bar) bool true + +#Time difference in seconds between updates to the armor HUD bar. +#Increase this number for slow servers. +hbarmor_tick (Armor HUD bar update frequency) float 0.1 0.0