mirror of
https://github.com/mt-mods/home_workshop_modpack.git
synced 2025-03-30 09:30:39 +02:00
add commands to terminal
This commit is contained in:
parent
d0a4ace94e
commit
ef2ceed755
16
computers/commands.lua
Normal file
16
computers/commands.lua
Normal file
@ -0,0 +1,16 @@
|
||||
computers.registered_commands = {}
|
||||
|
||||
function computers.register_command(modpath)
|
||||
local func = dofile(modpath .. "/init.lua")
|
||||
local f = io.open(modpath .. "/conf.json")
|
||||
local conf = minetest.parse_json(f:read("*all"))
|
||||
f:close()
|
||||
if func and computers.os.version >= conf.engine then computers.registered_commands[conf.name] = func end
|
||||
end
|
||||
|
||||
--load default commands
|
||||
local dirs = minetest.get_dir_list(computers.modpath .. "/commands", true)
|
||||
|
||||
for _, dir in pairs(dirs) do
|
||||
computers.register_command(computers.modpath .. "/commands/" .. dir)
|
||||
end
|
6
computers/commands/echo/conf.json
Normal file
6
computers/commands/echo/conf.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "echo",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.3
|
||||
}
|
5
computers/commands/echo/init.lua
Normal file
5
computers/commands/echo/init.lua
Normal file
@ -0,0 +1,5 @@
|
||||
function echo(input)
|
||||
return input
|
||||
end
|
||||
|
||||
return echo
|
6
computers/commands/test/conf.json
Normal file
6
computers/commands/test/conf.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "test",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 100000000
|
||||
}
|
6
computers/commands/test/init.lua
Normal file
6
computers/commands/test/init.lua
Normal file
@ -0,0 +1,6 @@
|
||||
function test()
|
||||
--minetest.chat_send_all("test")
|
||||
return 0
|
||||
end
|
||||
|
||||
return test
|
@ -122,16 +122,32 @@ function computers.load_gui(pos, node, clicker)
|
||||
border = false,
|
||||
},
|
||||
on_event = function(form, player, element, value)
|
||||
minetest.chat_send_all("value: " .. value)
|
||||
local cindex = futil.get_index_by_name(form, "terminal_ctn")
|
||||
local eindex = futil.get_index_by_name(form[cindex], "terminal_output")
|
||||
local text = form[cindex][eindex].default
|
||||
form[cindex][eindex].default = text .. "user:~$ " .. value .. "\n"
|
||||
--form[cindex][eindex].default = text .. "user:~$ " .. value .. "\n"
|
||||
|
||||
if value == "clear" then
|
||||
form[cindex][eindex].default = "user:~$\n"
|
||||
end
|
||||
|
||||
local cdata = value:split(" ", false, 1)
|
||||
|
||||
if computers.registered_commands[cdata[1]] then
|
||||
form[cindex][eindex].default = text .. "user:~$ " .. cdata[1] .. "\n"
|
||||
text = form[cindex][eindex].default
|
||||
local output = computers.registered_commands[cdata[1]](cdata[2])
|
||||
if output and output ~= "" and type(output) == "string" then
|
||||
form[cindex][eindex].default = text .. output .. "\n"
|
||||
end
|
||||
elseif value == "clear" then
|
||||
form[cindex][eindex].default = "user:~$\n"
|
||||
elseif value == "" then
|
||||
form[cindex][eindex].default = text .. "user:~$\n"
|
||||
else
|
||||
form[cindex][eindex].default = text .. "user:~$ " .. value .. "\nERROR: command not found\n"
|
||||
end
|
||||
|
||||
return form
|
||||
end,
|
||||
},
|
||||
|
@ -1,7 +1,16 @@
|
||||
computers = {}
|
||||
computers.modpath = minetest.get_modpath("computers")
|
||||
|
||||
computers.os = {
|
||||
version = 0.3,
|
||||
name = "kuto",
|
||||
authors = {"wsor", "luk3yx"},
|
||||
license = "MIT",
|
||||
}
|
||||
|
||||
dofile(computers.modpath .. "/old_stuff/init.lua")
|
||||
|
||||
dofile(computers.modpath .. "/formspec.lua")
|
||||
dofile(computers.modpath .. "/commands.lua")
|
||||
dofile(computers.modpath .. "/gui.lua")
|
||||
dofile(computers.modpath .. "/demo.lua")
|
||||
|
Loading…
x
Reference in New Issue
Block a user