Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Uses In game documentation for computercraft peripherals and displays it in a practical way
- --Explicitly supports
- --Open Peripherals
- --Logistics Pipes
- local fTitle = "METHODMAN: Practical display for in game documentation of computercraft + addons\n"
- local newFiles = {}
- local logisticsPipeID1 = "LogisticsPipes"
- local logisticsPipeID2 = "LogisticsChassiePipe"
- function advMethodHandler(data, name)
- local file = fs.open(name, "a")
- file.writeLine("\nOpen Peripherals Advanced Method Data")
- for i,v in pairs(data) do
- file.writeLine("\n"..i..". "..v["name"].."\n")
- local returnType = "Unknown"
- if v["returnType"] ~= nil then
- returnType = v["returnType"]
- elseif v["returnTypes"] ~= nil then
- returnType = ""
- local tLen = #v["returnTypes"]
- for j = 1,tLen do
- local str = v["returnTypes"][j]
- if j < tLen then
- returnType = returnType..str..", "
- else
- returnType = returnType..str
- end
- end
- end
- file.writeLine("Return Type: "..returnType)
- file.writeLine("Description: "..v["description"])
- local args = v["args"]
- local str = "("
- local len = #args
- for k = 1, len do
- str = str..args[k]["name"]
- if k < len then
- str = str..", "
- end
- end
- file.writeLine("\n\tArguments: "..v["name"]..str..")")
- if len >= 1 then
- file.writeLine("")
- for k = 1,len do
- file.writeLine("\t\t"..k..". "..args[k]["name"])
- file.writeLine("\t\tDescription: "..args[k]["description"])
- file.writeLine("\t\tType: "..args[k]["type"])
- end
- else
- file.writeLine("\tNo Arguments")
- end
- end
- file.close()
- end
- function lpMethodHandler(data, name)
- local file = fs.open(name, "a")
- file.writeLine("\nLogistics Pipes Peripheral Help")
- file.write(data)
- file.close()
- end
- function yesOrNo(timeout)
- local timer
- local answer = "timeout"
- if type(timeout) == "number" then
- timer = os.startTimer(timeout)
- end
- while true do
- local event = {os.pullEvent()}
- if event[2] == timer then
- break
- elseif event[1] == "key" then
- local key = string.lower(keys.getName(event[2]))
- if key == "y" or key == "n" then
- if key == "y" then
- answer = true
- elseif key == "n" then
- answer = false
- end
- break
- end
- end
- end
- return answer
- end
- function uploadToPastebin(files)
- for i,v in pairs(files) do
- term.clear()
- term.setCursorPos(1,1)
- print("Uploading file: "..v)
- shell.run("pastebin", "put", v)
- print("Press any key to continue")
- os.pullEvent("key")
- end
- end
- function mainProg(side)
- local pType = peripheral.getType(side)
- local isLPPipe = false
- if string.match(pType, logisticsPipeID1) == logisticsPipeID1 or string.match(pType, logisticsPipeID2) == logisticsPipeID2 then
- isLPPipe = true
- end
- if pType == "modem" then
- local p = peripheral.wrap(side)
- if p.isWireless() == true then
- pType = "wireless_modem"
- else
- pType = "wired_modem"
- end
- end
- local header = "Peripheral found\n\tSide: "..side.."\n\tType: "..pType.."\n"
- print(header)
- local fileName
- if fs.exists(pType) == true then
- term.clear()
- term.setCursorPos(1,1)
- print("A file by the name of "..pType.." already exists")
- print("Do you wish to overwrite this file or generate a new filename?")
- print("Press the \"y\" key to overwrite, press then \"n\" to get a new filename")
- local answer = yesOrNo()
- if answer == false then
- local c = 2
- while true do
- local testName = pType.."_"..c
- if fs.exists(testName) == false then
- fileName = testName
- break
- end
- c = c+1
- end
- else
- fileName = pType
- end
- else
- fileName = pType
- end
- table.insert(newFiles, 0, fileName)
- local file = fs.open(fileName, "w")
- file.writeLine(fTitle)
- file.writeLine(header)
- file.close()
- local basicMethods = peripheral.getMethods(side)
- local openPeripheralSupport = false
- local logisticsPipesSupport = false
- print("Generating Basic Method List")
- file = fs.open(fileName, "a")
- file.writeLine(pType.." method list:\n")
- file.close()
- for i,v in pairs(basicMethods) do
- file = fs.open(fileName, "a")
- file.writeLine("\t"..v)
- file.close()
- if v == "getAdvancedMethodsData" then
- print("Open Peripheral's advanced method data info found")
- openPeripheralSupport = true
- end
- if v == "help" and isLPPipe == true then
- print("Logistics Pipes help found")
- logisticsPipesSupport = true
- end
- end
- print("Basic Method List Complete")
- if openPeripheralSupport then
- local pHandler = peripheral.wrap(side)
- print("Resolving squiggly OP nested tables")
- local advMethods = pHandler.getAdvancedMethodsData()
- advMethodHandler(advMethods, fileName)
- end
- if logisticsPipesSupport then
- local pHandler = peripheral.wrap(side)
- print("Resolving LP help string")
- local lpMethods = pHandler.help()
- lpMethodHandler(lpMethods, fileName)
- end
- file = fs.open(fileName, "a")
- file.writeLine("\n\n--------------------\n")
- file.writeLine("All actual documentation is written by the mod developer who made the peripheral, not me. I just displayed it - happy computercrafting")
- file.close()
- print("Documentation roundup for "..pType.." complete")
- end
- term.clear()
- term.setCursorPos(1,1)
- print("This program will create reports documenting any peripheral attached to this computer")
- print("The reports can be found on the directory of this computer - type dir into the console to find them")
- print("File names are based on the name the peripheral")
- print("Documentation was written by the mod developers, not me. I have just tried to display it nicely")
- print("Do you wish to continue (y/n)")
- local answer = yesOrNo(60)
- if answer == true then
- term.clear()
- term.setCursorPos(1,1)
- for i,v in pairs(peripheral.getNames()) do
- mainProg(v)
- end
- if #newFiles > 0 then
- print("\nThe following files have been generated in this computer's directory\n")
- for i,v in pairs(newFiles) do
- print("\t"..i..": "..v)
- end
- print("\nWould you like to upload these files automatically to pastebin (y/n)")
- local answer = yesOrNo(60)
- if answer == true then
- uploadToPastebin(newFiles)
- end
- else
- print("No peripherals found")
- end
- print("\nHappy computercrafting")
- else
- print("Never mind, goodbye")
- end
- sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement