nlist: add .nltodf command

Dragonfire's register_list_command is terribly tedious to use. This
copies an nlist to a dragonfire list.

e.g. .nltodf xray_nodes/search_nodes/eject

that will copy your currently selected nlist.
master
cora 2021-08-21 13:19:27 +02:00
parent 08213f3c17
commit f56aac926f
1 changed files with 40 additions and 10 deletions

View File

@ -8,14 +8,16 @@ local mode=1 --1:add, 2:remove
local nled_hud
local edmode_wason=false
nlist.selected=sl
minetest.register_globalstep(function()
if not minetest.settings:get_bool('nlist_edmode') then
if (edmode_wason) then edmode_wason=false nlist.hide() end
return
end
edmode_wason=true
nlist.show_list(sl,true)
end)
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
dofile(modpath .. "/forms.lua")
minetest.register_cheat('Lists','nList',function()ws.display_list_formspec("NodeLists",nlist.get_lists(),{}) end)
ws.rg('NlEdMode','nList','nlist_edmode', function()nlist.show_list(sl,true) end,function() end,function()nlist.hide() end)
minetest.register_on_punchnode(function(p, n)
if not minetest.settings:get_bool('nlist_edmode') then return end
@ -55,6 +57,26 @@ function nlist.get(list)
if not arr then arr={} end
return arr
end
function nlist.get_lists()
local ret={}
for name, _ in pairs(storage:to_table().fields) do
table.insert(ret, name)
end
table.sort(ret)
return ret
end
function nlist.rename(oldname, newname)
oldname, newname = tostring(oldname), tostring(newname)
local list = storage:get_string(oldname)
if not list or not storage:set_string(newname,list)then return end
if oldname ~= newname then
storage:set_string(list,'')
end
return true
end
function nlist.clear(list)
storage:set_string(list,'')
end
@ -113,13 +135,21 @@ function set_nled_hud(ttext)
return true
end
local function todflist(list)
--if not minetest.settings:get(list) then return end
minetest.settings:set(list,table.concat(nlist.get(nlist.selected),","))
end
minetest.register_chatcommand('nls',{func=function(list) sl=list nlist.selected=list end})
minetest.register_chatcommand('nlshow',{func=function() nlist.show_list(sl) end})
minetest.register_chatcommand('nla',{func=function(el) nlist.add(sl,el) end})
minetest.register_chatcommand('nlr',{func=function(el) nlist.remove(sl,el) end})
minetest.register_chatcommand('nlc',{func=function(el) nlist.clear(sl) end})
minetest.register_cheat("nlEdMode","Player","nlist_edmode")
minetest.register_chatcommand('nlawi',{func=function() nlist.add(sl,minetest.localplayer:get_wielded_item():get_name()) end})
minetest.register_chatcommand('nlrwi',{func=function() nlist.remove(sl,minetest.localplayer:get_wielded_item():get_name()) end})
minetest.register_chatcommand('nltodf',{func=function(p) todflist(tostring(p)) end})
function nlist.get_mtnodes()
local arr= {
@ -1176,4 +1206,4 @@ function nlist.get_mclnodes()
'mcl_wool:yellow_carpet'
}
return arr
end
end