2 Commits

Author SHA1 Message Date
478402dda9 Replace Travis CI with GitHub Actions (#12) 2023-08-31 20:50:04 +02:00
98f346882d Fix crash on math.round field as nil (#11)
Co-authored-by: sys4 <bricassa@sys4.fr>
2021-11-10 01:20:25 +01:00
3 changed files with 27 additions and 18 deletions

20
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,20 @@
name: build
on: [push, pull_request]
jobs:
luacheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -qqq luarocks
- name: Install LuaCheck and pre-commit
run: |
pip3 install pre-commit
luarocks install --local luacheck
- name: Run LuaCheck with pre-commit
run: |
export PATH="$HOME/.luarocks/bin:$PATH"
pre-commit run --all-files

View File

@ -1,16 +0,0 @@
dist: bionic
language: python
python:
- 3.7.1
install:
- sudo apt-get update -qq
- sudo apt-get install -qqq luarocks
- pip3 install pre-commit
- luarocks install --local luacheck
script:
# All linters are run with pre-commit hooks
- export PATH="$HOME/.luarocks/bin:$PATH"
- pre-commit run --all-files

View File

@ -3,6 +3,10 @@
-- Copyright © 2014-2020 4aiman, Hugo Locurcio and contributors - MIT License
-- See `LICENSE.md` included in the source distribution for details.
local function round(v)
return math.floor(v + 0.5)
end
local enabled = minetest.settings:get_bool("health_bars") ~= false
if enabled then
enabled = minetest.settings:get_bool("enable_damage")
@ -31,12 +35,13 @@ local function add_gauge(player)
end
end
-- credit: https://github.com/minetest/minetest/blob/6de8d77e17017cd5cc7b065d42566b6b1cd076cc/builtin/game/statbars.lua#L30-L37
-- credit:
-- https://github.com/minetest/minetest/blob/master/builtin/game/statbars.lua#L31-L37
local function scaleToDefault(player, field)
-- Scale "hp" or "breath" to supported amount
local current = player["get_" .. field](player)
local max_display = math.max(player:get_properties()[field .. "_max"], current)
return math.round(current / max_display * max[field])
return round(current / max_display * max[field])
end
minetest.register_entity("gauges:hp_bar", {