mirror of
https://repo.or.cz/minetest_orienteering.git
synced 2024-11-05 06:33:44 +01:00
Add 12-hour clock mode (use watch to toggle modes)
This commit is contained in:
parent
f1300e118d
commit
50583fbdd3
28
init.lua
28
init.lua
@ -34,6 +34,15 @@ minetest.register_tool("orienteering:watch", {
|
|||||||
description = "Watch",
|
description = "Watch",
|
||||||
wield_image = "orienteering_watch.png",
|
wield_image = "orienteering_watch.png",
|
||||||
inventory_image = "orienteering_watch.png",
|
inventory_image = "orienteering_watch.png",
|
||||||
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
local name = user:get_player_name()
|
||||||
|
if orienteering.playerhuds[name].twelve then
|
||||||
|
orienteering.playerhuds[name].twelve = false
|
||||||
|
else
|
||||||
|
orienteering.playerhuds[name].twelve = true
|
||||||
|
end
|
||||||
|
update_hud_displays(user)
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Displays speed
|
-- Displays speed
|
||||||
@ -84,11 +93,14 @@ function init_hud(player)
|
|||||||
scale= { x = 100, y = 20 },
|
scale= { x = 100, y = 20 },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
orienteering.playerhuds[name].twelve = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_hud_displays(player)
|
function update_hud_displays(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local gps, altimeter, triangulator, compass, sextant, watch, speedometer
|
local gps, altimeter, triangulator, compass, sextant, watch, speedometer
|
||||||
|
|
||||||
if inv:contains_item("main", "orienteering:gps") then
|
if inv:contains_item("main", "orienteering:gps") then
|
||||||
gps = true
|
gps = true
|
||||||
end
|
end
|
||||||
@ -140,7 +152,22 @@ function update_hud_displays(player)
|
|||||||
local totalminutes = time * 1440
|
local totalminutes = time * 1440
|
||||||
local hours = math.floor(totalminutes / 60)
|
local hours = math.floor(totalminutes / 60)
|
||||||
local minutes = math.floor(math.fmod(totalminutes, 60))
|
local minutes = math.floor(math.fmod(totalminutes, 60))
|
||||||
|
local twelve = orienteering.playerhuds[name].twelve
|
||||||
|
if twelve then
|
||||||
|
local ampm
|
||||||
|
if hours == 12 and minutes == 0 then
|
||||||
|
str_time = "Time: noon"
|
||||||
|
elseif hours == 0 and minutes == 0 then
|
||||||
|
str_time = "Time: midnight"
|
||||||
|
else
|
||||||
|
if hours >= 12 then ampm = "p.m." else ampm = "a.m." end
|
||||||
|
hours = math.fmod(hours, 12)
|
||||||
|
if hours == 0 then hours = 12 end
|
||||||
|
str_time = string.format("Time: %i:%02i %s", hours, minutes, ampm)
|
||||||
|
end
|
||||||
|
else
|
||||||
str_time = string.format("Time: %02i:%02i", hours, minutes)
|
str_time = string.format("Time: %02i:%02i", hours, minutes)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
str_time = ""
|
str_time = ""
|
||||||
end
|
end
|
||||||
@ -151,7 +178,6 @@ function update_hud_displays(player)
|
|||||||
str_speed = ""
|
str_speed = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = player:get_player_name()
|
|
||||||
player:hud_change(orienteering.playerhuds[name].pos, "text", str_pos)
|
player:hud_change(orienteering.playerhuds[name].pos, "text", str_pos)
|
||||||
player:hud_change(orienteering.playerhuds[name].angles, "text", str_angles)
|
player:hud_change(orienteering.playerhuds[name].angles, "text", str_angles)
|
||||||
player:hud_change(orienteering.playerhuds[name].time, "text", str_time)
|
player:hud_change(orienteering.playerhuds[name].time, "text", str_time)
|
||||||
|
Loading…
Reference in New Issue
Block a user