From f56aac926fc74de62c79e2d10f4095ba6f6bd8f0 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 21 Aug 2021 13:19:27 +0200 Subject: [PATCH] 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. --- clientmods/nlist/init.lua | 50 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/clientmods/nlist/init.lua b/clientmods/nlist/init.lua index 1dc3fae03..3709f2228 100644 --- a/clientmods/nlist/init.lua +++ b/clientmods/nlist/init.lua @@ -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 \ No newline at end of file -- 2.11.4.GIT