From b2bb39322a3346052e1093679faa82e1993d082f Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 1 Jan 2020 04:11:02 +0100 Subject: [PATCH 1/8] Update copyright statements to 2020 --- LICENSE.md | 2 +- README.md | 2 +- init.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 0d79608..650a3aa 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # MIT License -Copyright © 2014-2019 4aiman, Hugo Locurcio and contributors +Copyright © 2014-2020 4aiman, Hugo Locurcio and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 0943b8c..b309a9d 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Gauges requires Minetest 5.0.0 or newer to work as expected. ## License -Copyright © 2014-2019 4aiman, Hugo Locurcio and contributors +Copyright © 2014-2020 4aiman, Hugo Locurcio and contributors - Code is licensed under the MIT license, see [`LICENSE.md`](LICENSE.md) for details. diff --git a/init.lua b/init.lua index c7afcbb..082c756 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,6 @@ -- gauges: Adds health/breath bars above players -- --- Copyright © 2014-2019 4aiman, Hugo Locurcio and contributors - MIT License +-- Copyright © 2014-2020 4aiman, Hugo Locurcio and contributors - MIT License -- See `LICENSE.md` included in the source distribution for details. local hp_bar = { From f9471512bd4607465d7d5a6234aed0925056dcde Mon Sep 17 00:00:00 2001 From: Maksim Date: Wed, 1 Jan 2020 13:42:09 +0100 Subject: [PATCH 2/8] Optimize the mod code This also improves formatting to comply with Minetest's Lua code style guidelines. --- init.lua | 90 +++++++++++++++++--------------------- textures/breath_0.png | Bin 131 -> 124 bytes textures/breath_1.png | Bin 170 -> 111 bytes textures/breath_2.png | Bin 171 -> 118 bytes textures/breath_3.png | Bin 167 -> 120 bytes textures/breath_4.png | Bin 162 -> 120 bytes textures/breath_5.png | Bin 155 -> 120 bytes textures/breath_6.png | Bin 151 -> 124 bytes textures/breath_65535.png | Bin 68 -> 0 bytes textures/breath_7.png | Bin 146 -> 126 bytes textures/breath_8.png | Bin 140 -> 126 bytes textures/breath_9.png | Bin 130 -> 126 bytes textures/health_3.png | Bin 107 -> 106 bytes 13 files changed, 40 insertions(+), 50 deletions(-) delete mode 100644 textures/breath_65535.png diff --git a/init.lua b/init.lua index 082c756..3a957b2 100644 --- a/init.lua +++ b/init.lua @@ -3,62 +3,52 @@ -- Copyright © 2014-2020 4aiman, Hugo Locurcio and contributors - MIT License -- See `LICENSE.md` included in the source distribution for details. -local hp_bar = { - physical = false, - collisionbox = {x = 0, y = 0, z = 0}, +if minetest.settings:get_bool("health_bars") == false or + not minetest.settings:get_bool("enable_damage") +then return end + +minetest.register_entity("gauges:hp_bar", { visual = "sprite", - textures = {"20.png"}, -- The texture is changed later in the code - visual_size = {x = 1.5, y = 0.09375, z = 1.5}, -- Y value is (1 / 16) * 1.5 - wielder = nil, -} + visual_size = {x=1, y=1/16, z = 1}, + -- The texture is changed later in the code + textures = {"blank.png"}, + collisionbox = {0}, + physical = false, -function vector.sqdist(a, b) - local dx = a.x - b.x - local dy = a.y - b.y - local dz = a.z - b.z - return dx * dx + dy * dy + dz * dz -end + on_step = function(self) + local player = self.wielder -function hp_bar:on_step(dtime) - local wielder = self.wielder and minetest.get_player_by_name(self.wielder) + if not player or + not minetest.is_player(player) or + vector.distance(player:get_pos(), self.object:get_pos()) > 3 + then + self.object:remove() + return + end - if - wielder == nil or - vector.sqdist(wielder:get_pos(), self.object:get_pos()) > 3 - then - self.object:remove() - return + local hp = player:get_hp() <= 20 and player:get_hp() or 20 + local breath = player:get_breath() <= 10 and player:get_breath() or 11 + + if self.hp ~= hp or self.breath ~= breath then + self.object:set_properties({ + textures = { + "health_"..tostring(hp)..".png^".. + "breath_"..tostring(breath)..".png" + } + }) + self.hp = hp + self.breath = breath + end end +}) - local hp = wielder:get_hp() - local breath = wielder:get_breath() +local function add_gauge(player) + local entity = minetest.add_entity(player:get_pos(), "gauges:hp_bar") - self.object:set_properties({ - textures = { - "health_" .. tostring(hp) .. ".png^breath_" .. tostring(breath) .. ".png", - }, - }) + entity:set_attach(player, "", {x=0, y=19, z=0}, {x=0, y=0, z=0}) + entity:get_luaentity().wielder = player end -minetest.register_entity("gauges:hp_bar", hp_bar) - -local function add_HP_gauge(name) - local player = minetest.get_player_by_name(name) - local pos = player:get_pos() - local ent = minetest.add_entity(pos, "gauges:hp_bar") - - if ent ~= nil then - ent:set_attach(player, "", {x = 0, y = 19, z = 0}, {x = 0, y = 0, z = 0}) - ent = ent:get_luaentity() - ent.wielder = player:get_player_name() - end -end - -if - minetest.settings:get_bool("enable_damage") and - minetest.settings:get_bool("health_bars") ~= false -then - minetest.register_on_joinplayer(function(player) - minetest.after(1, add_HP_gauge, player:get_player_name()) - end) -end +minetest.register_on_joinplayer(function(player) + minetest.after(1, add_gauge, player) +end) diff --git a/textures/breath_0.png b/textures/breath_0.png index 6aeb84e5e58cfea42bc81ce78cf5548400fa4f90..655da8faca6883b4d922a0e86acfd6f27c9d4d49 100644 GIT binary patch delta 94 zcmZo>teKz^!5QEa;`-k?^nYdB*9oo+@+<5Z7#NsKg8YL2|7W;zopr E0Bdt3WB>pF diff --git a/textures/breath_1.png b/textures/breath_1.png index 5182fc8aac9eac2685af0342b01b12f5b3e21ffe..724d6002c6185a26d45efd2aa686a869c7ae6da8 100644 GIT binary patch delta 93 zcmZ3*m_I=xoROJ44o^Chr0`kN> uT^vIy7?Tqce)Ka+y!y|-Kp{+>k>T*~8L4k#BRGI67(8A5T-G@yGywpRJ|8Op delta 153 zcmc~_#W+Eto`so#fuU#J%eg>GF~BFp6-fJT_!_tNN%pGiWh>8Ap7`H(^wY#6&u1OF z_p0&x6YuXg`Hn6ED&i^$@(TviP*A);A_K_O^K@|x(U_PVbCiMc{lYI<8gHA9r583_ w*l(UNz5S!4xQao5@PFVdQ&MBb@0DbBp A`v3p{ delta 154 zcmXS0%{W1#o`so#fuU#J%eg>GF~BFp6-fJT_!_tNN%pGiWh>8Ap7`H(^wY#6&u1OF z_r&}AtH$ruT5f4TMVuu;e!)N*0*X^+F9fm-JY5_^G$tm`Imy7-6i_8LrL6JN>V+oV z%q{=+GVZqNId8GBp>bA2>6HTqGZeN?=4BAEIv{ZI!i4{oAY(jT{an^LB{Ts5t2I6K diff --git a/textures/breath_3.png b/textures/breath_3.png index dc787dff93732632a12115087d52f6a498df5de1..19f0d5c8b031b8fcc66242c80b64993d367d2f60 100644 GIT binary patch delta 102 zcmZ3^STR8&fr*)cfr0s*j4hDj4DbnYT~+x1(9Hj{4&5^|-8c&*R}$nG{Qp10^;5i# zK(4f>i(^OyV=_ZyfC9tC)gKtxbXCrE1bUQwU|=}@=ZNKt;C-w>WelFKelF{r5}E+p COd~-6 delta 150 zcmbGF2EbP0l+XkKDA+e? diff --git a/textures/breath_4.png b/textures/breath_4.png index f22fdac2308f60227235f830dd7913ca9ed49e43..7687f2452a6894d9371afa277527b4f387aa5588 100644 GIT binary patch delta 102 zcmZ3)STR8&fr*)cfr0s*j4hDj4DbnYEnIbR)}edZtFCYUvx^BNR}$nG{Qp10^;5i# zK(4f>i(^OyV=_ZyfI`E?)ddV}x+aZ+3n#pIz{tQ7dvKzBQw$qW8H1;*pUXO@geCyM Cts#~G delta 145 zcmbGI>0By6-fJT_!_tNN%pGil_&nU9sM-%$n(Ng7iS&1 zC(h;e7bwkM666;Qq(LAwN&5 q#6ZL#Ky*Wol!XNElCn*V3{F~>oHK2@x*52Enmt|pT-G@yGywo!qAmsi diff --git a/textures/breath_5.png b/textures/breath_5.png index bc7e23f68e263edaaa1c94ad6bf6cb1477744908..44921fcbf7a1838b85451a3b4aea735d30928182 100644 GIT binary patch delta 102 zcmbQuSTR8&fr*)cfr0s*j4hDj4DbnY&0ckV+TlkNk36r*%xnY6l?3?(|NqZ${S>bw zkSp!!;uuoFn9R@^py04GBEToa6-fJT_!_tNN#%+EZAU*%Jn}qy)%9tIA4Rj9 z>;%fOl?3?(18E@0TgE;SNa=XGIEH9UO!jDQD$+P`)StJtK|z(HppnT@!=R0+jfHI$ j)3ZQk_Qj1?{LC0OEj2m(v~?CINWZ76p9{-6r-UW|L;x>a diff --git a/textures/breath_6.png b/textures/breath_6.png index 3396ea65b3beed6ea12e384b25ea5ea1cdd00e4f..1b29fc3d6a8062431aaab148f1ad81792209b2e8 100644 GIT binary patch delta 106 zcmbQvSTjK)g^8Jgfr0s*j4hDj4DbnYO|Yh%eZt&jr?wsNscoa5@`lVflS-Z67my-W#EDTAl0pUXO@ GgeCxHVk4yh delta 133 zcmb=K&NxA$o`so#fuU#J%eg>GG{7gs6-fJT_!_tNN#%+EZAU+)uDLt$$aAseAReFu zYe|q_Fpy?oIF!w{5lHEHx;TbtOibozZ8Fg~aFoCK)8r`%2UxjS79Nn`l3Zci7-5DwYogajamnSs&YgKIsI O#o+1c=d#Wzp$Pyq!wQA~ diff --git a/textures/breath_7.png b/textures/breath_7.png index 03dbd4ab8110608853aa6904de8733d454c0b960..7447afbdfbae656b9a71cbe8deb57f9093f17199 100644 GIT binary patch delta 108 zcmbQlST{i;jft6ofr0s*j4hDj4DbnYja&Pq=jfZZqo1_@%=`nAD+%%o{{Nrh`YB#V zAXm}T#WAFUF`1z;K*3>|YvUH?3306~5?jI^vK~8JYD@< J);T3K0RZ3DC7J*L delta 128 zcmb=M#5h5siiMehfuU#J%eg>GD8MJg6-fJT_*!}5f7{VdaciIS9DP%FCm{qV%2E>K z7Yw8sHcw8Q1*Eh+T^vI+CMFj&HU(%LI9lHN$$3FdvW7qlld48SLBay91S!)311XQU aDa;I4S83e67al7F((dW%=d#Wzp$Pzp7%fQv diff --git a/textures/breath_8.png b/textures/breath_8.png index 6c4b40cd0d679a276632b851a4260e4525ae11b4..5bae595bf754a8c1f32127351a9f3ed73db7482a 100644 GIT binary patch delta 108 zcmeBSteYT_#>C9Pz`*=Y#ui9%2Ka=yhOK+kcJ!0)hOfEj1*Ac8B|(0{|Nk>wKgH_^ z&CZJ*lPgg&e IbxsLQ0At=HIsgCw delta 122 zcmb>HVVodQ!otkJz|gbq3Z#8Ee62k3KWyEbwxgexZF`Xl6k;w3@(Tvi zzsio>15%ovE{-7@6O#?vn8Y;>95rwJH22~Y)`bq7ToODIE4XI3@yhhD1zF!@U^sJG VN%qXoge5>t44$rjF6*2UngCyfD-{3$ diff --git a/textures/breath_9.png b/textures/breath_9.png index 22edb2d4dd891be78d07a1591ecbe4b6850ca238..3ac93a0beb2f07b2535932d6efe80435b96bb7a2 100644 GIT binary patch delta 96 zcmZo-tec<`#Tnoe;_AEMYs2v$l_&n&M;Nj(FfcHe1o;L3|Icv!6t5$YtLW+C7*fHQ z%+MI1;IPcKaSO9hy{Lde##$wwwz*D=n%NniaIXn`m%thdRLtP%>gTe~DWM4fgZUtr delta 100 zcmby6lP=6-?wqcmU!L)Ze$5y7VZ28~h@0V$ X*UiaA(b}(piWody{an^LB{Ts57t$9h delta 68 zcmd1Go}goIY;3&4#N?~1YiLxx3T@~P@kW!(kBF4a= X6B#pGX6FkvpehDWS3j3^P6 Date: Wed, 1 Jan 2020 17:34:23 +0100 Subject: [PATCH 3/8] Add a project changelog --- CHANGELOG.md | 14 ++++++++++++++ README.md | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..855f54d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## 1.0.0 - 2020-01-01 + +- Initial versioned release. + +[Unreleased]: https://github.com/minetest-mods/gauges/compare/v1.0.0...HEAD diff --git a/README.md b/README.md index b309a9d..7236c37 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,9 @@ on that line. ## Version compatibility -Gauges requires Minetest 5.0.0 or newer to work as expected. +Gauges is currently primarily tested with Minetest 5.1.0. It may or may not work +with newer or older versions. Issues arising in versions older than 5.0.0 +will generally not be fixed. ## License From 29a7dabe8d6b55278eb73e03c84d6333b893eda5 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 1 Jan 2020 17:53:37 +0100 Subject: [PATCH 4/8] Add a preview screenshot at the top of the README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7236c37..f57c1b8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Gauges +![Preview](https://content.minetest.net/uploads/GBoKauWSou.png) + Gauges for [Minetest](https://www.minetest.net/), a free and open source infinite world block sandbox game. From f7be847de4ad92b5dc150f041462ab0cd9b836ac Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 1 Jan 2020 17:54:24 +0100 Subject: [PATCH 5/8] Remove obsolete notice about renaming the extracted mod folder This is no longer required thanks to `mod.conf`. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index f57c1b8..89e326f 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,7 @@ git clone https://github.com/minetest-mods/gauges.git You can also [download a ZIP archive](https://github.com/minetest-mods/gauges/archive/master.zip) -of Gauges. If you do so, you will need to extract the archive then rename -the resulting folder from `gauges-master` to `gauges` – this is -**absolutely** required, as the mod won't work otherwise. +of Gauges. ### Enable the mod From c28b6a9f358b3c986334928e47ca78b6368d87c3 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 1 Jan 2020 18:03:08 +0100 Subject: [PATCH 6/8] Fix a code style issue --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 3a957b2..f8be2c1 100644 --- a/init.lua +++ b/init.lua @@ -9,7 +9,7 @@ then return end minetest.register_entity("gauges:hp_bar", { visual = "sprite", - visual_size = {x=1, y=1/16, z = 1}, + visual_size = {x=1, y=1/16, z=1}, -- The texture is changed later in the code textures = {"blank.png"}, collisionbox = {0}, From 7c3afd699cda81b464731395824d8dc010a0c9f9 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 1 Jan 2020 18:06:03 +0100 Subject: [PATCH 7/8] Localize the `vector.distance` function for performance --- CHANGELOG.md | 4 ++++ init.lua | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 855f54d..5c75c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- Improve performance by localizing the `vector.distance()` function. + ## 1.0.0 - 2020-01-01 - Initial versioned release. diff --git a/init.lua b/init.lua index f8be2c1..98c76d6 100644 --- a/init.lua +++ b/init.lua @@ -7,6 +7,10 @@ if minetest.settings:get_bool("health_bars") == false or not minetest.settings:get_bool("enable_damage") then return end +-- Localize the vector distance function for better performance, as it's called +-- on every step +local vector_distance = vector.distance + minetest.register_entity("gauges:hp_bar", { visual = "sprite", visual_size = {x=1, y=1/16, z=1}, @@ -20,7 +24,7 @@ minetest.register_entity("gauges:hp_bar", { if not player or not minetest.is_player(player) or - vector.distance(player:get_pos(), self.object:get_pos()) > 3 + vector_distance(player:get_pos(), self.object:get_pos()) > 3 then self.object:remove() return From 1990169c0ab79bdd387fc9ce458ef8fb5130a129 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 1 Jan 2020 18:08:11 +0100 Subject: [PATCH 8/8] Bump to version 1.0.1 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c75c48..e6b46da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [1.0.1] - 2020-01-01 + ### Changed - Improve performance by localizing the `vector.distance()` function. @@ -15,4 +17,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Initial versioned release. -[Unreleased]: https://github.com/minetest-mods/gauges/compare/v1.0.0...HEAD +[Unreleased]: https://github.com/minetest-mods/gauges/compare/v1.0.1...HEAD +[1.0.1]: https://github.com/minetest-mods/gauges/compare/v1.0.0...v1.0.1