Initial commit.

master
David G 2019-10-28 11:21:52 -07:00
commit c3a28ad188
20 changed files with 109 additions and 0 deletions

40
README.md Normal file
View File

@ -0,0 +1,40 @@
HUD Compass [hud_compass]
-------------------------
A Minetest mod to optionally place a HUD compass in the bottom right corner of the screen.
By David G (kestral246)
![HUD Compass Screenshot](screenshot.jpeg "hud_compass")
How to enable
-------------
This mod defaults to not displaying compass. To enable, use the chat command:
> "/compass"
Repeated use of this command will toggle the compass display off and on.
Local mod storage is used to maintain state of hud_compass display between sessions, per user.
Licenses
--------
Source code
> The MIT License (MIT)
Media (textures)
> Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
> (Textures were copied from my realcompass mod, which were originally based on the textures created by tacotexmex for the ccompass mod.)

67
init.lua Normal file
View File

@ -0,0 +1,67 @@
-- hud_compass
-- Optionally place a compass on the screen.
-- A HUD version of my realcompass mod.
-- By David_G (kestral246@gmail.com)
-- 2019-10-28
local hud_compass = {}
local storage = minetest.get_mod_storage()
minetest.register_on_joinplayer(function(player)
local pname = player:get_player_name()
local is_enabled = false
if storage:get(pname) and storage:get(pname) == "1" then
is_enabled = true
end
hud_compass[pname] = {
id = player:hud_add({
hud_elem_type = "image",
text = "",
position = {x=1.0, y=1.0},
scale = {x=4, y=4},
alignment = {x=-1, y=-1},
offset = {x=-8, y=-4}
}),
last_image = -1,
enabled = is_enabled,
}
end)
minetest.register_chatcommand("compass", {
params = "",
description = "Toggle display of hud compass.",
privs = {},
func = function(pname, param)
local player = minetest.get_player_by_name(pname)
if hud_compass[pname].enabled == true then -- is enabled
hud_compass[pname].enabled = false -- toggle to disabled
player:hud_change(hud_compass[pname].id, "text", "") -- blank hud
storage:set_string(pname, "0")
else -- is disabled
hud_compass[pname].enabled = true -- toggle to enabled
storage:set_string(pname, "1")
end
end,
})
minetest.register_on_leaveplayer(function(player)
local pname = player:get_player_name()
if hud_compass[pname] then
hud_compass[pname] = nil
end
end)
minetest.register_globalstep(function(dtime)
local players = minetest.get_connected_players()
for i,player in ipairs(players) do
local pname = player:get_player_name()
local dir = player:get_look_horizontal()
local angle_relative = math.deg(dir)
local image = math.floor((angle_relative/22.5) + 0.5)%16
if hud_compass[pname].enabled and image ~= hud_compass[pname].last_image then
player:hud_change(hud_compass[pname].id, "text", "realcompass_"..image..".png")
hud_compass[pname].last_image = image
end
end
end)

2
mod.conf Normal file
View File

@ -0,0 +1,2 @@
name = hud_compass
description = Optionally place a HUD compass on the screen.

BIN
screenshot.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

BIN
textures/realcompass_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/realcompass_9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB