rewrite os sytem to be more modular using a filesystem
This commit is contained in:
parent
b5ac03f99b
commit
01b32c9202
45
api.lua
45
api.lua
@ -1,4 +1,6 @@
|
||||
-- digicompute/api.lua
|
||||
local modpath = digicompute.modpath -- modpath pointer
|
||||
local path = digicompute.path -- path pointer
|
||||
|
||||
-- SYSTEM FUNCTIONS
|
||||
-- turn on
|
||||
@ -14,7 +16,7 @@ function digicompute.on(pos, node)
|
||||
meta:set_string("formspec", digicompute.formspec_name("")) -- set formspec
|
||||
else -- use default formspec
|
||||
-- if not when_on, use blank
|
||||
if not digicompute.os.when_on(pos) then
|
||||
if not dofile(path.."/"..meta:get_string("name").."/os/start.lua") then
|
||||
meta:set_string("formspec", digicompute.formspec("", "")) -- set formspec
|
||||
end
|
||||
digicompute.os.refresh(pos) -- refresh
|
||||
@ -40,11 +42,6 @@ end
|
||||
-- /SYSTEM FUNCTIONS
|
||||
|
||||
function digicompute.register_terminal(termstring, desc)
|
||||
-- check os
|
||||
if not desc.os then
|
||||
desc.os = "bios"
|
||||
end
|
||||
digicompute.os.load(desc.os) -- load os
|
||||
-- off
|
||||
minetest.register_node("digicompute:"..termstring, {
|
||||
drawtype = "nodebox",
|
||||
@ -132,24 +129,46 @@ function digicompute.register_terminal(termstring, desc)
|
||||
meta:set_string("formspec", digicompute.formspec("", "")) -- clear formspec
|
||||
end
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
local meta = minetest.get_meta(pos) -- get meta
|
||||
local name = meta:get_string("name") -- get name
|
||||
if name then os.remove(path.."/"..name) end -- try to remove files
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender) -- precess formdata
|
||||
local meta = minetest.get_meta(pos) -- get meta
|
||||
digicompute.pos = pos -- make pos global
|
||||
digicompute.input = fields.input -- make input global
|
||||
-- if name, set
|
||||
if fields.name then
|
||||
meta:set_string("name", fields.name) -- set name
|
||||
meta:set_string("setup", "true") -- set computer to configured
|
||||
-- create filesystem
|
||||
digicompute.file.mkdir(path.."/"..fields.name.."/os/")
|
||||
local conf = digicompute.file.read(modpath.."/bios/conf.lua")
|
||||
local main = digicompute.file.read(modpath.."/bios/main.lua")
|
||||
local start = digicompute.file.read(modpath.."/bios/start.lua")
|
||||
digicompute.file.write(path.."/"..fields.name.."/os/conf.lua", conf)
|
||||
digicompute.file.write(path.."/"..fields.name.."/os/main.lua", main)
|
||||
digicompute.file.write(path.."/"..fields.name.."/os/start.lua", start)
|
||||
digicompute.file.mkdir(path.."/"..fields.name.."/user/")
|
||||
local conf = nil -- unset
|
||||
local main = nil -- unset
|
||||
local start = nil -- unset
|
||||
-- try to run when_on
|
||||
if digicompute.os.when_on(pos) then return true end
|
||||
meta:set_string("formspec", digicompute.formspec(meta:get_string("input"), meta:get_string("output"))) -- update formspec
|
||||
return
|
||||
if not dofile(path.."/"..meta:get_string("name").."/os/start.lua") then
|
||||
meta:set_string("formspec", digicompute.formspec("", "")) -- set formspec
|
||||
end
|
||||
digicompute.os.refresh(pos) -- refresh
|
||||
end
|
||||
|
||||
local name = meta:get_string("name") -- get name
|
||||
dofile(path.."/"..name.."/os/conf.lua")
|
||||
-- if submitted, process basic commands, pass on to os
|
||||
if fields.submit then
|
||||
if fields.input == digicompute.os.clear then meta:set_string("formspec", digicompute.formspec("",""))
|
||||
elseif fields.input == digicompute.os.off then digicompute.off(pos, termstring) -- set off
|
||||
elseif fields.input == digicompute.os.reboot then digicompute.reboot(pos, termstring) -- reboot
|
||||
else digicompute.os.proc_input(pos, fields.input) end -- turn over to os
|
||||
if fields.input == clear then meta:set_string("formspec", digicompute.formspec("",""))
|
||||
elseif fields.input == off then digicompute.off(pos, termstring) -- set off
|
||||
elseif fields.input == reboot then digicompute.reboot(pos, termstring) -- reboot
|
||||
else dofile(path.."/"..name.."/os/main.lua") end -- turn over to os
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
8
bios/conf.lua
Normal file
8
bios/conf.lua
Normal file
@ -0,0 +1,8 @@
|
||||
-- bios os config
|
||||
clear = "clear" -- clear command
|
||||
off = "shutdown" -- shutdown command
|
||||
reboot = "reboot" -- reboot command
|
||||
digiline = false -- do not support digilines
|
||||
network = false -- do not support network
|
||||
on = "rightclick" -- on command (rightclick)
|
||||
clear_on_close = false -- do not clear output on close
|
2
bios/main.lua
Normal file
2
bios/main.lua
Normal file
@ -0,0 +1,2 @@
|
||||
digicompute.os.set(digicompute.pos, "output", digicompute.os.get(digicompute.pos, "output")..digicompute.input.."\n"..digicompute.os.get(digicompute.pos, "name")..":~$ ") -- print input
|
||||
digicompute.os.refresh(digicompute.pos) -- refresh
|
1
bios/start.lua
Normal file
1
bios/start.lua
Normal file
@ -0,0 +1 @@
|
||||
digicompute.os.set(digicompute.pos, "output", "Welcome to BiosOS version 0.1.\n\n"..digicompute.os.get(digicompute.pos, "name")..":~$ ") -- print welcome
|
6
os.lua
6
os.lua
@ -1,12 +1,12 @@
|
||||
-- digicompute/os.lua
|
||||
digicompute.os = {} -- init os table
|
||||
local modpath = digicompute.modpath -- modpath pointer
|
||||
local path = digicompute.datapath -- datapath pointer
|
||||
local path = digicompute.path -- datapath pointer
|
||||
|
||||
-- [function] load os
|
||||
function digicompute.os.load(os_name)
|
||||
if datalib.dofile(modpath.."/os/"..os_name..".lua") ~= true then
|
||||
if datalib.dofile(path.."/os/"..os_name.."/.lua") ~= true then
|
||||
if digicompute.file.dofile(modpath.."/os/"..os_name..".lua") ~= true then
|
||||
if digicompute.file.dofile(path.."/os/"..os_name.."/.lua") ~= true then
|
||||
-- print error
|
||||
digicompute.log(os_name.." os could not be found. Please place the OS file in "..modpath.."/os/ or "..path.."/os/ with extension '.lua'.", "error")
|
||||
end
|
||||
|
19
os/bios.lua
19
os/bios.lua
@ -1,19 +0,0 @@
|
||||
-- bios os
|
||||
digicompute.os.clear = "clear" -- clear command
|
||||
digicompute.os.off = "shutdown" -- shutdown command
|
||||
digicompute.os.reboot = "reboot" -- reboot command
|
||||
digicompute.os.digiline = false -- do not support digilines
|
||||
digicompute.os.network = false -- do not support network
|
||||
digicompute.os.on = "rightclick" -- on command (rightclick)
|
||||
digicompute.os.clear_on_close = false -- do not clear output on close
|
||||
|
||||
-- when_on
|
||||
function digicompute.os.when_on(pos)
|
||||
digicompute.os.set(pos, "output", "Welcome to BiosOS version 0.1.\n\n"..digicompute.os.get(pos, "name")..":~$ ") -- print welcome
|
||||
end
|
||||
|
||||
-- process input
|
||||
function digicompute.os.proc_input(pos, input)
|
||||
digicompute.os.set(pos, "output", digicompute.os.get(pos, "output")..input.."\n"..digicompute.os.get(pos, "name")..":~$ ") -- print input
|
||||
digicompute.os.refresh(pos) -- refresh
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user