Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fs = require("filesystem")
- local io = require("io")
- local shell = require("shell")
- local Dir = shell.getWorkingDirectory()
- local Conf = {}
- ----API Functions---
- function Conf.GetSide(Side)
- if (Side == "bottom") or (Side == "down") then
- return 0
- elseif (Side == "top") or (Side == "up") then
- return 1
- elseif (Side == "back") or (Side == "north") then
- return 2
- elseif (Side == "front") or (Side == "south") then
- return 3
- elseif (Side == "right") or (Side == "west") then
- return 4
- elseif (Side == "left") or (Side == "east") then
- return 5
- end
- return nil
- end
- function Conf.ConfigExists(File)
- fs.makeDirectory(Dir.."/Config")
- File = Dir.."/Config/"..File
- if fs.exists(File) then
- return true
- else
- return false
- end
- end
- function Conf.GetConfig(File, Line)
- File = Dir.."/Config/"..File
- if not fs.exists(File) then
- return nil
- end
- local Lines = { }
- local Index = 0
- for LINE in io.lines(File) do
- Lines[Index] = LINE
- Index = Index + 1
- end
- if Lines[Line] == nil then
- return nil
- else
- OUT = Lines[Line]
- if(OUT == "true") then
- return true
- elseif(OUT == "false") then
- return false
- else
- return OUT
- end
- end
- end
- function Conf.EditConfig(File, Line, Name, Type)
- File = Dir.."/Config/"..File
- CreateConfig(File)
- local Lines = {}
- local Index = 0
- for LINE in io.lines(File) do
- Lines[Index] = LINE
- Index = Index + 1
- end
- print("Lines: " ..Index)
- local CorrectSyntax = false
- local Input
- while CorrectSyntax == false do
- print(Name)
- Input = io.read()
- if Type == "Direction" then if IsDirection(Input) then CorrectSyntax = true else print("Incorrect Syntax, Must Be Direction! (down, up, north, south, west, east)") end end
- if Type == "Facing" then if IsFacing(Input) then CorrectSyntax = true else print("Incorrect Syntax, Must Be Facing! (top, bottom, left, right, back, front)") end end
- if Type == "Number" then if IsNumber(Input) then CorrectSyntax = true else print("Incorrect Syntax, Must Be Number!") end end
- if Type == "Boolean" then if IsBoolean(Input) then CorrectSyntax = true else print("Incorrect Syntax, Must Be Boolean!") end end
- if Type == "String" then CorrectSyntax = true end
- end
- FILE = fs.open(File, "w")
- Index = -1
- local NumberOfLines = #Lines
- local ConfigLength
- if NumberOfLines >= Line then ConfigLength = NumberOfLines else ConfigLength = Line end
- for I = 0, ConfigLength do
- if I == Line then
- FILE:write(Input.."\n")
- else
- if Lines[I] == nil then FILE:write("\n") else FILE:write(Lines[I].."\n") end
- end
- end
- FILE:close()
- end
- -----------------
- -----------------
- -----------------
- function IsNumber(str)
- if tonumber(str) ~= nil then
- return true
- end
- return false
- end
- function IsFacing(str)
- if str == "top" or str == "bottom" or str == "left" or str == "right" or str == "front" or str == "back" then
- return true
- end
- return false
- end
- function IsDirection(str)
- if str == "down" or str == "up" or str == "north" or str == "south" or str == "west" or str == "east" then
- return true
- end
- return false
- end
- function IsBoolean(str)
- if str == "true" or str == "false" then
- return true
- end
- return false
- end
- function CreateConfig(File)
- if not fs.exists(File) then
- local FILE = fs.open(File, "w")
- FILE:write("==Config==\n")
- FILE:close()
- end
- end
- return Conf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement