Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rhotator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
rhotator
Commits
8ffef59d
Commit
8ffef59d
authored
6 years ago
by
entuland
Browse files
Options
Downloads
Patches
Plain Diff
moved and improved notification facility
parent
91064a37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
init.lua
+8
-57
8 additions, 57 deletions
init.lua
notify.lua
+72
-0
72 additions, 0 deletions
notify.lua
with
80 additions
and
57 deletions
init.lua
+
8
−
57
View file @
8ffef59d
...
...
@@ -2,6 +2,7 @@ rhotator = {}
local
mod_path
=
minetest
.
get_modpath
(
minetest
.
get_current_modname
())
local
storage
=
minetest
.
get_mod_storage
()
local
notify
=
dofile
(
mod_path
..
"/notify.lua"
)
-- constants
...
...
@@ -26,9 +27,6 @@ rhotator.SECONDARY_BTN = SECONDARY_BTN
local
rot_matrices
=
{}
local
dir_matrices
=
{}
local
huds
=
{}
local
hud_timeout_seconds
=
3
local
facedir_memory
=
{}
-- ============================================================
...
...
@@ -187,52 +185,6 @@ local function vector_to_dir_index(vec)
return
(
vec
.
y
>
0
)
and
POS
.
Y
or
NEG
.
Y
end
-- ============================================================
-- hud functions
local
function
hud_remove
(
player
)
local
playername
=
player
:
get_player_name
()
local
hud
=
huds
[
playername
]
if
not
hud
then
return
end
if
os.time
()
<
hud_timeout_seconds
+
hud
.
time
then
return
end
player
:
hud_remove
(
hud
.
id
)
huds
[
playername
]
=
nil
end
local
function
hud_create
(
player
,
message
)
local
playername
=
player
:
get_player_name
()
local
id
=
player
:
hud_add
({
text
=
message
,
hud_elem_type
=
"text"
,
name
=
"rhotator_feedback"
,
direction
=
0
,
position
=
{
x
=
0
.
1
,
y
=
0
.
9
},
alignment
=
{
x
=
1
,
y
=
-
1
},
number
=
0xFFFFFF
,
})
huds
[
playername
]
=
{
id
=
id
,
time
=
os.time
(),
}
end
local
function
notify
(
player
,
message
)
message
=
"[rhotator] "
..
message
local
playername
=
player
:
get_player_name
()
local
hud
=
huds
[
playername
]
if
not
hud
then
hud_create
(
player
,
message
)
else
player
:
hud_change
(
hud
.
id
,
"text"
,
message
)
hud
.
time
=
os.time
()
end
minetest
.
after
(
hud_timeout_seconds
,
function
()
hud_remove
(
player
)
end
)
end
-- ============================================================
-- rhotator main
...
...
@@ -402,10 +354,9 @@ local function interact(player, pointed_thing, click)
if
pointed_thing
.
type
~=
"node"
then
return
end
local
pos
=
pointed_thing
.
under
if
minetest
.
is_protected
(
pos
,
player
:
get_player_name
())
then
notify
(
player
,
"You're not authorized to alter nodes in this area"
)
notify
.
error
(
player
,
"You're not authorized to alter nodes in this area"
)
minetest
.
record_protection_violation
(
pos
,
player
:
get_player_name
())
return
end
...
...
@@ -414,12 +365,12 @@ local function interact(player, pointed_thing, click)
local
nodedef
=
minetest
.
registered_nodes
[
node
.
name
]
if
not
nodedef
then
notify
(
player
,
"Unsupported node type: "
..
node
.
name
)
notify
.
error
(
player
,
"Unsupported node type: "
..
node
.
name
)
return
end
local
handler
=
handlers
[
nodedef
.
paramtype2
]
-- Node provides a handler, so let the handler decide instead if the node can be rotated
if
nodedef
.
on_rotate
then
-- Copy pos and node because callback can modify it
...
...
@@ -430,17 +381,17 @@ local function interact(player, pointed_thing, click)
notify
(
player
,
"Rotation reportedly performed by on_rotate()"
)
return
else
notify
(
player
,
"Rotation disallowed by on_rotate() return value"
)
notify
.
warning
(
player
,
"Rotation disallowed by on_rotate() return value"
)
return
end
elseif
nodedef
.
on_rotate
==
false
then
notify
(
player
,
"Rotation prevented by on_rotate == false"
)
notify
.
warning
(
player
,
"Rotation prevented by on_rotate == false"
)
return
elseif
nodedef
.
can_dig
and
not
nodedef
.
can_dig
(
pos
,
player
)
then
notify
(
player
,
"Rotation prevented by can_dig() checks"
)
notify
.
warning
(
player
,
"Rotation prevented by can_dig() checks"
)
return
elseif
not
handler
then
notify
(
player
,
"Cannot rotate node with paramtype2 == "
..
nodedef
.
paramtype2
)
notify
.
warning
(
player
,
"Cannot rotate node with paramtype2 == "
..
nodedef
.
paramtype2
)
return
end
...
...
This diff is collapsed.
Click to expand it.
notify.lua
0 → 100644
+
72
−
0
View file @
8ffef59d
local
mod_name
=
minetest
.
get_current_modname
()
local
huds
=
{}
local
hud_timeout_seconds
=
3
-- defaults
local
position
=
{
x
=
0
.
1
,
y
=
0
.
9
}
local
alignment
=
{
x
=
1
,
y
=
-
1
}
local
normal_color
=
0xFFFFFF
local
warning_color
=
0xFFFF00
local
error_color
=
0xDD0000
local
direction
=
0
local
notify
=
{}
notify
.
__index
=
notify
setmetatable
(
notify
,
notify
)
local
function
hud_remove
(
player
)
local
playername
=
player
:
get_player_name
()
local
hud
=
huds
[
playername
]
if
not
hud
then
return
end
if
os.time
()
<
hud_timeout_seconds
+
hud
.
time
then
return
end
player
:
hud_remove
(
hud
.
id
)
huds
[
playername
]
=
nil
end
local
function
hud_create
(
player
,
message
,
params
)
local
playername
=
player
:
get_player_name
()
local
def
=
type
(
params
)
==
"table"
and
params
or
{}
def
.
position
=
def
.
position
or
position
def
.
alignment
=
def
.
alignment
or
alignment
def
.
number
=
def
.
number
or
def
.
color
or
normal_color
def
.
color
=
nil
def
.
position
=
def
.
position
or
position
def
.
direction
=
def
.
direction
or
direction
def
.
text
=
message
or
def
.
text
def
.
hud_elem_type
=
def
.
hud_elem_type
or
"text"
def
.
name
=
mod_name
..
"_feedback"
local
id
=
player
:
hud_add
(
def
)
huds
[
playername
]
=
{
id
=
id
,
time
=
os.time
(),
}
end
notify
.
warn
=
function
(
player
,
message
)
notify
(
player
,
message
,
{
color
=
warning_color
})
end
notify
.
warning
=
notify
.
warn
notify
.
err
=
function
(
player
,
message
)
notify
(
player
,
message
,
{
color
=
error_color
})
end
notify
.
error
=
notify
.
err
notify
.
__call
=
function
(
self
,
player
,
message
,
params
)
message
=
"["
..
mod_name
..
"] "
..
message
local
playername
=
player
:
get_player_name
()
local
hud
=
huds
[
playername
]
if
hud
then
player
:
hud_remove
(
hud
.
id
)
end
hud_create
(
player
,
message
,
params
)
minetest
.
after
(
hud_timeout_seconds
,
function
()
hud_remove
(
player
)
end
)
end
return
notify
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment