From bfd46c88c8e8ffbab3991c194c80912be06d283d Mon Sep 17 00:00:00 2001 From: Maksym H Date: Mon, 19 Sep 2022 20:58:33 +0200 Subject: [PATCH] Minor statbars update --- LICENSE.txt | 6 +++-- builtin/game/hunger.lua | 35 ++++++++++++++++++--------- textures/base/pack/heart.png | Bin 344 -> 279 bytes textures/base/pack/heart_gone.png | Bin 212 -> 1728 bytes textures/base/pack/hunger.png | Bin 366 -> 427 bytes textures/base/pack/hunger_gone.png | Bin 226 -> 1809 bytes textures/base/pack/hunger_poisen.png | Bin 424 -> 364 bytes 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 0850db902..a912bebb5 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -37,8 +37,6 @@ MultiCraft Development Team: textures/base/pack/down_btn.png textures/base/pack/drop_btn.png textures/base/pack/escape_btn.png - textures/base/pack/heart.png - textures/base/pack/heart_gone.png textures/base/pack/hunger_*.png textures/base/pack/inventory_btn.png textures/base/pack/joystick_*.png @@ -105,6 +103,10 @@ Zughy: textures/base/pack/cdb_update.png textures/base/pack/cdb_viewonline.png +KevDoy, An0n3m0us: + textures/base/pack/heart.png + textures/base/pack/heart_gone.png + License of Minetest source code ------------------------------- diff --git a/builtin/game/hunger.lua b/builtin/game/hunger.lua index b46b86b9e..034a5fcfa 100644 --- a/builtin/game/hunger.lua +++ b/builtin/game/hunger.lua @@ -75,6 +75,14 @@ local function is_player(player) ) end +local function get_hud_id(player) + return hunger.hud[player:get_player_name()] +end + +local function set_hud_id(player, hud_id) + hunger.hud[player:get_player_name()] = hud_id +end + --- SATURATION API --- function hunger.get_saturation(player) if not is_player(player) then @@ -91,8 +99,7 @@ function hunger.set_hud_level(player, level) return end - local hud = hunger.hud[player:get_player_name()] - player:hud_change(hud, "number", min(settings.visual_max, level)) + player:hud_change(get_hud_id(player), "number", min(settings.visual_max, level)) end function hunger.set_saturation(player, level) @@ -103,7 +110,7 @@ end hunger.registered_on_update_saturations = {} function hunger.register_on_update_saturation(fun) local saturations = hunger.registered_on_update_saturations - saturations[#saturations+1] = fun + saturations[#saturations + 1] = fun end function hunger.update_saturation(player, level) @@ -137,7 +144,13 @@ function hunger.change_saturation(player, change) return false end - local level = hunger.get_saturation(player) + change or 0 + local old = hunger.get_saturation(player) + + if not old then + return false + end + + local level = old + change level = max(level, 0) level = min(level, settings.level_max) hunger.update_saturation(player, level) @@ -162,9 +175,8 @@ function hunger.set_hud_poisoned(player, poisoned) return end - local hud = hunger.hud[player:get_player_name()] local texture = poisoned and "hunger_poisen.png" or "hunger.png" - player:hud_change(hud, "text", texture) + player:hud_change(get_hud_id(player), "text", texture) end function hunger.set_poisoned(player, poisoned) @@ -195,7 +207,7 @@ end hunger.registered_on_poisons = {} function hunger.register_on_poison(fun) local poison = hunger.registered_on_poisons - poison[#poison+1] = fun + poison[#poison + 1] = fun end function hunger.poison(player, ticks, interval) @@ -236,7 +248,7 @@ end hunger.registered_on_exhaust_players = {} function hunger.register_on_exhaust_player(fun) local exhaust = hunger.registered_on_exhaust_players - exhaust[#exhaust+1] = fun + exhaust[#exhaust + 1] = fun end function hunger.exhaust_player(player, change, cause) @@ -384,7 +396,8 @@ core.register_on_joinplayer(function(player) if hunger.bar_definition then local def = tcopy(hunger.bar_definition) def.number = min(settings.visual_max, level) - hunger.hud[player:get_player_name()] = player:hud_add(def) + local id = player:hud_add(def) + set_hud_id(player, id) end -- reset poisoned @@ -392,7 +405,7 @@ core.register_on_joinplayer(function(player) end) core.register_on_leaveplayer(function(player) - hunger.hud[player:get_player_name()] = nil + set_hud_id(player, nil) end) local exhaust = hunger.exhaust_player @@ -409,7 +422,7 @@ core.register_on_punchplayer(function(_, hitter) exhaust(hitter, settings.exhaust_punch, hunger.exhaustion_reasons.punch) end) core.register_on_respawnplayer(function(player) - hunger.set_saturation(player, settings.level_max) + hunger.update_saturation(player, settings.level_max) hunger.set_exhaustion(player, 0) hunger.set_poisoned(player, false) end) diff --git a/textures/base/pack/heart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6NUkSVZ_jA9*trt`M8daVz?@cgCiG*GofYE97uUEQl`Q z_^qDtbeF*#r~d+lny0Iu%Q~lo FCIH&nkHG){ diff --git a/textures/base/pack/hunger_gone.png b/textures/base/pack/hunger_gone.png index f66d36dba1addc595d0d44b2aa084ee9dec34f0c..494689aaca3da313e31b59a640bce5b0605229da 100644 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4(FKU|F9T5>XQ2>tmIipR1RclAn~S zSCLx)lxJYDv9BmdOwLX%QAkQn&&;z`dcS+Wl0s&Rtx~wDuYqrYb81GWM^#a3aFt(3 za#eP+Wr~u$9hXgo70`g()RIJnirk#MVyg;UC9t_xKsHENUr7P1q$Jx`DZ)2E!8yMu zRl!uxRL?-kj!VI&C?(A*$i)q+8OXC$$|xx*u+rBrFE7_CH`dE9O4m2Ew6xSWFw!?N z(gmu}Ew0QfNvzP#D^>;>0WrfRwK%ybv!En1KTiQQ?NYIsRz8p8Cv zVyO3l0ih3)(KpmH&_`CDT9JuEIYK&@#lxz{<$j z%Fs;Pz{twL0BkZ?H83xvB$gx+QV&Ye3N}C;zP?r-nZ+gfMU`M7NHPyjErjqO+?-5s z`c_Z?$FfyoGAPt-l?saTQ%aLlQ^1x3jf2P*=ckpFCl;kTrUN6`RtcD6GSl-?ixe^g z5>pfm^$ZR4Oi?wIXQToR!|gSFsKfL@84l($8+{D7+kh1ydmb~yxZgIV7$3$mo z7B0@oymD!l=Hav7-rZfct+M*QuI~0zYZo2qjTisJdPnQJm!Rg(DcO(M_RhP0MWx#B ze5Kv<>T{n<&J`b!JF8{6_!{@l8pnQ?zwd6|m~;E12eaO-jAO##Jh?hDe1TW*(7$)~Uz-xb%bN4`(BiIT;w|be&Zk+=KJtB7rYh{uCC~l+RgvSvY;XT5KTkd? znQ5t#Rp<}S#Wx^I?yT3>Y4TxHF9@6bOdKk^5Y$H(*= zlb${W)fSuu9+AZi4BWyX%*Zfnjs#G!%G1R$#G*GjLE=+`VE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