KDKiller

CC Setup

Jan 17th, 2021 (edited)
270
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if turtle then pos = t.getPos() end
  2.  
  3. if not fs.exists('config') then
  4.     t.save({map=true}, 'config')
  5. end
  6. config = t.load('config')
  7.  
  8. r = {val=true}
  9. if turtle then data = {
  10.     x = {val=pos.x},
  11.     y = {val=pos.y},
  12.     z = {val=pos.z},
  13.     direction = {val=pos.direction},
  14.     label = {val=os.getComputerLabel()},
  15.     map = {val=config.map}
  16. } end
  17. s = {val='Save'}
  18.  
  19. function save()
  20.     pos.x = data.x.val
  21.     pos.y = data.y.val
  22.     pos.z = data.z.val
  23.     pos.direction = data.direction.val
  24.     t.save(pos,'locale')
  25.     config.map = data.map.val
  26.     t.save(config, 'config')
  27.     os.setComputerLabel(data.label.val)
  28.     s.val = 'Saved!'
  29. end
  30.  
  31.  
  32. if turtle then f = {
  33.     gui.createField{data.x, typ='int', cursurPos={x=5,y=5}},
  34.     gui.createField{data.y, typ='int', cursurPos={x=5,y=6}},
  35.     gui.createField{data.z, typ='int', cursurPos={x=5,y=7}},
  36.     gui.createField{data.direction, typ='options', cursurPos={x=5,y=8}, options={'North', 'East', 'South', 'West'}},
  37.     gui.createField{data.map, typ='bool', cursurPos={x=25,y=5}},
  38.     gui.createField{data.label, typ='string', cursurPos={x=8,y=10}, maxLength=15},
  39.     gui.createField{s, typ='select', cursurPos={x=3,y=12}, func=save},
  40.     gui.createField{{val='Exit'}, typ='select', cursurPos={x=31,y=12}, func=function() r.val=false end}
  41. }
  42. else f = {
  43.     gui.createField{{val='Exit'}, typ='select', cursurPos={x=gui.default.width-10,y=gui.default.height-2}, func=function() r.val=false end}
  44. } end
  45.  
  46. term.clear()
  47. gui.drawBox{colors.gray,{1,1},{gui.default.width,2}}
  48.  
  49. if turtle then
  50.     gui.writeText{'[Turtle Config]', cursurPos={x=12,y=1}, bg=colors.gray}
  51.  
  52.     term.setCursorPos(1,3)
  53.     print('\nPosition:')
  54.     print(' x: ')
  55.     print(' y: ')
  56.     print(' z: ')
  57.     print(' d: ')
  58.     print('\nLabel: ')
  59.  
  60.     gui.writeText{'Other config:', cursurPos={x=19,y=4}}
  61.     gui.writeText{'Map: ', cursurPos={x=20,y=5}}
  62. else
  63.     gui.writeText{'[Computer Config]', cursurPos={x=math.floor(gui.default.width/2)-9,y=1}, bg=colors.gray}
  64.     term.setCursorPos(1,3)
  65.     print('\nNo config options available!')
  66. end
  67.  
  68. selection = {val=0}
  69. key = gui.createMenuListener{f, r, onChange=function() s.val = 'Save' end, sel=selection}
  70. click = gui.createMenuClickListener{f, r, sel=selection}
  71. parallel.waitForAny(key, click)
  72. gui.reset()
  73. print('Setup finished')
  74.  
RAW Paste Data