monster010

CC - monster010 API

Apr 20th, 2016
3,923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. -- monster010 API - (c) monster010 -- v1.1
  2. local monSide = ""
  3. local softLabel = ""
  4. local monitor
  5.  
  6. function construct(monSid, label)
  7.     softLabel = label
  8.     monSide = monSid
  9. end
  10.  
  11. function getMonitor()
  12.     return monitor
  13. end
  14.  
  15. function clearMonitor()
  16.     monitor.clear()
  17. end
  18.  
  19. function round(num, idp, pointless)
  20.     if not pointless then pointless = false end
  21.  
  22.     local mult = 10^(idp or 0)
  23.     local erg = math.floor(num * mult + 0.5) / mult
  24.  
  25.     if pointless then
  26.         erg = string.sub(erg, 1)
  27.     end
  28.  
  29.     return erg
  30. end
  31.  
  32. function startUp()
  33.     term.clear()
  34.     term.setCursorPos(1,1)
  35.  
  36.     write("##### "..softLabel.." #####\n")
  37.     write("Copyright (c) monster010\n")
  38.     write("-------------------------\n")
  39.     write("Initialisiere Software...\n")
  40.  
  41.     if peripheral.isPresent(monSide) and peripheral.getType(monSide) == "monitor" then
  42.         monitor = peripheral.wrap(monSide)
  43.  
  44.         monitor.setTextScale(1)
  45.         monitor.setTextColor(colors.white)
  46.         monitor.setBackgroundColor(colors.black)
  47.     else
  48.         term.setTextColor(colors.red)
  49.         print("Monitor "..monSide.." nicht gefunden!")
  50.         term.setTextColor(colors.white)
  51.         return
  52.     end
  53.  
  54.     monitor.clear()
  55.     monitor.setCursorPos(1,1)
  56. end
  57.  
  58. function startUpDone()
  59.     for i = 1, 20 do
  60.         write(".")
  61.         sleep(0.1)
  62.     end
  63.     write("\n")
  64.     for i = 1, 11 do
  65.         write(".")
  66.         sleep(0.3)
  67.     end
  68.     write(" done\n")
  69.     sleep(3)
  70.     term.clear()
  71.     term.setCursorPos(1,1)
  72. end
  73.  
  74. function heading()
  75.     w, h = monitor.getSize()
  76.     monitor.setCursorPos((w - string.len(softLabel)) / 2 + 1, 1)
  77.     monitor.write(softLabel)
  78.     monitor.setCursorPos(1,2)
  79. end
  80.  
  81. function label(x, y, text)
  82.     monitor.setCursorPos(x, y)
  83.     monitor.write(text)
  84.     monitor.setCursorPos(1,2)
  85. end
  86.  
  87. function saveFile(path, content, serial)
  88.     if not serial then serial = false end
  89.  
  90.     local file = fs.open(path, "w")
  91.  
  92.     if serial then
  93.         content = textutils.serialize(content)
  94.     end
  95.  
  96.     file.write(content)
  97.     file.close()
  98. end
  99.  
  100. function loadFile(path, unserialize)
  101.     local data
  102.     if not unserialize then unserialize = false end
  103.  
  104.     if fs.exists(path) then
  105.         local file = fs.open(path, "r")
  106.  
  107.         if unserialize then
  108.             data = textutils.unserialize(file.readAll())
  109.         else
  110.             data = file.readAll()
  111.         end
  112.  
  113.         file.close()
  114.     end
  115.  
  116.     return data
  117. end
  118.  
  119. function toboolean(str)
  120.     if str == "true" then
  121.         return true
  122.     else
  123.         return false
  124.     end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment