Initial commit.

master
Robert Zenz 2015-12-06 17:48:21 +01:00
commit e2f019041b
10 changed files with 276 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "deps/utils"]
path = deps/utils
url = https://github.com/minetest-australopithecus/minetest-australopithecus-utils.git

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
Copyright (c) 2014, Robert 'Bobby' Zenz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

43
Makefile Normal file
View File

@ -0,0 +1,43 @@
deps := deps
doc := doc
mod_name := auto_hud_hide
mods := mods
release := release
release_name := auto-hud-hide
all: doc
clean:
$(RM) -R $(doc)
.PHONY: doc
doc:
ldoc --dir=$(doc) mods/$(mod_name)
.PHONY: release
release:
# Prepare the directory structure.
mkdir -p $(release)/
mkdir -p $(release)/$(release_name)/
mkdir -p $(release)/$(release_name)/mods/
# Copy the dependencies.
cp -R $(deps)/utils/utils $(release)/$(release_name)/mods/
# Copy the mods.
cp -R $(mods)/$(mod_name) $(release)/$(release_name)/mods/
# Copy the files.
cp LICENSE $(release)/$(release_name)/
cp README $(release)/$(release_name)/
tar -c --xz -C $(release) -f $(release)/$(release_name).tar.xz $(release_name)/
tar -c --gz -C $(release) -f $(release)/$(release_name).tar.gz $(release_name)/
cd $(release); zip -r -9 $(release_name).zip $(release_name); cd -
.PHONY: update-deps
update-deps:
git submodule foreach git pull origin master
git add $(deps)/
git commit -m "Updated dependencies."

31
README Normal file
View File

@ -0,0 +1,31 @@
minetest-australopithecus-auto-hud-hide
=======================================
A system which automatically hides the HUD if there are no changes.
Usage
-----
The system activates itself, you just need to add the mod to the subgame.
Configuration
-------------
The system can be configured by adding settings to the `minetest.conf`:
# If the system should be activated, defaults to true.
autohudhide_activate = true
# The timeout after which the healthbar is hidden, in seconds, defaults
# to 5 seconds.
autohudhide_healthbar_timeout = 5
# The timeout after which the hotbar is hidden, in seconds, defaults
# to 3 seconds.
autohudhide_hotbar_timeout = 3
# The interval in which the check is run, in seconds, defaults to 0.1.
autohudhide_interval = 0.1

1
README.md Symbolic link
View File

@ -0,0 +1 @@
README

1
deps/utils vendored Submodule

@ -0,0 +1 @@
Subproject commit 517accbba950b2cc0ad55cc297e06743c966e210

View File

@ -0,0 +1,136 @@
--[[
Copyright (c) 2015, Robert 'Bobby' Zenz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--]]
--- A system which automatically hides hud items if there are no changes.
autohudhide = {
--- The timeout after which the healthbar is hidden.
healthbar_timeout = settings.get_number("autohudhide_healthbar_timeout", 5),
--- The timeout after which the hotbar is hidden.
hotbar_timeout = settings.get_number("autohudhide_hotbar_timeout", 3),
--- The infos of players used for determining when to hide elements.
infos = {}
}
--- Activates the system, if it has not been deactivated in the configuration
-- by settings autohudhide_activate to false.
function autohudhide.activate()
if settings.get_bool("autohudhide_activate", true) then
minetest.register_on_leaveplayer(autohudhide.remove_info)
scheduler.schedule(
"autohudhide",
settings.get_number("autohudhide_interval", 0.1),
autohudhide.run,
scheduler.OVERSHOOT_POLICY_RUN_ONCE)
end
end
--- Gets the info for the given player. If there is none, one will be created.
--
-- @param player_name The player for which to get the info.
-- @return The info object for the given player.
function autohudhide.get_info(player)
local info = autohudhide.infos[player:get_player_name()]
if info == nil then
info = {
hotbar_visible = true,
last_hotbar_change = os.time()
}
autohudhide.infos[player:get_player_name()] = info
end
return info
end
--- Removes the info for the given player.
--
-- @param player The player for whom to remove the info.
function autohudhide.remove_info(player)
autohudhide.infos[player:get_player_name()] = nil
end
--- Runs the update on all players.
function autohudhide.run()
for key, player in pairs(minetest.get_connected_players()) do
autohudhide.run_on_player(player)
end
end
--- Runs the update on the given player.
--
-- @param player The player on which to run.
function autohudhide.run_on_player(player)
local info = autohudhide.get_info(player)
autohudhide.update_healthbar(player, info)
autohudhide.update_hotbar(player, info)
end
--- Updates the status of the healthbar for the given player.
--
-- @param player The player which to update.
-- @param info The info for the player.
function autohudhide.update_healthbar(player, info)
local current_health = player:get_hp()
if info.health ~= current_health then
info.health = current_health
info.healthbar_visible = true
info.last_health_change = os.time()
player:hud_set_flags({ healthbar = true })
elseif info.healthbar_visible and (os.time() - info.last_health_change) >= autohudhide.healthbar_timeout then
info.healthbar_visible = false
player:hud_set_flags({ healthbar = false })
end
end
--- Updates the status of the hotbar for the given player.
--
-- @param player The player which to update.
-- @param info The info for the player.
function autohudhide.update_hotbar(player, info)
local current_wield_item = player:get_wielded_item():to_string()
if info.wield_item ~= current_wield_item then
info.hotbar_visible = true
info.last_wield_item_change = os.time()
info.wield_item = current_wield_item
player:hud_set_flags({ hotbar = true })
elseif info.hotbar_visible and (os.time() - info.last_wield_item_change) >= autohudhide.hotbar_timeout then
info.hotbar_visible = false
player:hud_set_flags({ hotbar = false })
end
end

View File

@ -0,0 +1 @@
utils

View File

@ -0,0 +1,35 @@
--[[
Copyright (c) 2015, Robert 'Bobby' Zenz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--]]
local base_path = minetest.get_modpath(minetest.get_current_modname())
dofile(base_path .. "/autohudhide.lua")
autohudhide.activate()

1
mods/utils Symbolic link
View File

@ -0,0 +1 @@
../deps/utils/mods/utils