commit c3a28ad18880ffe1ce6a99d74f7b721ea7bf23f9 Author: David G Date: Mon Oct 28 11:21:52 2019 -0700 Initial commit. diff --git a/README.md b/README.md new file mode 100644 index 0000000..39ca86a --- /dev/null +++ b/README.md @@ -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.) + + + + + + + + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..24da21a --- /dev/null +++ b/init.lua @@ -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) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..c10228d --- /dev/null +++ b/mod.conf @@ -0,0 +1,2 @@ +name = hud_compass +description = Optionally place a HUD compass on the screen. diff --git a/screenshot.jpeg b/screenshot.jpeg new file mode 100644 index 0000000..f6d0b70 Binary files /dev/null and b/screenshot.jpeg differ diff --git a/textures/realcompass_0.png b/textures/realcompass_0.png new file mode 100644 index 0000000..e4d53bc Binary files /dev/null and b/textures/realcompass_0.png differ diff --git a/textures/realcompass_1.png b/textures/realcompass_1.png new file mode 100644 index 0000000..3251d19 Binary files /dev/null and b/textures/realcompass_1.png differ diff --git a/textures/realcompass_10.png b/textures/realcompass_10.png new file mode 100644 index 0000000..75991b8 Binary files /dev/null and b/textures/realcompass_10.png differ diff --git a/textures/realcompass_11.png b/textures/realcompass_11.png new file mode 100644 index 0000000..b154a1c Binary files /dev/null and b/textures/realcompass_11.png differ diff --git a/textures/realcompass_12.png b/textures/realcompass_12.png new file mode 100644 index 0000000..0832ca8 Binary files /dev/null and b/textures/realcompass_12.png differ diff --git a/textures/realcompass_13.png b/textures/realcompass_13.png new file mode 100644 index 0000000..975bd20 Binary files /dev/null and b/textures/realcompass_13.png differ diff --git a/textures/realcompass_14.png b/textures/realcompass_14.png new file mode 100644 index 0000000..34e0005 Binary files /dev/null and b/textures/realcompass_14.png differ diff --git a/textures/realcompass_15.png b/textures/realcompass_15.png new file mode 100644 index 0000000..b128569 Binary files /dev/null and b/textures/realcompass_15.png differ diff --git a/textures/realcompass_2.png b/textures/realcompass_2.png new file mode 100644 index 0000000..4feaf78 Binary files /dev/null and b/textures/realcompass_2.png differ diff --git a/textures/realcompass_3.png b/textures/realcompass_3.png new file mode 100644 index 0000000..d72c8a2 Binary files /dev/null and b/textures/realcompass_3.png differ diff --git a/textures/realcompass_4.png b/textures/realcompass_4.png new file mode 100644 index 0000000..fd6c516 Binary files /dev/null and b/textures/realcompass_4.png differ diff --git a/textures/realcompass_5.png b/textures/realcompass_5.png new file mode 100644 index 0000000..1722beb Binary files /dev/null and b/textures/realcompass_5.png differ diff --git a/textures/realcompass_6.png b/textures/realcompass_6.png new file mode 100644 index 0000000..3f3ae53 Binary files /dev/null and b/textures/realcompass_6.png differ diff --git a/textures/realcompass_7.png b/textures/realcompass_7.png new file mode 100644 index 0000000..f16bd29 Binary files /dev/null and b/textures/realcompass_7.png differ diff --git a/textures/realcompass_8.png b/textures/realcompass_8.png new file mode 100644 index 0000000..a7ee00a Binary files /dev/null and b/textures/realcompass_8.png differ diff --git a/textures/realcompass_9.png b/textures/realcompass_9.png new file mode 100644 index 0000000..35740c8 Binary files /dev/null and b/textures/realcompass_9.png differ