diff --git a/mods/CORE/adminCommands/init.lua b/mods/CORE/adminCommands/init.lua index e69de29..de712b6 100644 --- a/mods/CORE/adminCommands/init.lua +++ b/mods/CORE/adminCommands/init.lua @@ -0,0 +1,71 @@ +local modInfo = Mod.getInfo('smc__core__formspec') +local require = modInfo.require + +---@type Formspec +local Formspec = require('Formspec') + +local listForm = Formspec:new({ + size = {x=21, y=12}, +}) + +listForm:list('current_player', 'main', 10.5, 6.5, 8, 4) + +local listFormItems = Formspec:new() + +local items = core.registered_nodes + +local w, h = 0, 0 + +---@param name string +---@param def NodeDefinition +for name, def in pairs(items) do + listFormItems:itemImageButton(w, h, 1, 1, name, name..'::item_button') + + w = w + 1 + + if w > 9 then + w = 0 + h = h + 1 + end +end + +--listFormItems:list('current_player', 'main', 0, 0, 1, 32) + +listForm:scrollContainer(listFormItems, 0.5, 0.5, 9, 11, 'admin_commands:list_items', 'vertical') +listForm:scrollbar(10, 0.5, 0.25, 10, 'vertical', 'admin_commands:list_items') + +core.log(listForm:toString()) + +core.register_chatcommand('list', { + privs = {server = true}, + + func = function(name, param) + local player = core.get_player_by_name(name) + + core.show_formspec(name, 'admin_commands:list_form', listForm:toString()) + + return true, '' + end +}) + +core.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= 'admin_commands:list_form' then + return + end + + for key, value in pairs(fields) do + if string.ends_with(key, '::item_button') then + ---@type ItemStackString + local stack = string.match(key, '(%S+)::item_button') + + core.log(tostring(stack)) + + ---@type InvRef + local inv = player:get_inventory() + + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + end + end + end +end) \ No newline at end of file diff --git a/mods/CORE/adminCommands/mod.conf b/mods/CORE/adminCommands/mod.conf index d298204..4bccec4 100644 --- a/mods/CORE/adminCommands/mod.conf +++ b/mods/CORE/adminCommands/mod.conf @@ -1,2 +1,2 @@ name = smc__core__admin_commands -depends = smc__api__api_loader +depends = smc__api__api_loader, smc__core__formspec, smc__core__item