jamawie

Config Configurator

Jan 4th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. --Config-Cunfigurator
  2. --valid types are: boolean (true|false), int (0-9), String (*), Side (right, left, top, bottom, front, back)
  3.  
  4. local x,y  = term.getSize()
  5. local vars = {}
  6. --         Variablenname      Variablentyp    angezeigte Nachricht
  7. vars[1] = {"monSide"    , "Side"        , "Bitte Monitorseite auswählen"}
  8. vars[2] = {"rSide"      , "Side"        , "Bitte Redstoneseite auswählen"}
  9. vars[3] = {"frequency"  , "Side"        , "Bitte Frequenzseite auswählen"}
  10. vars[4] = {"number"     , "int"         , "Bitte eine Zahl eingeben"}
  11. vars[5] = {"boolean"    , "boolean"     , "Bitte einen Wahrheitswert eingeben"}
  12. vars[6] = {"string"     , "String"      , "Bitte eine Zeichenkette eingeben"}
  13.  
  14. function select(varName, varType, varMsg)
  15.   for i=1,y do
  16.     term.setBackgroundColor(colors.blue)
  17.     term.setCursorPos(1,i)
  18.     for j=1,x do
  19.       term.write(" ")
  20.     end
  21.   end
  22.  
  23.   term.setBackgroundColor(colors.gray)
  24.   term.setTextColor(colors.white)
  25.   term.setCursorPos(5,3)
  26.   term.write(varMsg)
  27.   term.setCursorPos(5,5)
  28.   term.write(varName)
  29.   term.setCursorPos(15,5)
  30.   term.write(varType)
  31.   if varType == "int" or varType == "String" then
  32.     while true do
  33.       term.setCursorPos(5,8)
  34.       term.setBackgroundColor(colors.lightGray)
  35.       term.setTextColor(colors.black)
  36.       for i=1,20 do term.write(" ") end
  37.       term.setCursorPos(5,8)
  38.       input = read()
  39.       if varType == "String" then break end
  40.       if tonumber(input)~=nil then
  41.         input = tonumber(input)
  42.         break
  43.       end
  44.       term.setCursorPos(5,8)
  45.       term.setTextColor(colors.red)
  46.       term.write("Bitte nur Zahlen eingeben.")
  47.       sleep(2)
  48.     end
  49.   else
  50.     if varType == "Side" then auswahl = {"right", "left", "top", "bottom", "front", "back"} else auswahl = {"true", "false"} end
  51.     actual = 1
  52.     max = #auswahl
  53.     while true do
  54.       for i=0,(max*2) do
  55.         term.setCursorPos(5,6+i)
  56.         term.setBackgroundColor(colors.lightGray)
  57.         term.write("              ")
  58.       end
  59.       for i=1, max do
  60.         term.setCursorPos(7,5+(i*2))
  61.         if actual == i then term.setBackgroundColor(colors.blue) else term.setBackgroundColor(colors.gray) end
  62.         term.write("          ")  
  63.         term.setCursorPos(6 + (6-(#auswahl[i])/2),5+(i*2))
  64.         term.setTextColor(colors.white)
  65.         term.write(auswahl[i])      
  66.       end
  67.       event, k = os.pullEvent()
  68.       if k== 28 then
  69.         input = auswahl[actual]
  70.         break
  71.       elseif k == 200 then
  72.         if actual == 1 then actual = max else actual = actual-1 end
  73.       elseif k == 208 then
  74.         if actual == max then actual = 1 else actual = actual+1 end
  75.       else
  76.         term.setCursorPos(2,7)
  77.         term.setTextColor(colors.red)
  78.         term.setBackgroundColor(colors.blue)
  79.         term.write("Bitte Pfeiltasten nutzen und mit <ENTER> bestaetigen.")
  80.         sleep(2)
  81.       end
  82.     end
  83.   end
  84.   return input
  85. end
  86.  
  87. for i=1, #vars do
  88.   if vars[i][2] == "String" or vars[i][2] == "Side" then
  89.     vars[i][4] = "\""..select(vars[i][1], vars[i][2], vars[i][3]).."\""
  90.   else
  91.     vars[i][4] = select(vars[i][1], vars[i][2], vars[i][3])
  92.   end
  93. end
  94.  
  95. file = fs.open("config", "w")
  96. for i=1, #vars do
  97.   file.writeLine(vars[i][1].." = "..vars[i][4])
  98. end
  99. file.close()
Add Comment
Please, Sign In to add comment