Initial commit

This commit is contained in:
stujones11 2014-08-10 21:04:17 +01:00
commit b0455a5f25
11 changed files with 225 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
## Generic ignorable patterns and files
*~
.*.swp
*bak*
tags
*.vim

28
README.txt Normal file
View File

@ -0,0 +1,28 @@
Minetest Mod - HUD Map [hudmap]
===============================
Mod Version: 0.1.0
Minetest Version: 0.4.8 or later (untested on older versions)
Depends: none
License Code: LGPL v2.1
License Textures: WTFPL
Adds a scalable overhead map to the player's HUD.
Map images must be supplied by the server admin and configured in hudmap.conf.
See hudmap.conf.example for a demo setup featuring the fantastic Karsthafen map.
https://forum.minetest.net/viewtopic.php?f=12&t=6642
Chat Commands
-------------
/hudmap on - Display HUD Map
/hudmap off - Remove HUD Map
/hudmap scale [number] - Set Hudmap Scale (default 1)

0
depends.txt Normal file
View File

43
hudmap.conf.example Normal file
View File

@ -0,0 +1,43 @@
-- Hudmap config example (defaults)
-- Hudmap refresh rate
HUDMAP_UPDATE_TIME = 2
-- Pixel size of the player marker texture
HUDMAP_MARKER_SIZE = {x=15, y=15}
-- Default texture when no map is available
HUDMAP_DEFAULT_TEXTURE = "hudmap_default.png"
-- Default user preferences
HUDMAP_DEFAULT_PREFS = {visible=true, scale=1}
-- Karsthafen example maps
hudmap:register_map("world", {
size = {x=320, y=320},
minp = {x=-2000, y=-1000, z=-2000},
maxp = {x=2000, y=30000, z=2000},
texture = "karsthafen_world.png",
})
hudmap:register_map("karsthafen", {
size = {x=320, y=320},
minp = {x=346, y=-1000, z=306},
maxp = {x=666, y=30000, z=626},
texture = "karsthafen_town.png",
})
hudmap:register_map("tennis_courts", {
size = {x=320, y=320},
minp = {x=63, y=-1000, z=-361},
maxp = {x=383, y=30000, z=-41},
texture = "karsthafen_tennis.png",
})
hudmap:register_map("spawn", {
size = {x=320, y=320},
minp = {x=-61, y=-1000, z=-64},
maxp = {x=67, y=30000, z=64},
texture = "karsthafen_spawn.png",
})

147
init.lua Normal file
View File

@ -0,0 +1,147 @@
hudmap = {
id = {},
map = {},
pref = {},
}
HUDMAP_UPDATE_TIME = 2
HUDMAP_MARKER_SIZE = {x=15, y=15}
HUDMAP_DEFAULT_TEXTURE = "hudmap_default.png"
HUDMAP_DEFAULT_PREFS = {visible=true, scale=1}
function hudmap:register_map(name, def)
local scale_size = {
x = def.maxp.x - def.minp.x,
z = def.maxp.z - def.minp.z,
}
local map = {
name = name,
size = def.size,
minp = def.minp,
maxp = def.maxp,
area = scale_size.x * scale_size.z,
texture = def.texture,
scale = {
x = scale_size.x / def.size.x,
y = scale_size.z / def.size.y,
},
}
table.insert(hudmap.map, map)
table.sort(hudmap.map, function(a, b) return a.area < b.area end)
end
local modpath = minetest.get_modpath(minetest.get_current_modname())
local input = io.open(modpath.."/hudmap.conf", "r")
if input then
dofile(modpath.."/hudmap.conf")
input:close()
input = nil
end
local timer = 0
local marker_offset = {
x = math.ceil(HUDMAP_MARKER_SIZE.x / 2),
y = math.ceil(HUDMAP_MARKER_SIZE.y / 2),
}
local function get_map_texture(player)
local texture = HUDMAP_DEFAULT_TEXTURE
local pos = player:getpos()
if pos then
local map = nil
for _, v in ipairs(hudmap.map) do
if pos.x >= v.minp.x and pos.x <= v.maxp.x and
pos.y >= v.minp.y and pos.y <= v.maxp.y and
pos.z >= v.minp.z and pos.z <= v.maxp.z then
map = v
break
end
end
if map then
local x = pos.x - map.minp.x
local y = pos.z - map.minp.z
x = x / map.scale.x - marker_offset.x
y = map.size.y - y / map.scale.y - marker_offset.y
texture = "[combine:"..map.size.x.."x"..map.size.y..
":0,0,="..map.texture..":"..x..","..y..",=hudmap_marker.png"
end
end
return texture
end
local function update_hud(player)
local name = player:get_player_name()
if hudmap.id[name] then
player:hud_change(hudmap.id[name], "text", get_map_texture(player))
else
local scale = hudmap.pref[name].scale
hudmap.id[name] = player:hud_add({
hud_elem_type = "image",
position = {x=1,y=0},
scale = {x=scale, y=scale},
text = get_map_texture(player),
offset = {x=0,y=0},
alignment = {x=-1,y=1},
})
end
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
hudmap.pref[name] = HUDMAP_DEFAULT_PREFS
minetest.after(1, function(player)
if player then
if hudmap.pref[name].visible == true then
update_hud(player)
end
end
end, player)
end)
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer > HUDMAP_UPDATE_TIME then
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
if hudmap.pref[name].visible == true then
update_hud(player)
end
end
timer = 0
end
end)
minetest.register_chatcommand("hudmap", {
params = "<cmd> [args]",
description = "Hudmap",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if param == nil or player == nil then
return
end
local cmd, args = string.match(param, "([^ ]+) (.+)")
cmd = cmd or param
if cmd == "on" then
hudmap.pref[name].visible = true
update_hud(player)
elseif cmd == "off" then
hudmap.pref[name].visible = false
player:hud_remove(hudmap.id[name])
hudmap.id[name] = nil
elseif cmd == "scale" then
if args then
scale = tonumber(args)
if scale then
if scale > 0 then
hudmap.pref[name].scale = scale
player:hud_remove(hudmap.id[name])
hudmap.id[name] = nil
update_hud(player)
return
end
end
end
minetest.chat_send_player(name, "Invalid scale!")
end
end,
})

BIN
textures/hudmap_default.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

BIN
textures/hudmap_marker.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB