mirror of
https://github.com/mt-mods/home_workshop_modpack.git
synced 2024-09-27 14:50:42 +02:00
add filesystem
This commit is contained in:
parent
ef2ceed755
commit
4cfacb1abc
|
@ -1,11 +1,15 @@
|
||||||
computers.registered_commands = {}
|
computers.registered_commands = {}
|
||||||
|
computers.registered_confs = {}
|
||||||
|
|
||||||
function computers.register_command(modpath)
|
function computers.register_command(modpath)
|
||||||
local func = dofile(modpath .. "/init.lua")
|
local func = dofile(modpath .. "/init.lua")
|
||||||
local f = io.open(modpath .. "/conf.json")
|
local f = io.open(modpath .. "/conf.json")
|
||||||
local conf = minetest.parse_json(f:read("*all"))
|
local conf = minetest.parse_json(f:read("*all"))
|
||||||
f:close()
|
f:close()
|
||||||
if func and computers.os.version >= conf.engine then computers.registered_commands[conf.name] = func end
|
if func and computers.os.version >= conf.engine then
|
||||||
|
computers.registered_commands[conf.name] = func
|
||||||
|
computers.registered_confs[conf.name] = conf
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--load default commands
|
--load default commands
|
||||||
|
|
7
computers/commands/cd/conf.json
Normal file
7
computers/commands/cd/conf.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "cd",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 0.4,
|
||||||
|
"help": "move in and out of folders"
|
||||||
|
}
|
25
computers/commands/cd/init.lua
Normal file
25
computers/commands/cd/init.lua
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
function cd(pos, input, data)
|
||||||
|
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||||
|
|
||||||
|
if input and input ~= "" and not input:find("/") then
|
||||||
|
if input == ".." then
|
||||||
|
local uri = data.element.pwd:split("/")
|
||||||
|
uri[#uri] = nil
|
||||||
|
data.element.pwd = "/" .. table.concat(uri, "/")
|
||||||
|
if data.element.pwd == "/" then data.element.pwd = "" end
|
||||||
|
return "sucess"
|
||||||
|
else
|
||||||
|
for _, folder in pairs(minetest.get_dir_list(path, true)) do
|
||||||
|
if folder == input then
|
||||||
|
data.element.pwd = data.element.pwd .. "/" .. input
|
||||||
|
return "sucess"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "ERROR: path not found"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return "invalid or missing input"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return cd
|
|
@ -2,5 +2,6 @@
|
||||||
"name": "echo",
|
"name": "echo",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": 0.1,
|
"version": 0.1,
|
||||||
"engine": 0.3
|
"engine": 0.3,
|
||||||
|
"help": "prints out input to the terminal"
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
function echo(input)
|
function echo(pos, input, data)
|
||||||
return input
|
return input
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
7
computers/commands/help/conf.json
Normal file
7
computers/commands/help/conf.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "help",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 0.4,
|
||||||
|
"help": "prints out help"
|
||||||
|
}
|
9
computers/commands/help/init.lua
Normal file
9
computers/commands/help/init.lua
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
function help(pos, input, data)
|
||||||
|
local output = ""
|
||||||
|
for command, def in pairs(computers.registered_confs) do
|
||||||
|
output = output .. "\n" .. command .. ": " .. def.help
|
||||||
|
end
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
|
return help
|
7
computers/commands/ls/conf.json
Normal file
7
computers/commands/ls/conf.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "ls",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 0.4,
|
||||||
|
"help": "lists out all files and folders in the current path"
|
||||||
|
}
|
9
computers/commands/ls/init.lua
Normal file
9
computers/commands/ls/init.lua
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
function ls(pos, input, data)
|
||||||
|
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||||
|
--make dir to be safe
|
||||||
|
minetest.mkdir(path)
|
||||||
|
|
||||||
|
return table.concat(minetest.get_dir_list(path), " ")
|
||||||
|
end
|
||||||
|
|
||||||
|
return ls
|
7
computers/commands/mkdir/conf.json
Normal file
7
computers/commands/mkdir/conf.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "mkdir",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 0.4,
|
||||||
|
"help": "makes a dir in the current path"
|
||||||
|
}
|
12
computers/commands/mkdir/init.lua
Normal file
12
computers/commands/mkdir/init.lua
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
function mkdir(pos, input, data)
|
||||||
|
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||||
|
|
||||||
|
if input and input ~= "" and not input:find("/") then
|
||||||
|
minetest.mkdir(path .. "/" .. input)
|
||||||
|
return "folder " .. input .. " created"
|
||||||
|
else
|
||||||
|
return "invalid or missing input"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return mkdir
|
7
computers/commands/pwd/conf.json
Normal file
7
computers/commands/pwd/conf.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "pwd",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 0.4,
|
||||||
|
"help": "list the current path"
|
||||||
|
}
|
7
computers/commands/pwd/init.lua
Normal file
7
computers/commands/pwd/init.lua
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
function pwd(pos, input, data)
|
||||||
|
local output = data.element.pwd
|
||||||
|
if output == "" then output = "/" end
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
|
return pwd
|
|
@ -2,5 +2,6 @@
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": 0.1,
|
"version": 0.1,
|
||||||
"engine": 100000000
|
"engine": 100000000,
|
||||||
|
"help": "literally worthless"
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
function test()
|
function test(pos, input)
|
||||||
--minetest.chat_send_all("test")
|
--minetest.chat_send_all("test")
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
7
computers/commands/touch/conf.json
Normal file
7
computers/commands/touch/conf.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "touch",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 0.4,
|
||||||
|
"help": "creates a file in the current path"
|
||||||
|
}
|
14
computers/commands/touch/init.lua
Normal file
14
computers/commands/touch/init.lua
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
function touch(pos, input, data)
|
||||||
|
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||||
|
--make dir to be safe
|
||||||
|
minetest.mkdir(path)
|
||||||
|
|
||||||
|
if input and input ~= "" and not input:find("/") then
|
||||||
|
minetest.safe_file_write(path .. "/" .. input, "")
|
||||||
|
return "file " .. input .. " created"
|
||||||
|
else
|
||||||
|
return "invalid or missing input"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return touch
|
|
@ -100,7 +100,7 @@ function computers.load_gui(pos, node, clicker)
|
||||||
name = "terminal_output",
|
name = "terminal_output",
|
||||||
read_only = 1,
|
read_only = 1,
|
||||||
--label = "test",
|
--label = "test",
|
||||||
default = "user:~$ test command\ntest output\n",
|
default = "welcome to kuto\nversion " .. computers.os.version .. "\n\nuser:~$ ",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "box",
|
type = "box",
|
||||||
|
@ -118,6 +118,7 @@ function computers.load_gui(pos, node, clicker)
|
||||||
h = 1,
|
h = 1,
|
||||||
name = "terminal_input",
|
name = "terminal_input",
|
||||||
close_on_enter = false,
|
close_on_enter = false,
|
||||||
|
pwd = "",
|
||||||
props = {
|
props = {
|
||||||
border = false,
|
border = false,
|
||||||
},
|
},
|
||||||
|
@ -125,27 +126,30 @@ function computers.load_gui(pos, node, clicker)
|
||||||
local cindex = futil.get_index_by_name(form, "terminal_ctn")
|
local cindex = futil.get_index_by_name(form, "terminal_ctn")
|
||||||
local eindex = futil.get_index_by_name(form[cindex], "terminal_output")
|
local eindex = futil.get_index_by_name(form[cindex], "terminal_output")
|
||||||
local text = form[cindex][eindex].default
|
local text = form[cindex][eindex].default
|
||||||
--form[cindex][eindex].default = text .. "user:~$ " .. value .. "\n"
|
local pass_table = {
|
||||||
|
element = element
|
||||||
|
}
|
||||||
|
|
||||||
if value == "clear" then
|
if value == "clear" then
|
||||||
form[cindex][eindex].default = "user:~$\n"
|
form[cindex][eindex].default = "user:~" .. element.pwd .."$" .."\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
local cdata = value:split(" ", false, 1)
|
local cdata = value:split(" ", false, 1)
|
||||||
|
|
||||||
if computers.registered_commands[cdata[1]] then
|
if computers.registered_commands[cdata[1]] then
|
||||||
form[cindex][eindex].default = text .. "user:~$ " .. cdata[1] .. "\n"
|
form[cindex][eindex].default = text .. value .. "\n"
|
||||||
text = form[cindex][eindex].default
|
text = form[cindex][eindex].default
|
||||||
local output = computers.registered_commands[cdata[1]](cdata[2])
|
local output = computers.registered_commands[cdata[1]](pos, cdata[2], pass_table)
|
||||||
if output and output ~= "" and type(output) == "string" then
|
if output and type(output) == "string" then
|
||||||
form[cindex][eindex].default = text .. output .. "\n"
|
form[cindex][eindex].default = text .. output .. "\n" .. "user:~" .. element.pwd .."$" .." "
|
||||||
end
|
end
|
||||||
elseif value == "clear" then
|
elseif value == "clear" then
|
||||||
form[cindex][eindex].default = "user:~$\n"
|
form[cindex][eindex].default = "user:~$ "
|
||||||
elseif value == "" then
|
elseif value == "" then
|
||||||
form[cindex][eindex].default = text .. "user:~$\n"
|
form[cindex][eindex].default = text .. "user:~" .. element.pwd .."$" .. "\n"
|
||||||
else
|
else
|
||||||
form[cindex][eindex].default = text .. "user:~$ " .. value .. "\nERROR: command not found\n"
|
form[cindex][eindex].default = text .. value ..
|
||||||
|
"\nERROR: command not found\n" .. "user:~" .. element.pwd .."$" .. " "
|
||||||
end
|
end
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
computers = {}
|
computers = {}
|
||||||
computers.modpath = minetest.get_modpath("computers")
|
computers.modpath = minetest.get_modpath("computers")
|
||||||
|
computers.storagepath = minetest.get_worldpath() .. "/computers"
|
||||||
|
computers.devicepath = computers.storagepath .. "/devices"
|
||||||
|
computers.networkpath = computers.storagepath .. "/networks"
|
||||||
|
minetest.mkdir(computers.storagepath) --make sure it exists
|
||||||
|
|
||||||
computers.os = {
|
computers.os = {
|
||||||
version = 0.3,
|
version = 0.4,
|
||||||
name = "kuto",
|
name = "kuto",
|
||||||
authors = {"wsor", "luk3yx"},
|
authors = {"wsor", "luk3yx"},
|
||||||
license = "MIT",
|
license = "MIT",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user