add settings, refine behavior
This commit is contained in:
parent
bf89b88cfe
commit
3cf7df7543
6
init.lua
6
init.lua
@ -23,3 +23,9 @@ name_monoid = {
|
|||||||
|
|
||||||
name_monoid.dofile("settings")
|
name_monoid.dofile("settings")
|
||||||
name_monoid.dofile("monoid")
|
name_monoid.dofile("monoid")
|
||||||
|
|
||||||
|
if name_monoid.settings.show_name then
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
name_monoid.monoid:add_change(player, {text = player:get_player_name()}, "name_monoid")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
57
monoid.lua
57
monoid.lua
@ -9,31 +9,52 @@ local function remove_empty(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
name_monoid.monoid_def = {
|
name_monoid.monoid_def = {
|
||||||
identity = {},
|
identity = {
|
||||||
combine = function(tag_desc1, tag_desc2)
|
color = {a = 255, r = 255, g = 255, b = 255},
|
||||||
if tag_desc1.hide_all or tag_desc2.hide_all then
|
bgcolor = false,
|
||||||
|
},
|
||||||
|
|
||||||
|
combine = function(nametag_attributes1, nametag_attributes2)
|
||||||
|
if nametag_attributes1.hide_all or nametag_attributes2.hide_all then
|
||||||
return {
|
return {
|
||||||
tag = "",
|
text = "",
|
||||||
hide_all = true
|
color = {a = 0, r = 255, g = 255, b = 255},
|
||||||
|
bgcolor = {a = 0, r = 255, g = 255, b = 255},
|
||||||
|
hide_all = true,
|
||||||
|
}
|
||||||
|
else
|
||||||
|
local bgcolor
|
||||||
|
if nametag_attributes2.bgcolor == nil then
|
||||||
|
bgcolor = nametag_attributes1.bgcolor
|
||||||
|
else
|
||||||
|
bgcolor = nametag_attributes2.bgcolor
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
text = table.concat(
|
||||||
|
remove_empty({nametag_attributes1.text, nametag_attributes2.text}),
|
||||||
|
nametag_attributes2.text_separator or name_monoid.settings.text_separator
|
||||||
|
),
|
||||||
|
color = nametag_attributes1.color or nametag_attributes2.color,
|
||||||
|
bgcolor = bgcolor,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
return {
|
|
||||||
tag = table.concat(
|
|
||||||
remove_empty({tag_desc1.tag, tag_desc2.tag}),
|
|
||||||
tag_desc2.separator or name_monoid.settings.separator
|
|
||||||
)
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
fold = function(values)
|
fold = function(values)
|
||||||
local tag_desc1 = table.copy(name_monoid.monoid_def.identity)
|
local nametag_attributes1 = table.copy(name_monoid.monoid_def.identity)
|
||||||
for _, tag_desc2 in ipairs(values) do
|
for _, nametag_attributes2 in pairs(values) do
|
||||||
tag_desc1 = name_monoid.monoid_def.combine(tag_desc1, tag_desc2)
|
nametag_attributes1 = name_monoid.monoid_def.combine(nametag_attributes1, nametag_attributes2)
|
||||||
end
|
end
|
||||||
return tag_desc1
|
return nametag_attributes1
|
||||||
end,
|
end,
|
||||||
apply = function(tag_desc, player)
|
|
||||||
player:set_nametag_attributes({text=tag_desc.tag})
|
apply = function(nametag_attributes, player)
|
||||||
|
player:set_nametag_attributes({
|
||||||
|
text = nametag_attributes.text,
|
||||||
|
color = nametag_attributes.color,
|
||||||
|
bgcolor = nametag_attributes.bgcolor or false,
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
local s = minetest.settings
|
||||||
|
|
||||||
|
name_monoid.settings = {
|
||||||
|
tag_separator = s:get("name_monoid.tag_separator") or " ",
|
||||||
|
show_name = s:get_bool("name_monoid.show_name", true)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user