istasi

GPS Tower (ComputerCraft)

Sep 3rd, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 73.72 KB | None | 0 0
  1. _G ['i'] = {
  2.     ['files'] = {
  3.         ['_url'] = '_blank',
  4.         ['_data'] = {
  5.             ['class/map.lua'] = [[
  6. local data = {
  7.     ['_path'] = '/.map',
  8.     ['_data'] = false,
  9.  
  10.     ['_init'] = function ( self )
  11.         if self._data == false then
  12.             if fs.exists ( self._path ) == true then
  13.                 local f = fs.open ( self._path, 'r' )
  14.                 local content = f.readAll ()
  15.                 f.close ()
  16.  
  17.                 self._data = textutils.unserialize ( content )
  18.                 if type ( self._data ) ~= 'table' then
  19.                     self._data = {}
  20.                 end
  21.             else
  22.                 self._data = {}
  23.             end
  24.         end
  25.     end,
  26.  
  27.     ['get'] = function ( self, key )
  28.         self:_init ()
  29.  
  30.         return self._data [key]
  31.     end,
  32.  
  33.     ['set'] = function ( self, key, value )
  34.         self:_init ()
  35.         self._data [key] = value
  36.  
  37.         local content = textutils.serialize ( self._data )
  38.         local f = fs.open ( self._path, 'w' )
  39.         f.write ( content )
  40.         f.close ()
  41.  
  42.         return self
  43.     end,
  44. }
  45. local map = {}
  46. map = {
  47.     ['_raw'] = {},
  48.     ['blocks'] = nil,
  49.  
  50.     ['get'] = function ( self, node )
  51.         if node.x == nil then error ( 'X missing' ) end
  52.         if node.y == nil then error ( 'Y missing' ) end
  53.         if node.z == nil then error ( 'Z missing' ) end
  54.  
  55.         local bind = function ( node, block )
  56.             for k,v in pairs ( node ) do block [k] = v end
  57.  
  58.             if block ['solid'] == nil then
  59.                 block ['solid'] = function ( self )
  60.                     if self._solid == true then return true end
  61.  
  62.                     if self.id == nil then return false end
  63.                     if self.id == 1 then return false end
  64.  
  65.  
  66.                     local block = map.blocks [ self.id ]
  67.                     if block == nil then return false end
  68.  
  69.                     if block.solid == nil then return false end
  70.                     if block.solid == true then return true end
  71.  
  72.                     return block.solid
  73.                 end
  74.             end
  75.  
  76.             if block ['neighbors'] == nil then
  77.                 block ['neighbors'] = function ( self )
  78.                     local nodes = {}
  79.                     for x = -1, 1, 1 do
  80.                         for y = -1, 1, 1 do
  81.                             for z = -1, 1, 1 do
  82.                                 local c = 0
  83.                                 if x == 0 then c = c + 1 end
  84.                                 if y == 0 then c = c + 1 end
  85.                                 if z == 0 then c = c + 1 end
  86.  
  87.                                 if c == 2 then
  88.                                     table.insert ( nodes, {
  89.                                         ['x'] = self.x + x,
  90.                                         ['y'] = self.y + y,
  91.                                         ['z'] = self.z + z,
  92.                                     } )
  93.                                 end
  94.                             end
  95.                         end
  96.                     end
  97.  
  98.                     return nodes
  99.                 end
  100.             end
  101.  
  102.             if block ['east'] == nil then
  103.                 block ['east'] = function ( self )
  104.                     if self._east == nil then
  105.                         self._east = map:get ({ ['x'] = self.x + 1, ['y'] = self.y, ['z'] = self.z, })
  106.                         self._east._west = self
  107.                     end
  108.                     return self._east
  109.                 end
  110.             end
  111.  
  112.             if block ['west'] == nil then
  113.                 block ['west'] = function ( self )
  114.                     if self._west == nil then
  115.                         self._west = map:get ({ ['x'] = self.x - 1, ['y'] = self.y, ['z'] = self.z, })
  116.                         self._west._east = self
  117.                     end
  118.                     return self._west
  119.                 end
  120.             end
  121.  
  122.             if block ['north'] == nil then
  123.                 block ['north'] = function ( self )
  124.                     if self._north == nil then
  125.                         self._north = map:get ({ ['x'] = self.x, ['y'] = self.y, ['z'] = self.z - 1, })
  126.                         self._north._south = self
  127.                     end
  128.                     return self._north
  129.                 end
  130.             end
  131.  
  132.             if block ['south'] == nil then
  133.                 block ['south'] = function ( self )
  134.                     if self._south == nil then
  135.                         self._south = map:get ({ ['x'] = self.x, ['y'] = self.y, ['z'] = self.z + 1, })
  136.                         self._south._north = self
  137.                     end
  138.                     return self._south
  139.                 end
  140.             end
  141.  
  142.             if block ['up'] == nil then
  143.                 block ['up'] = function ( self )
  144.                     if self._up == nil then
  145.                         self._up = map:get ({ ['x'] = self.x, ['y'] = self.y + 1, ['z'] = self.z, })
  146.                         self._up._down = self
  147.                     end
  148.                     return self._up
  149.                 end
  150.             end
  151.  
  152.             if block ['down'] == nil then
  153.                 block ['down'] = function ( self )
  154.                     if self._down == nil then
  155.                         self._down = map:get ({ ['x'] = self.x, ['y'] = self.y - 1, ['z'] = self.z, })
  156.                         self._down._up = self
  157.                     end
  158.                     return self._down
  159.                 end
  160.             end
  161.            
  162.             return block
  163.         end
  164.  
  165.         if self._raw [node.x] == nil then
  166.             self._raw [node.x] = { [node.y] = { [node.z] = { ['x'] = node.x, ['y'] = node.y, ['z'] = node.z } } }
  167.         elseif self._raw [node.x][node.y] == nil then
  168.             self._raw [node.x][node.y] = { [node.z] = { ['x'] = node.x, ['y'] = node.y, ['z'] = node.z } }
  169.         elseif self._raw [node.x][node.y][node.z] == nil then
  170.             self._raw [node.x][node.y][node.z] = { ['x'] = node.x, ['y'] = node.y, ['z'] = node.z }
  171.         end
  172.  
  173.         return bind ( self._raw [node.x][node.y][node.z], node )
  174.     end,
  175.  
  176.     ['set'] = function ( self, node, value )
  177.         if node.x == nil then error ( 'X missing' ) end
  178.         if node.y == nil then error ( 'Y missing' ) end
  179.         if node.z == nil then error ( 'Z missing' ) end
  180.  
  181.         if self._raw [node.x] == nil then
  182.             self._raw [node.x] = { [node.y] = { [node.z] = value } }
  183.             return self
  184.         end
  185.  
  186.         if self._raw [node.x][node.y] == nil then
  187.             self._raw [node.x][node.y] = { [node.z] = value }
  188.             return self
  189.         end
  190.  
  191.         if self._raw [node.x][node.y][node.z] == nil then
  192.             self._raw [node.x][node.y][node.z] = value
  193.             return self
  194.         end
  195.  
  196.         for k,v in pairs ( value ) do
  197.             if type (v) ~= 'function' then
  198.                 self._raw [node.x][node.y][node.z][k] = v
  199.             end
  200.         end
  201.         return self
  202.     end,
  203.  
  204.     ['save'] = function ( self )
  205.         local _data = {}
  206.         local ignore = {
  207.             ['x'] = true,
  208.             ['y'] = true,
  209.             ['z'] = true
  210.         }
  211.  
  212.         for x in pairs ( self._raw ) do
  213.             for y in pairs ( self._raw [x] ) do
  214.                 for z in pairs ( self._raw [x][y] ) do
  215.                     local save = false
  216.                     for k in pairs ( self._raw [x][y][z] ) do
  217.                         if ignore [k] == nil then
  218.                             save = true
  219.  
  220.                             break
  221.                         end
  222.                     end
  223.  
  224.                     if save == true then
  225.                         if _data [x] == nil then _data [x] = {} end
  226.                         if _data [x][y] == nil then _data [x][y] = {} end
  227.                         if _data [x][y][z] == nil then _data [x][y][z] = {} end
  228.  
  229.                         for k,v in pairs ( self._raw [x][y][z] ) do
  230.                             if ignore [k] ~= true and type (v) ~= 'function' then
  231.                                 _data [x][y][z][k] = v
  232.                             end
  233.                         end
  234.                     end
  235.                 end
  236.             end
  237.         end
  238.         data:set ( 'map', _data )
  239.     end,
  240. }
  241.  
  242. local _data = data:get ( 'map' )
  243. if _data ~= nil then
  244.     for x in pairs ( _data ) do
  245.         for y in pairs ( _data [x] ) do
  246.             for z in pairs ( _data [x][y] ) do
  247.                 if map._raw [x] == nil then map._raw [x] = {} end
  248.                 if map._raw [x][y] == nil then map._raw [x][y] = {} end
  249.                 if map._raw [x][y][z] == nil then map._raw [x][y][z] = {} end
  250.  
  251.                 map._raw [x][y][z] = _data [x][y][z]
  252.                 map._raw [x][y][z].x = x
  253.                 map._raw [x][y][z].y = y
  254.                 map._raw [x][y][z].z = z
  255.             end
  256.         end
  257.     end
  258. end
  259.  
  260. return map
  261.             ]],
  262.             ['class/turtle.lua'] = [[
  263. local data = {
  264.     ['_path'] = '/.turtle',
  265.     ['_data'] = false,
  266.  
  267.     ['_init'] = function ( self )
  268.         if self._data == false then
  269.             if fs.exists ( self._path ) == true then
  270.                 local f = fs.open ( self._path, 'r' )
  271.                 local content = f.readAll ()
  272.                 f.close ()
  273.  
  274.                 self._data = textutils.unserialize ( content )
  275.                 if type ( self._data ) ~= 'table' then
  276.                     self._data = {}
  277.                 end
  278.             else
  279.                 self._data = {}
  280.             end
  281.         end
  282.     end,
  283.  
  284.     ['get'] = function ( self, key )
  285.         self:_init ()
  286.  
  287.         return self._data [key]
  288.     end,
  289.  
  290.     ['set'] = function ( self, key, value )
  291.         self:_init ()
  292.         self._data [key] = value
  293.  
  294.         local content = textutils.serialize ( self._data )
  295.         local f = fs.open ( self._path, 'w' )
  296.         f.write ( content )
  297.         f.close ()
  298.  
  299.         return self
  300.     end,
  301. }
  302.  
  303. local names = {
  304.     ['east']    = 1,
  305.     ['north']   = 2,
  306.     ['west']    = 3,
  307.     ['south']   = 4,
  308.     [1] = 'east',
  309.     [2] = 'north',
  310.     [3] = 'west',
  311.     [4] = 'south',
  312. }
  313.  
  314. local custom = {}
  315. custom = {
  316.     ['inventory'] = i.files:run ( 'class/turtle.inventory.lua' ),
  317.  
  318.     ['location'] = {
  319.         ['x'] = data:get ( 'x' ) or 0,
  320.         ['y'] = data:get ( 'y' ) or 0,
  321.         ['z'] = data:get ( 'z' ) or 0,
  322.     },
  323.  
  324.     ['direction'] = {
  325.         ['_parent'] = nil,
  326.         ['forward'] = function ( self )
  327.             return self._parent:face ()
  328.             --return 'cake'
  329.         end,
  330.  
  331.         ['back'] = function ( self )
  332.             local f = custom.facing + 2
  333.             if f > 4 then f = f - 4 end
  334.  
  335.             return names [f]
  336.         end,
  337.  
  338.         ['left'] = function ( self )
  339.             local f = custom.facing + 1
  340.             if f > 4 then f = f - 4 end
  341.  
  342.             return names [f]
  343.         end,
  344.  
  345.         ['right'] = function ( self )
  346.             local f = custom.facing - 1
  347.             if f > 4 then f = f - 4 end
  348.  
  349.             return names [f]
  350.         end,
  351.     },
  352.  
  353.     ['facing'] = data:get ( 'facing' ) or 2,
  354.     ['face'] = function ( self, direction )
  355.         if type ( direction ) == 'string' then direction = names [direction] end
  356.  
  357.         if direction == nil then return names [self.facing] end
  358.         if direction == self.facing then return true end
  359.  
  360.         local diff = direction - self.facing
  361.  
  362.         if direction > self.facing then
  363.             local diff = direction - self.facing
  364.             if diff > 2 then
  365.                 self:right ( 1 )
  366.             else
  367.                 self:left ( diff )
  368.             end
  369.         else
  370.             local diff = self.facing - direction
  371.             if diff > 2 then
  372.                 self:left ( 1 )
  373.             else
  374.                 self:right ( diff )
  375.             end
  376.         end
  377.  
  378.         self:update ()
  379.     end,
  380.  
  381.     ['__update'] = function ( self )
  382.         data:set ( 'x', self.location.x )
  383.         data:set ( 'y', self.location.y )
  384.         data:set ( 'z', self.location.z )
  385.  
  386.         if data:get ( 'facing' ) ~= self.facing then
  387.             data:set ( 'facing', self.facing )
  388.         end
  389.     end,
  390.     ['_update'] = nil,
  391.     ['update'] = function ( self, func )
  392.         if func == nil then
  393.             self:__update ()
  394.  
  395.             if type ( self._update ) == 'function' then
  396.                 self:_update ()
  397.  
  398.                 return self
  399.             else
  400.                 return false
  401.             end
  402.         end
  403.  
  404.         if type ( func ) ~= 'function' then
  405.             error ( 'Argument supplied is not a function' )
  406.         end
  407.  
  408.         self._update = func
  409.         return self
  410.     end,
  411.  
  412.     ['forward'] = function ( self, amount )
  413.         if amount == nil then amount = 1 end
  414.         if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
  415.  
  416.         local moved = 0
  417.         for i = 1, amount do
  418.             local state, reason = turtle.forward ()
  419.             if state == false then
  420.                 return moved, reason
  421.             end
  422.  
  423.             if self.facing == 2 then
  424.                 self.location.z = self.location.z - 1
  425.             elseif self.facing == 4 then
  426.                 self.location.z = self.location.z + 1
  427.             elseif self.facing == 1 then
  428.                 self.location.x = self.location.x + 1
  429.             elseif self.facing == 3 then
  430.                 self.location.x = self.location.x - 1
  431.             end
  432.  
  433.             self:update ()
  434.             moved = moved + 1
  435.         end
  436.  
  437.         return moved
  438.     end,
  439.     ['back'] = function ( self, amount )
  440.         if amount == nil then amount = 1 end
  441.         if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
  442.  
  443.         local moved = 0
  444.         for i = 1, amount do
  445.             local state, reason = turtle.back ()
  446.             if state == false then return moved, reason end
  447.  
  448.             if self.facing == 2 then
  449.                 self.location.z = self.location.z + 1
  450.             elseif self.facing == 4 then
  451.                 self.location.z = self.location.z - 1
  452.             elseif self.facing == 1 then
  453.                 self.location.x = self.location.x - 1
  454.             elseif self.facing == 3 then
  455.                 self.location.x = self.location.x + 1
  456.             end
  457.  
  458.             self:update ()
  459.             moved = moved + 1
  460.         end
  461.  
  462.         return moved
  463.     end,
  464.  
  465.     ['up'] = function ( self, amount )
  466.         if amount == nil then amount = 1 end
  467.         if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
  468.  
  469.         local moved = 0
  470.         for i = 1, amount do
  471.             local state, reason = turtle.up ()
  472.             if state == false then return moved, reason end
  473.  
  474.             self.location.y = self.location.y + 1
  475.  
  476.             self:update ()
  477.             moved = moved + 1
  478.         end
  479.  
  480.         return moved
  481.     end,
  482.     ['down'] = function ( self, amount )
  483.         if amount == nil then amount = 1 end
  484.         if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
  485.  
  486.         local moved = 0
  487.         for i = 1, amount do
  488.             local state, reason = turtle.down ()
  489.             if state == false then return moved, reason end
  490.  
  491.             self.location.y = self.location.y - 1
  492.  
  493.             self:update ()
  494.             moved = moved + 1
  495.         end
  496.  
  497.         return moved
  498.     end,
  499.  
  500.     ['left'] = function ( self, amount )
  501.         if amount == nil then amount = 1 end
  502.  
  503.         local moved = 0
  504.         for i = 1, amount do
  505.             local state, reason = turtle.turnLeft ()
  506.             if state == false then return false, reason end
  507.  
  508.             self.facing = self.facing + 1
  509.             if self.facing > 4 then self.facing = 1 end
  510.  
  511.             self:update ()
  512.             moved = moved + 1
  513.         end
  514.  
  515.         return moved
  516.     end,
  517.     ['right'] = function ( self, amount )
  518.         if amount == nil then amount = 1 end
  519.  
  520.         local moved = 0
  521.         for i = 1, amount do
  522.             local state, reason = turtle.turnRight ()
  523.             if state == false then return false, reason end
  524.  
  525.             self.facing = self.facing - 1
  526.             if self.facing < 1 then self.facing = 4 end
  527.  
  528.             self:update ()
  529.             moved = moved + 1
  530.         end
  531.  
  532.         return moved
  533.     end,
  534.  
  535.     ['goto'] = function ( self, position )
  536.         if position.x == self.location.x and position.y == self.location.y and position.z == self.location.z then return true end
  537.  
  538.         -- Y
  539.         local diff = position.y - self.location.y
  540.         if diff ~= 0 then
  541.             if diff > 0 then
  542.                 local response, message = self:up ( diff )
  543.                 if response ~= diff then return false, message end
  544.             else
  545.                 diff = 0 - diff
  546.  
  547.                 local response, message = self:down ( diff )
  548.                 if response ~= diff then return false, message end
  549.             end
  550.         end
  551.  
  552.         -- X
  553.         local diff = position.x - self.location.x
  554.         if diff ~= 0 then
  555.             if diff > 0 then
  556.                 if self:face () ~= 'east' then
  557.                     self:face ( 'east' )
  558.                 end
  559.  
  560.                 local response, message = self:forward ( diff )
  561.                 if response ~= diff then return false, message end
  562.             else
  563.                 if self:face () ~= 'west' then
  564.                     self:face ( 'west' )
  565.                 end
  566.  
  567.                 diff = 0 - diff
  568.                
  569.                 local response, message = self:forward ( diff )
  570.                 if response ~= diff then return false, message end
  571.             end
  572.         end
  573.  
  574.         -- Z
  575.         local diff = position.z - self.location.z
  576.         if diff ~= 0 then
  577.             if diff > 0 then
  578.                 if self:face () ~= 'south' then
  579.                     self:face ( 'south' )
  580.                 end
  581.                 local response, message = self:forward ( diff )
  582.                 if response ~= diff then return false, message end
  583.             else
  584.                 if self:face () ~= 'north' then
  585.                     self:face ( 'north' )
  586.                 end
  587.                 diff = 0 - diff
  588.                
  589.                 local response, message = self:forward ( diff )
  590.                 if response ~= diff then return false, message end
  591.             end
  592.         end
  593.  
  594.         return true
  595.     end,
  596.  
  597.     ['refuel'] = function ( self )
  598.         if self.inventory.select:fuel () == false then
  599.             return false
  600.         end
  601.  
  602.         turtle.refuel ( 1 )
  603.         return true
  604.     end,
  605. }
  606. custom.direction._parent = custom
  607.  
  608. setmetatable ( custom.location, {
  609.     ['__call'] = function ( self )
  610.         if i ~= nil and i.map ~= nil then return i.map:get ( { ['x'] = self.x, ['y'] = self.y, ['z'] = self.z, } ) end
  611.  
  612.         return {
  613.             ['x'] = self.x,
  614.             ['y'] = self.y,
  615.             ['z'] = self.z,
  616.         }
  617.     end,
  618. } )
  619.  
  620. local x,y,z = gps.locate (0.5)
  621. if x and y and z then
  622.     custom.location.x = x
  623.     custom.location.y = y
  624.     custom.location.z = z
  625.  
  626.     custom._hasGPS = true
  627. end
  628.  
  629. return custom
  630.             ]],
  631.             ['class/turtle.inventory.lua'] = [[
  632. local inventory = {}
  633. inventory = {
  634.     ['_fuels'] = {
  635.         ['has'] = function ( self, details )
  636.             if details == nil then return false end
  637.  
  638.             for _, item in ipairs ( self ) do
  639.                 if item.damage ~= nil then
  640.                     if item.name == details.name and item.damage == details.damage then
  641.                         return item.fuel
  642.                     end
  643.                 else
  644.                     if item.name == details.name then
  645.                         return item.fuel
  646.                     end
  647.                 end
  648.             end
  649.  
  650.             return false
  651.         end,
  652.  
  653.         ['add'] = function ( self, details, fuel )
  654.             table.insert ( self, { ['name'] = details.name, ['damage'] = details.damage, ['fuel'] = fuel, } )
  655.             return self
  656.         end,
  657.     },
  658.     ['_data'] = {},
  659.  
  660.     ['scan'] = function ( self )
  661.         for i = 1, 16 do
  662.             if turtle.getItemCount (i) > 0 then
  663.                 self._data [ i ] = self:details ( i )
  664.             else
  665.                 self._data [ i ] = nil
  666.             end
  667.         end
  668.  
  669.         return self
  670.     end,
  671.  
  672.     ['snapshot'] = function ( self )
  673.         local inventory = {
  674.             ['_parent'] = self,
  675.  
  676.             ['compare'] = {
  677.                 ['_parent'] = self,
  678.  
  679.                 ['current'] = function ( self )
  680.                     return self._parent:compare ( self._parent._parent:snapshot () )
  681.                 end,
  682.             },
  683.            
  684.             ['each'] = function ( self, method )
  685.                 for i = 1,16 do
  686.                     if self [i] ~= nil then
  687.                         if method ( i, self [i] ) == false then
  688.                             break
  689.                         end
  690.                     end
  691.                 end
  692.                 return self
  693.             end,
  694.         }
  695.         inventory.compare._parent = inventory
  696.  
  697.         setmetatable ( inventory.compare, {
  698.             ['__call'] = function ( self, _, current )
  699.                 local before = self._parent
  700.  
  701.                 for slot = 1, 16 do
  702.                     if before [slot] ~= nil then
  703.                         if current [slot] ~= nil then
  704.                             current [slot].count = current [slot].count - before [slot].count
  705.  
  706.                             if current [slot].count == 0 then
  707.                                 current [slot] = nil
  708.                             end
  709.                         else
  710.                             current [slot] = before [slot]
  711.                             current [slot].count = 0 - current [slot].count
  712.                         end
  713.                     end
  714.  
  715.                 end
  716.  
  717.                 return current
  718.             end,
  719.         } )
  720.  
  721.         self:scan ()
  722.         for slot, entry in pairs ( self._data ) do
  723.             inventory [slot] = entry
  724.         end
  725.  
  726.         return inventory
  727.     end,
  728.  
  729.     ['details'] = function ( self, slot )
  730.         local data = turtle.getItemDetail ( slot )
  731.  
  732.         if data ~= nil then
  733.             data.stackSize = data.count + turtle.getItemSpace ( slot )
  734.         end
  735.  
  736.         return data
  737.     end,
  738.  
  739.     ['select'] = {
  740.         ['_parent'] = nil,
  741.  
  742.         ['empty'] = function ( self )
  743.             self:scan ()
  744.             for slot = 1, 16 do
  745.                 local item = self._data [slot]
  746.  
  747.                 if item == nil then
  748.                     turtle.select ( slot )
  749.                     return true
  750.                 end
  751.             end
  752.  
  753.             return true
  754.         end,
  755.  
  756.         ['fuel'] = function ( self )
  757.             local items = {
  758.                 ['_fuels'] = self._parent._fuels,
  759.  
  760.                 ['first'] = function ( self )
  761.                     local entry = self [1]
  762.                     if entry == nil then return false end
  763.  
  764.                     turtle.select ( entry.slot )
  765.                     return true
  766.                 end,
  767.  
  768.                 ['last'] = function ( self )
  769.                     local entry = self [ #self ]
  770.                     if entry == nil then return false end
  771.  
  772.                     turtle.select ( entry.slot )
  773.                     return true
  774.                 end,
  775.  
  776.                 ['best'] = function ( self )
  777.                     if #self == 0 then return false end
  778.  
  779.                     local score,best = 0 - 1/0,nil
  780.                     for slot, entry in ipairs ( self ) do
  781.                         local _score = self._fuels:has ( entry.item )
  782.                         if _score > score then
  783.                             score = _score
  784.                             best = entry
  785.                         end
  786.                     end
  787.  
  788.                     turtle.select ( best.slot )
  789.                     return true
  790.                 end,
  791.  
  792.                 ['worst'] = function ( self )
  793.                     if #self == 0 then return false end
  794.  
  795.                     local score,worst = 1/0,nil
  796.                     for slot, entry in ipairs ( self ) do
  797.                         local _score = self._fuels:has ( entry.item )
  798.  
  799.                         if _score < score then
  800.                             score = _score
  801.                             worst = entry
  802.                         end
  803.                     end
  804.  
  805.                     turtle.select ( worst.slot )
  806.                     return true
  807.                 end,
  808.  
  809.                 ['least'] = function ( self )
  810.                     if #self == 0 then return false end
  811.  
  812.                     local score,least = 1/0,nil
  813.                     for slot, entry in ipairs ( self ) do
  814.                         local _score = entry.item.count
  815.  
  816.                         if _score < score then
  817.                             score = _score
  818.                             least = entry
  819.                         end
  820.                     end
  821.  
  822.                     turtle.select ( least.slot )
  823.                     return true
  824.                 end,
  825.  
  826.                 ['most'] = function ( self )
  827.                     if #self == 0 then return false end
  828.  
  829.                     local score,most = 0 - 1/0,nil
  830.                     for slot, entry in ipairs ( self ) do
  831.                         local _score = entry.item.count
  832.  
  833.                         if _score > score then
  834.                             score = _score
  835.                             most = entry
  836.                         end
  837.                     end
  838.  
  839.                     turtle.select ( most.slot )
  840.                     return true
  841.                 end,
  842.             }
  843.             self._parent:scan ()
  844.  
  845.             local selected = false
  846.             for slot = 1, 16 do
  847.                 local item = self._parent._data [slot]
  848.                 if item ~= nil then
  849.                     local fuel = self._parent._fuels:has ( item )
  850.  
  851.                     if fuel ~= false then
  852.                         table.insert ( items, {
  853.                             ['slot'] = slot,
  854.                             ['fuel'] = fuel,
  855.  
  856.                             ['item'] = item,
  857.                         } )
  858.                     end
  859.                 end
  860.             end
  861.  
  862.             if #items == 0 then
  863.                 return false
  864.             end
  865.  
  866.             items:first ()
  867.             return items
  868.         end,
  869.     },
  870.  
  871.     ['stack'] = function ( self )
  872.         local items = {}
  873.         for i = 1, 16, 1 do items [i] = turtle.getItemDetail ( i ) end
  874.  
  875.         for i = 1, 16, 1 do
  876.             if items [i] ~= nil then
  877.                 for slot = 16, 1, -1 do
  878.                     local item = items [slot]
  879.                     local stackSize = turtle.getItemSpace ( i ) + items [i].count
  880.  
  881.                     if slot ~= i and item ~= nil and items [i].name == item.name and items [i].damage == item.damage and turtle.getItemSpace ( i ) > 0 and item.count < stackSize then
  882.                         turtle.select ( slot )
  883.                         turtle.transferTo ( i )
  884.  
  885.                         items [slot] = turtle.getItemDetail ( slot )
  886.                         items [i] = turtle.getItemDetail ( i )
  887.                     end
  888.                 end
  889.             end
  890.         end
  891.  
  892.         return self
  893.     end,
  894. }
  895.  
  896. setmetatable ( inventory.select, {
  897.     ['__call'] = function ( self, _, search, sel )
  898.         if search == nil then error ( 'Search is nil' ) end
  899.         self._parent:scan ()
  900.  
  901.         for slot = 1, 16 do
  902.             local item = self._parent._data [slot]
  903.             if item ~= nil then
  904.                 if i ~= nil and i.items ~= nil then item = i.items:has ( item ) end
  905.  
  906.                 if type ( search ) == 'string' and tostring ( item.name ):lower ():sub ( 1, #search ) == search:lower () then
  907.                     if sel ~= false then
  908.                         turtle.select ( slot )
  909.                     end
  910.  
  911.                     return item
  912.                 elseif type ( search ) == 'table' then
  913.                     if i ~= nil and i.items ~= nil then search = i.items:has ( search ) end
  914.                     local accept = true
  915.  
  916.                     for k, v in pairs ( search ) do
  917.                         if k ~= 'count' and k ~= 'stackSize' then
  918.                             if item [k] ~= v then
  919.                                 accept = false
  920.                             end
  921.                         end
  922.                     end
  923.  
  924.                     if accept == true then
  925.                         if sel ~= false then
  926.                             turtle.select ( slot )
  927.                         end
  928.  
  929.                         return item
  930.                     end
  931.                 end
  932.             end
  933.         end
  934.  
  935.         return false
  936.     end,
  937. } )
  938.  
  939. inventory._fuels:add ( {
  940.     ['name'] = 'minecraft:coal',
  941.     ['damage'] = 0,
  942. }, 80 )
  943.  
  944. inventory._fuels:add ( {
  945.     ['name'] = 'minecraft:coal',
  946.     ['damage'] = 1,
  947. }, 80 )
  948.  
  949. inventory._fuels:add ( {
  950.     ['name'] = 'minecraft:coal_block',
  951.     ['damage'] = 0,
  952. }, 800 )
  953.  
  954. inventory._fuels:add ( {
  955.     ['name'] = 'minecraft:lava_bucket',
  956.     ['damage'] = 0,
  957. }, 1000 )
  958.  
  959.  
  960. inventory.select._parent = inventory
  961. return inventory:scan ()
  962.             ]],
  963.             ['class/items.lua'] = [[
  964. local items = {
  965.     ['has'] = {
  966.         ['_parent'] = nil,
  967.  
  968.         ['category'] = function ( self, category )
  969.             local items = { ['has'] = self._parent ['has'] }
  970.  
  971.             for _, item in ipairs ( self._parent ) do
  972.                 if type ( item.category ) == 'table' then
  973.                     for _, cat in ipairs ( item.category ) do
  974.                         --print ( cat ..'='.. category )
  975.                         --os.sleep ( 0.1 )
  976.                         if cat == category then
  977.                             table.insert ( items, item )
  978.                         end
  979.                     end
  980.                 end
  981.             end
  982.  
  983.             items.has ['_parent'] = items
  984.             return items
  985.         end,
  986.     },
  987.  
  988.     -- ITEMS
  989.     {
  990.         ['match'] = {
  991.             ['name'] = 'ComputerCraft:CC-Peripheral',
  992.             ['damage'] = 0,
  993.         },
  994.  
  995.         ['mod'] = 'Computercraft',
  996.         ['category'] = { [1] = 'peripheral', },
  997.  
  998.         ['name'] = 'Disk Drive',
  999.     },
  1000.     {
  1001.         ['match'] = {
  1002.             ['name'] = 'ComputerCraft:CC-Peripheral',
  1003.             ['damage'] = 1,
  1004.         },
  1005.  
  1006.         ['mod'] = 'Computercraft',
  1007.         ['category'] = { [1] = 'peripheral', },
  1008.  
  1009.         ['name'] = 'Wireless modem',
  1010.     },
  1011.     {
  1012.         ['match'] = {
  1013.             ['name'] = 'ComputerCraft:CC-Computer',
  1014.             ['damage'] = 0,
  1015.         },
  1016.  
  1017.         ['mod'] = 'Computercraft',
  1018.         ['category'] = { [1] = 'computer', },
  1019.  
  1020.         ['name'] = 'Computer',
  1021.     },
  1022.     {
  1023.         ['match'] = {
  1024.             ['name'] = 'ComputerCraft:CC-Computer',
  1025.             ['damage'] = 16384,
  1026.         },
  1027.  
  1028.         ['mod'] = 'Computercraft',
  1029.         ['category'] = { [1] = 'computer', },
  1030.  
  1031.         ['name'] = 'Advanced Computer',
  1032.     },
  1033.     {
  1034.         ['match'] = {
  1035.             ['name'] = 'ComputerCraft:command_computer',
  1036.             ['damage'] = 0,
  1037.         },
  1038.  
  1039.         ['mod'] = 'Computercraft',
  1040.         ['category'] = { [1] = 'computer', },
  1041.  
  1042.         ['name'] = 'Command Computer',
  1043.     },
  1044.     {
  1045.         ['match'] = {
  1046.             ['name'] = 'ComputerCraft:disk',
  1047.         },
  1048.  
  1049.         ['mod'] = 'Computercraft',
  1050.         ['category'] = { [1] = 'disk', },
  1051.  
  1052.         ['name'] = 'Floppy Disk',
  1053.     },
  1054.     {
  1055.         ['match'] = {
  1056.             ['name'] = 'ComputerCraft:diskExpanded',
  1057.         },
  1058.  
  1059.         ['mod'] = 'Computercraft',
  1060.         ['category'] = { [1] = 'computer', },
  1061.  
  1062.         ['name'] = 'Floppy Disk - Expanded',
  1063.     },
  1064.     {
  1065.         ['match'] = {
  1066.             ['name'] = 'minecraft:diamond_pickaxe',
  1067.         },
  1068.  
  1069.         ['mod'] = 'vanilla',
  1070.         ['category'] = { [1] = 'tool', },
  1071.  
  1072.         ['name'] = 'Diamond Pickaxe',
  1073.     },
  1074. }
  1075. items.has._parent = items
  1076.  
  1077. setmetatable ( items ['has'], {
  1078.     ['__call'] = function ( self, _, item )
  1079.         for _, entry in ipairs ( self._parent ) do
  1080.             if entry.match ~= nil then
  1081.                 local accept = true
  1082.                 for k, v in pairs ( entry.match ) do
  1083.                     if item [k] == nil or item [k] ~= v then
  1084.                         --error ( 'failed on: ' .. k .. ' ' .. tostring ( item [k] ) .. ' ~= ' .. v )
  1085.                         accept = false
  1086.                     end
  1087.                 end
  1088.  
  1089.                 if accept == true then
  1090.                     local _newEntry = {}
  1091.                     _newEntry._name = item.name
  1092.  
  1093.                     for k,v in pairs ( entry ) do
  1094.                         if k ~= 'match' then
  1095.                             _newEntry [k] = v
  1096.                         end
  1097.                     end
  1098.  
  1099.                     for k,v in pairs ( item ) do
  1100.                         if _newEntry [k] == nil then
  1101.                             _newEntry [k] = v
  1102.                         end
  1103.                     end
  1104.  
  1105.                     return _newEntry
  1106.                 end
  1107.             end
  1108.         end
  1109.  
  1110.         return item
  1111.     end
  1112. } )
  1113.  
  1114. return items
  1115.             ]],
  1116.             ['class/timer.lua'] = [[
  1117. local timer = {}
  1118. timer = {
  1119.     ['__event'] = nil,
  1120.     ['__data'] = {},
  1121.  
  1122.     ['init'] = function ( self )
  1123.         self.__event = _G ['_event']
  1124.     end,
  1125.  
  1126.     ['start'] = function ( self, time, name, payload )
  1127.         if payload == nil then
  1128.             payload = name
  1129.             name = nil
  1130.         end
  1131.  
  1132.         if self.__event ['timer'] == nil then
  1133.             self.__event ['timer'] = {}
  1134.         end
  1135.  
  1136.         local load = {
  1137.             ['_name'] =  name or #self.__data,
  1138.             ['name'] = function ( self, name )
  1139.                 if name == nil then return self._name end
  1140.                 self._name = name
  1141.  
  1142.                 return self
  1143.             end,
  1144.             ['time'] = time + os.clock (),
  1145.  
  1146.             ['_payload'] = payload,
  1147.             ['payload'] = function ( self, payload )
  1148.                 if payload == nil then return self._payload end
  1149.                 if type ( payload ) ~= 'function' then self._payload = nil end
  1150.  
  1151.                 self._payload = payload
  1152.                 return self
  1153.             end,
  1154.         }
  1155.  
  1156.         setmetatable ( load, {
  1157.             ['__call'] = function ( self )
  1158.                 local payload = self:payload ()
  1159.                 if type (payload) == 'function' then
  1160.                     self:payload ( false )
  1161.  
  1162.                     return payload ()
  1163.                 end
  1164.  
  1165.                 return false
  1166.             end,
  1167.         } )
  1168.  
  1169.         table.insert ( self.__data, load )
  1170.  
  1171.         self.__event ['timer'][os.startTimer (time)] = function () timer:check () end
  1172.     end,
  1173.  
  1174.     ['interval'] = function ( self, time, name, payload )
  1175.         if payload == nil then
  1176.             payload = name
  1177.             name = nil
  1178.         end
  1179.  
  1180.         if self.__event ['timer'] == nil then
  1181.             self.__event ['timer'] = {}
  1182.         end
  1183.  
  1184.         local load = {
  1185.             ['_name'] =  name or #self.__data,
  1186.             ['name'] = function ( self, name )
  1187.                 if name == nil then return self._name end
  1188.                 self._name = name
  1189.  
  1190.                 return self
  1191.             end,
  1192.             ['_interval'] = time,
  1193.             ['interval'] = function ( self, time )
  1194.                 if time == nil then return self._interval end
  1195.                 if type ( time ) ~= 'number' then self._interval = nil end
  1196.  
  1197.                 self._interval = time
  1198.                 return self
  1199.             end,
  1200.             ['time'] = time + os.clock (),
  1201.  
  1202.             ['_payload'] = payload,
  1203.             ['payload'] = function ( self, payload )
  1204.                 if payload == nil then return self._payload end
  1205.                 if type ( payload ) ~= 'function' then self._payload = nil end
  1206.  
  1207.                 self._payload = payload
  1208.                 return self
  1209.             end,
  1210.  
  1211.             ['trigger'] = function ( self )
  1212.                 if type ( self._payload ) == 'function' then self:payload () () end
  1213.                 return self
  1214.             end,
  1215.         }
  1216.  
  1217.         setmetatable ( load, {
  1218.             ['__call'] = function ( self )
  1219.                 local payload = self:payload ()
  1220.                 if type (payload) == 'function' then
  1221.                     return payload ()
  1222.                 end
  1223.  
  1224.                 return false
  1225.             end,
  1226.         } )
  1227.  
  1228.         table.insert ( self.__data, load )
  1229.  
  1230.         self.__event ['timer'][os.startTimer (time)] = function () timer:check () end
  1231.     end,
  1232.  
  1233.     ['get'] = function ( self, name )
  1234.         for _, entry in ipairs ( self.__data ) do
  1235.             if entry:name () == name then
  1236.                 return entry
  1237.             end
  1238.         end
  1239.         return false
  1240.     end,
  1241.  
  1242.     ['check'] = function ( self )
  1243.         local clock = os.clock ()
  1244.         for i = #self.__data, 1, -1 do
  1245.             local entry = self.__data [i]
  1246.  
  1247.             if clock >= entry.time - 0.05 then
  1248.                 entry ()
  1249.  
  1250.                 if entry.interval ~= nil then
  1251.                     if self.__event ['timer'] == nil then
  1252.                         self.__event ['timer'] = {}
  1253.                     end
  1254.  
  1255.                     entry.time = math.max ( entry.time, clock ) + entry:interval ()
  1256.                     self.__event ['timer'][os.startTimer (entry:interval ())] = function () timer:check () end
  1257.                 else
  1258.                     table.remove ( self.__data, i )
  1259.                 end
  1260.             end
  1261.         end
  1262.     end,
  1263.  
  1264.     ['sleep'] = function ( self, time )
  1265.  
  1266.         local abort = false
  1267.         self:start ( time, function ()
  1268.             abort = true
  1269.         end )
  1270.  
  1271.         while abort ~= true do
  1272.             local event = ({os.pullEvent ()})
  1273.             local e = table.remove ( event, 1 )
  1274.  
  1275.             local success = false
  1276.             if _G ['_event'] ~= nil and _G ['_event'][e] ~= nil then
  1277.                 if success == false and _G ['_event'] [e][ event[1] ] ~= nil then
  1278.                     if _G ['_event'] [e][ event[1] ] ( self, event ) == true then
  1279.                         success = true
  1280.                     end
  1281.                 end
  1282.  
  1283.                 if success == false and _G ['_event'] [e]['*'] ~= nil then
  1284.                     if _G ['_event'] [e]['*'] ( self, event ) == true then
  1285.                         success = true
  1286.                     end
  1287.                 end
  1288.             end
  1289.         end
  1290.        
  1291.         return self
  1292.     end,
  1293. }
  1294.  
  1295. return timer
  1296.             ]],
  1297.             ['class/menu.basic.lua'] = [[
  1298. local data = {
  1299.     ['_path'] = '/.menu',
  1300.     ['_data'] = false,
  1301.  
  1302.     ['_init'] = function ( self )
  1303.         if self._data == false then
  1304.             if fs.exists ( self._path ) == true then
  1305.                 local f = fs.open ( self._path, 'r' )
  1306.                 local content = f.readAll ()
  1307.                 f.close ()
  1308.  
  1309.                 self._data = textutils.unserialize ( content )
  1310.                 if type ( self._data ) ~= 'table' then
  1311.                     self._data = {}
  1312.                 end
  1313.             else
  1314.                 self._data = {}
  1315.             end
  1316.         end
  1317.     end,
  1318.  
  1319.     ['get'] = function ( self, key )
  1320.         self:_init ()
  1321.  
  1322.         return self._data [key]
  1323.     end,
  1324.  
  1325.     ['set'] = function ( self, key, value )
  1326.         self:_init ()
  1327.         self._data [key] = value
  1328.  
  1329.         local content = textutils.serialize ( self._data )
  1330.         local f = fs.open ( self._path, 'w' )
  1331.         f.write ( content )
  1332.         f.close ()
  1333.  
  1334.         return self
  1335.     end,
  1336. }
  1337.  
  1338.  
  1339. local width, height = term.getSize ()
  1340. local sortId = 1
  1341.  
  1342. return {
  1343.     ['_name'] = 'menu',
  1344.     ['name'] = function ( self, name )
  1345.         if name == nil then
  1346.             return self._name
  1347.         end
  1348.  
  1349.         self._name = name
  1350.         return self
  1351.     end,
  1352.  
  1353.     ['_abort'] = false,
  1354.     ['abort'] = function ( self )
  1355.         self._abort = true
  1356.  
  1357.         return self
  1358.     end,
  1359.  
  1360.     ['_verifyQuit'] = false,
  1361.     ['verifyQuit'] = function ( self, bool )
  1362.         self._verifyQuit = bool
  1363.  
  1364.         return self
  1365.     end,
  1366.  
  1367.     ['_options'] = {
  1368.         ['sort'] = function ( self )
  1369.             local keys = {}
  1370.             local copy = {}
  1371.  
  1372.             for _, opt in ipairs ( self ) do
  1373.                 local sort = opt.__sortId
  1374.                 if sort == nil then sort = opt:name () end
  1375.  
  1376.                 table.insert ( keys, sort )
  1377.                 table.insert ( copy, opt )
  1378.             end
  1379.             self:clear ()
  1380.  
  1381.             table.sort ( keys )
  1382.             for _, sort in ipairs ( keys ) do
  1383.                 for _, opt in ipairs ( copy ) do
  1384.                     if sort == opt.__sortId or opt:name () == sort then
  1385.                         table.insert ( self, opt )
  1386.                     end
  1387.                 end
  1388.             end
  1389.  
  1390.             return self
  1391.         end,
  1392.  
  1393.         ['clear'] = function ( self )
  1394.             for i = #self, 1, -1 do
  1395.                 table.remove ( self, i )
  1396.             end
  1397.  
  1398.             return self
  1399.         end,
  1400.     },
  1401.     ['option'] = function ( self, id )
  1402.         if id == nil then return self._options end
  1403.         if self._options [id] == false then return false end
  1404.         return self._options [id]
  1405.     end,
  1406.     ['clear'] = function ( self )
  1407.         self:option ():clear ()
  1408.         return self
  1409.     end,
  1410.  
  1411.     ['_select'] = 1,
  1412.     ['_offset'] = 0,
  1413.  
  1414.     ['select'] = function ( self, id )
  1415.         if id == nil then return self._select end
  1416.  
  1417.         local options = self:option ()
  1418.         local config = self:settings ()
  1419.  
  1420.         if id < 1 then id = 1 end
  1421.         if id > #options then id = #options end
  1422.  
  1423.         if id > (height - config.offset()) + self._offset then
  1424.             self._offset = id - (height - config.offset ())
  1425.         elseif id <= self._offset then
  1426.             self._offset = id - 1
  1427.         end
  1428.         if self._offset < 0 then self._offset = 0 end
  1429.  
  1430.         self._select = id
  1431.         if self:option (id) ~= nil and type ( self:option ( id )._selected ) == 'function' then
  1432.             self:option (id):_selected ()
  1433.         end
  1434.     end,
  1435.  
  1436.     ['_search'] = false,
  1437.     ['_searchStatus'] = '',
  1438.     ['_searchHidden'] = {},
  1439.     ['search'] = function ( self, search )
  1440.         if search ~= nil then
  1441.             if self._search == false and search == ' ' then
  1442.                 search = ''
  1443.             end
  1444.  
  1445.             if search == '' then
  1446.                 self._search = false
  1447.             else
  1448.                 if self._search == false then
  1449.                     self._searchStatus = self._status
  1450.                 end
  1451.  
  1452.                 self._search = search
  1453.             end
  1454.         end
  1455.  
  1456.         local options = {}
  1457.         for _, opt in ipairs ( self._options ) do table.insert ( options, opt ) end
  1458.         for _, opt in ipairs ( self._searchHidden ) do table.insert ( options, opt ) end
  1459.         self._searchHidden = {}
  1460.         self:option ():clear ()
  1461.  
  1462.         if self._search ~= false then
  1463.             self:status ( 'Search:' .. self._search )
  1464.  
  1465.             for _, opt in ipairs ( options ) do
  1466.                 if self._search == '' or tostring ( opt:name () ):lower():match ( self._search:lower() ) then
  1467.                     table.insert ( self._options, opt )
  1468.                 else
  1469.                     table.insert ( self._searchHidden, opt )
  1470.                 end
  1471.             end
  1472.         else
  1473.             for _, opt in ipairs ( options ) do table.insert ( self._options, opt ) end
  1474.             self:status ( self._searchStatus )
  1475.         end
  1476.  
  1477.         self:option ():sort ()
  1478.         self:select ( self:select() )
  1479.     end,
  1480.  
  1481.     ['_option'] = {
  1482.         ['__sortId'] = 1/0,
  1483.  
  1484.         ['_parent'] = false,
  1485.         ['parent'] = function ( self, parent )
  1486.             if parent == nil then return self._parent end
  1487.             self._parent = parent
  1488.             return self
  1489.         end,
  1490.  
  1491.         ['_name'] = 'menu:option',
  1492.         ['name'] = function ( self, name )
  1493.             if name == nil then
  1494.                 return self._name
  1495.             end
  1496.  
  1497.             self._name = name
  1498.             return self
  1499.         end,
  1500.  
  1501.         ['_type'] = 'basic',
  1502.         ['type'] = function ( self, name )
  1503.             if name == nil then return self._type end
  1504.  
  1505.             local data = {}
  1506.             if name ~= 'basic' then
  1507.                 data = i.files:run ( 'class/menu.basic/' .. name .. '.lua' )
  1508.             end
  1509.             self._type = name
  1510.  
  1511.             local remove = {}
  1512.             for k,_ in pairs ( self ) do
  1513.                 if self._parent._option [k] == nil then
  1514.                     table.insert ( remove, k )
  1515.                 else
  1516.                     if k:sub ( 1,1 ) ~= '_' then
  1517.                         self [k] = self._parent._option [k]
  1518.                     end
  1519.                 end
  1520.             end
  1521.  
  1522.             for _, key in ipairs ( remove ) do self [key] = nil end
  1523.             remove = nil
  1524.  
  1525.             local d = function () end
  1526.             d = function ( self, data )
  1527.                 for k,v in pairs ( data ) do
  1528.                     if type ( self [k] ) == 'table' and type ( data [k] ) == 'table' then
  1529.                         self [k] = d ( self [k], data [k] )
  1530.                     else
  1531.                         self [k] = data [k]
  1532.                     end
  1533.                 end
  1534.  
  1535.                 return self
  1536.             end
  1537.  
  1538.             self = d ( self, data )
  1539.             self.type = self._parent._option.type
  1540.  
  1541.             return self
  1542.         end,
  1543.  
  1544.         ['_update'] = false,
  1545.         ['update'] = function ( self, func )
  1546.             if func == nil then return self._update end
  1547.             if type(func) ~= 'function' then return false end
  1548.  
  1549.             self._update = func
  1550.             return self
  1551.         end,
  1552.  
  1553.         ['event'] = false,
  1554.         ['toString'] = function ( self )
  1555.             return string.rep ( ' ', self._parent:settings ().options.indent ) .. self:name ()
  1556.         end,
  1557.  
  1558.         ['_selected'] = nil,
  1559.         ['selected'] = function ( self, func )
  1560.             if func == nil then return self._selected end
  1561.             self._selected = func
  1562.  
  1563.             return self
  1564.         end,
  1565.     },
  1566.  
  1567.     ['create'] = function ( self, name )
  1568.         local opt = {}
  1569.         for k,v in pairs ( self._option ) do opt [k] = v end
  1570.  
  1571.         opt:parent ( self )
  1572.         opt:name ( name )
  1573.  
  1574.         opt.__sortId = sortId
  1575.         sortId = sortId + 1
  1576.  
  1577.         table.insert ( self._options, opt )
  1578.         self:option ():sort ()
  1579.  
  1580.         return opt
  1581.     end,
  1582.  
  1583.     ['_status'] = '[Enter][Backspace] - [Up]/[Down]',
  1584.     ['status'] = function ( self, message )
  1585.         if message ~= nil then
  1586.             self._status = message
  1587.         end
  1588.         local config = self:settings ()
  1589.         if config.status () == false then return end
  1590.  
  1591.         term.setBackgroundColor ( config.status.background )
  1592.         term.setTextColor ( config.status.text )
  1593.         term.setCursorPos ( 1, height )
  1594.         term.clearLine ()
  1595.  
  1596.         term.write ( self._status )
  1597.  
  1598.         if message == nil then
  1599.             return self._status
  1600.         end
  1601.     end,
  1602.  
  1603.     ['event'] = {
  1604.         ['key'] = {
  1605.             ['*'] = function ( self, event )
  1606.                 --self:status ( 'key: ' .. tostring ( event [1] ) )
  1607.             end,
  1608.  
  1609.             [59] = function ( self ) -- F1
  1610.                 self:help ()
  1611.                 return true
  1612.             end,
  1613.             [62] = function ( self )
  1614.                 self:setup ()
  1615.             end,
  1616.  
  1617.             [88] = function ( self )
  1618.                 os.reboot ()
  1619.  
  1620.                 return true
  1621.             end,
  1622.  
  1623.             [199] = function ( self ) -- [Home]
  1624.                 self:select ( 1 )
  1625.                 return true
  1626.             end,
  1627.             [207] = function ( self ) -- [End]
  1628.                 self:select ( #self:option() )
  1629.                 return true
  1630.             end,
  1631.  
  1632.             [201] = function ( self ) -- [Page up]
  1633.                 self:select ( self:select() - (height - self:settings ().offset ()) )
  1634.                 return true
  1635.             end,
  1636.             [209] = function ( self ) -- [Page down]
  1637.                 self:select ( self:select() + (height - self:settings ().offset ()) )
  1638.                 return true
  1639.             end,
  1640.  
  1641.             [200] = function ( self ) -- [Up]
  1642.                 self:select ( self:select () - 1 )
  1643.                 return true
  1644.             end,
  1645.             [208] = function ( self ) -- [Down]
  1646.                 self:select ( self:select () + 1 )
  1647.                 return true
  1648.             end,
  1649.  
  1650.             [14] = function ( self, event )
  1651.                 local search = self._search
  1652.                 if search == false then
  1653.                     if self._verifyQuit == true then
  1654.                         local status = self._status
  1655.                         self:status ( 'Confirm quit, [Backspace] again' )
  1656.  
  1657.                         local _, key = os.pullEvent ( 'key' )
  1658.  
  1659.                         if key == event [1] then
  1660.                             self:abort ()
  1661.                         end
  1662.  
  1663.                         self:status ( status )
  1664.                     else
  1665.                         self:abort ()
  1666.                     end
  1667.                 else
  1668.                     if search == '' then
  1669.                         self:search ( false )
  1670.                     else
  1671.                         search = search:sub ( 1, #search - 1 )
  1672.                         self:search ( search )
  1673.                     end
  1674.                 end
  1675.  
  1676.                 return true
  1677.             end,
  1678.         },
  1679.         ['char'] = {
  1680.             ['*'] = function ( self, event )
  1681.                 local search = self._search
  1682.                 if search == false then search = '' end
  1683.                 if search == '' and event [1] == ' ' then event [1] = '' end
  1684.  
  1685.                 if event [1]:match ( '[A-Za-z0-9 ]' ) then
  1686.                     self:search ( search .. event [1] )
  1687.                 end
  1688.  
  1689.                 return true
  1690.             end,
  1691.         },
  1692.     },
  1693.  
  1694.     ['run'] = function ( self )
  1695.         if i ~= nil and data ~= nil then
  1696.             if data:get ( 'menu.tutorial.show' ) ~= false then
  1697.                 self:help ()
  1698.                 data:set ( 'menu.tutorial.show', false )
  1699.             end
  1700.         end
  1701.  
  1702.         local time = 0
  1703.         self:select ( self:select () )
  1704.         while self._abort ~= true do
  1705.             if time + 0.05 < os.clock () then
  1706.                 self:draw ()
  1707.                 time = os.clock ()
  1708.             end
  1709.  
  1710.             local event = ({os.pullEvent ()})
  1711.             local e = table.remove ( event, 1 )
  1712.  
  1713.             local success = false
  1714.  
  1715.             local opt = self:option ( self:select() )
  1716.             if opt ~= nil and opt.event ~= false and opt.event [e] ~= nil then
  1717.                 if success == false and opt ~= false and event [1] ~= nil and opt.event [e][ event[1] ] ~= nil then
  1718.                     if opt.event [e][ event[1] ] ( opt, event ) == true then
  1719.                         success = true
  1720.                     end
  1721.                 end
  1722.  
  1723.                 if success == false and opt ~= false and opt.event [e]['*'] ~= nil then
  1724.                     if opt.event [e]['*'] ( opt, event ) == true then
  1725.                         success = true
  1726.                     end
  1727.                 end
  1728.             end
  1729.             opt = nil
  1730.  
  1731.             if self.event [e] ~= nil then
  1732.                 if success == false and self.event [e][ event[1] ] ~= nil then
  1733.                     if self.event [e][ event[1] ] ( self, event ) == true then
  1734.                         success = true
  1735.                     end
  1736.                 end
  1737.  
  1738.                 if success == false and self.event [e]['*'] ~= nil then
  1739.                     if self.event [e]['*'] ( self, event ) == true then
  1740.                         success = true
  1741.                     end
  1742.                 end
  1743.             end
  1744.  
  1745.             if _G ['_event'] ~= nil and _G ['_event'][e] ~= nil then
  1746.                 if success == false and _G ['_event'] [e][ event[1] ] ~= nil then
  1747.                     if _G ['_event'] [e][ event[1] ] ( self, event ) == true then
  1748.                         success = true
  1749.                     end
  1750.                 end
  1751.  
  1752.                 if success == false and _G ['_event'] [e]['*'] ~= nil then
  1753.                     if _G ['_event'] [e]['*'] ( self, event ) == true then
  1754.                         success = true
  1755.                     end
  1756.                 end
  1757.             end
  1758.         end
  1759.         self._abort = false
  1760.  
  1761.         term.setBackgroundColor ( colors.black )
  1762.         term.setTextColor ( colors.white )
  1763.         term.setCursorPos ( 1,1 )
  1764.         term.clear ()
  1765.     end,
  1766.  
  1767.     ['draw'] = function ( self )
  1768.         local config = self:settings ()
  1769.  
  1770.         term.setBackgroundColor ( config.options.background )
  1771.         term.setTextColor ( config.options.text )
  1772.         term.clear ()
  1773.  
  1774.         if config.header ~= false then
  1775.             term.setBackgroundColor ( config.header.background )
  1776.             term.setTextColor ( config.header.text )
  1777.  
  1778.             term.setCursorPos ( 3,1 )
  1779.             term.clearLine ()
  1780.             term.setCursorPos ( 3,2 )
  1781.             term.clearLine ()
  1782.  
  1783.             term.write ( self._name )
  1784.         end
  1785.  
  1786.         for i = 1, height - config.offset () do
  1787.             term.setBackgroundColor ( config.options.background )
  1788.             term.setTextColor ( config.options.text )
  1789.  
  1790.             term.setCursorPos ( 4, config.offset.top + i )
  1791.             term.clearLine ()
  1792.  
  1793.             if self._offset + i == self:select () then
  1794.                 term.setBackgroundColor ( config.selection.background )
  1795.                 term.setTextColor ( config.selection.text )
  1796.             end
  1797.  
  1798.             local opt = self:option ( self._offset + i )
  1799.             if opt ~= nil then
  1800.                 if opt.draw ~= nil then
  1801.                     opt:draw ()
  1802.                 else
  1803.                     local str = tostring ( opt:toString () )
  1804.                     str = str:sub ( 1, width - 7 )
  1805.  
  1806.                     str = str .. string.rep ( ' ', math.max ( 0, width - #str - 7) )
  1807.  
  1808.                     term.write ( str )
  1809.                 end
  1810.             end
  1811.         end
  1812.  
  1813.         self:status ()
  1814.     end,
  1815.  
  1816.     ['_help'] = {
  1817.         {
  1818.             '',
  1819.             ' Help (Keybinds)',
  1820.             '',
  1821.             '  [Enter] Executes the selected option',
  1822.             '  [Backspace] Goes back a step',
  1823.             '  [Up] Selects the menu option above ',
  1824.             '  [Down] Selects the menu option below ',
  1825.             '  [F1] Opens this help screen',
  1826.             '  [F4] Setup (May be disabled)',
  1827.         },
  1828.         {
  1829.             '',
  1830.             ' Help (Keybinds)',
  1831.             '',
  1832.             '  [Page up] Goes up a page',
  1833.             '  [Page down] Goes down a page',
  1834.             '  [Home] Goes to first option',
  1835.             '  [End] Goes to last option',
  1836.             '',
  1837.             '  Do note that various custom options',
  1838.             '  may have their own keybinds, and as',
  1839.             '  such, they are not shown here',
  1840.         },
  1841.         {
  1842.             '',
  1843.             ' Search',
  1844.             '  The menu options can be searched in',
  1845.             '  simply by typing whichever you wish ',
  1846.             '  to search for, to stop searching ',
  1847.             '  repeat press backspace until the ',
  1848.             '  search is gone.',
  1849.         },
  1850.     },
  1851.     ['help'] = function ( self, page )
  1852.         if type ( page ) == 'boolean' then self._help = false end
  1853.         if self._help == false then return end
  1854.  
  1855.         term.setBackgroundColor ( colors.black )
  1856.         term.setTextColor ( colors.white )
  1857.  
  1858.         local s = function ( page, lines )
  1859.             if lines == nil then
  1860.                 lines = page
  1861.                 page = nil
  1862.             end
  1863.  
  1864.             term.clear ()
  1865.  
  1866.             for i, message in ipairs ( lines ) do
  1867.                 term.setCursorPos ( 1, i )
  1868.                 term.write ( message )
  1869.             end
  1870.  
  1871.             term.setCursorPos ( 1, height )
  1872.            
  1873.             local message = 'Press any key to continue'
  1874.             if page ~= nil then
  1875.                 local status = page ..'/' .. #self._help
  1876.                 message = message .. string.rep ( ' ', width - #status - 25 ) .. status
  1877.             end
  1878.  
  1879.             term.write ( message )
  1880.             os.pullEvent ( 'key' )
  1881.         end
  1882.  
  1883.         if type ( page ) == 'table' then
  1884.             s ( page )
  1885.  
  1886.             return self
  1887.         end
  1888.  
  1889.         for page, lines in ipairs ( self._help ) do
  1890.             s ( page, lines )
  1891.         end
  1892.  
  1893.         return self
  1894.     end,
  1895.  
  1896.     ['_settings'] = false,
  1897.     ['settings'] = function ( self )
  1898.         if self._settings ~= false then
  1899.             return self._settings
  1900.         end
  1901.  
  1902.         local config = {
  1903.             ['offset'] = {
  1904.                 ['top'] = 1,
  1905.                 ['bottom'] = 1,
  1906.             },
  1907.             ['status'] = {
  1908.                 ['_status'] = true,
  1909.             },
  1910.             ['header'] = {
  1911.                 ['_header'] = true,
  1912.  
  1913.             },
  1914.             ['options'] = {
  1915.  
  1916.             },
  1917.             ['selection'] = {
  1918.  
  1919.             },
  1920.         }
  1921.  
  1922.         setmetatable  ( config ['offset'], {
  1923.             ['__call'] = function ( self )
  1924.                 return self.top + self.bottom
  1925.             end,
  1926.         } )
  1927.  
  1928.         setmetatable ( config ['header'], {
  1929.             ['__call'] = function ( self, value )
  1930.                 if value == nil then return self._header end
  1931.                 self._header = value
  1932.             end,
  1933.         } )
  1934.  
  1935.         setmetatable ( config ['status'], {
  1936.             ['__call'] = function ( self, value )
  1937.                 if value == nil then return self._status end
  1938.                 self._status = value
  1939.             end,
  1940.         } )
  1941.  
  1942.  
  1943.  
  1944.         config.width,config.height = term.getSize ()
  1945.  
  1946.         if data:get ( 'menu.' .. self:name () .. '.setup.header' ) == false then
  1947.             config.header ( false )
  1948.         else
  1949.             config.header ( true )
  1950.             config.offset.top = config.offset.top + 2
  1951.         end
  1952.  
  1953.         if data:get ( 'menu.' .. self:name () .. '.setup.status' ) == false then
  1954.             config.status ( false )
  1955.         else
  1956.             config.status ( true )
  1957.             config.offset.bottom = config.offset.bottom + 1
  1958.         end
  1959.  
  1960.         config.status.background = data:get ( 'menu.' .. self:name () .. '.setup.status.background' )
  1961.         if type ( config.status.background ) ~= 'number' then
  1962.             config.status.background = colors.white
  1963.         end
  1964.  
  1965.         config.status.text = data:get ( 'menu.' .. self:name () .. '.setup.status.text' )
  1966.         if type ( config.status.text ) ~= 'number' then
  1967.             config.status.text = colors.black
  1968.         end
  1969.  
  1970.         config.header.background = data:get ( 'menu.' .. self:name () .. '.setup.header.background' )
  1971.         if type ( config.header.background ) ~= 'number' then
  1972.             config.header.background = colors.black
  1973.         end
  1974.  
  1975.         config.header.text = data:get ( 'menu.' .. self:name () .. '.setup.header.text' )
  1976.         if type ( config.header.text ) ~= 'number' then
  1977.             config.header.text = colors.white
  1978.         end
  1979.  
  1980.         config.options.background = data:get ( 'menu.' .. self:name () .. '.setup.options.background' )
  1981.         if type ( config.options.background ) ~= 'number' then
  1982.             config.options.background = colors.black
  1983.         end
  1984.  
  1985.         config.options.text = data:get ( 'menu.' .. self:name () .. '.setup.options.text' )
  1986.         if type ( config.options.text ) ~= 'number' then
  1987.             config.options.text = colors.white
  1988.         end
  1989.  
  1990.         config.selection.background = data:get ( 'menu.' .. self:name () .. '.setup.selection.background' )
  1991.         if type ( config.selection.background ) ~= 'number' then
  1992.             config.selection.background = colors.white
  1993.         end
  1994.  
  1995.         config.selection.text = data:get ( 'menu.' .. self:name () .. '.setup.selection.text' )
  1996.         if type ( config.selection.text ) ~= 'number' then
  1997.             config.selection.text = colors.black
  1998.         end
  1999.  
  2000.         config.options.indent = data:get ( 'menu.' .. self:name () .. '.setup.options.indent' )
  2001.         if type ( config.options.indent ) ~= 'number' then
  2002.             config.options.indent = 0
  2003.         end
  2004.  
  2005.         self._settings = config
  2006.         return config
  2007.     end,
  2008.  
  2009.     ['_setup'] = true,
  2010.     ['setup'] = function ( self, bool )
  2011.         if type ( bool ) == 'boolean' then
  2012.             self._setup = bool
  2013.  
  2014.             return self
  2015.         end
  2016.  
  2017.         if self._setup ~= true then return self end
  2018.  
  2019.         local menu = i.files:run ( 'class/menu.basic.lua' )
  2020.         menu.name = function () return self:name () end
  2021.         menu._name = 'Menu setup for: ' .. menu:name ()
  2022.         menu:setup ( false )
  2023.  
  2024.         local opt = menu:create ( 'Display: Header' )
  2025.         opt:type ( 'bool' )
  2026.         opt:bool ( data:get ( 'menu.' .. self:name () .. '.setup.header' ) )
  2027.         opt:update ( function ( opt )
  2028.             data:set ( 'menu.' .. self:name () .. '.setup.header', opt:bool () )
  2029.            
  2030.             self._settings = false
  2031.             menu._settings = false
  2032.         end )
  2033.  
  2034.         local opt = menu:create ( 'Display: Status' )
  2035.         opt:type ( 'bool' )
  2036.         opt:bool ( data:get ( 'menu.' .. self:name () .. '.setup.status' ) )
  2037.         opt:update ( function ( opt )
  2038.             data:set ( 'menu.' .. self:name () .. '.setup.status', opt:bool () )
  2039.            
  2040.             menu._settings = false
  2041.         end )
  2042.  
  2043.         local opt = menu:create ( 'Header: Background' )
  2044.         opt:type ( 'color' )
  2045.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.header.background' ) or colors.black )
  2046.         opt:update ( function ( opt )
  2047.             data:set ( 'menu.' .. self:name () .. '.setup.header.background', opt:color () )
  2048.            
  2049.             menu._settings = false
  2050.         end )
  2051.  
  2052.         local opt = menu:create ( 'Header: Text' )
  2053.         opt:type ( 'color' )
  2054.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.header.text' ) or colors.white )
  2055.         opt:update ( function ( opt )
  2056.             data:set ( 'menu.' .. self:name () .. '.setup.header.text', opt:color () )
  2057.            
  2058.             menu._settings = false
  2059.         end )
  2060.  
  2061.         local opt = menu:create ( 'Status: Background' )
  2062.         opt:type ( 'color' )
  2063.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.status.background' ) or colors.white )
  2064.         opt:update ( function ( opt )
  2065.             data:set ( 'menu.' .. self:name () .. '.setup.status.background', opt:color () )
  2066.            
  2067.             menu._settings = false
  2068.         end )
  2069.  
  2070.         local opt = menu:create ( 'Status: Text' )
  2071.         opt:type ( 'color' )
  2072.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.status.text' ) or colors.black )
  2073.         opt:update ( function ( opt )
  2074.             data:set ( 'menu.' .. self:name () .. '.setup.status.text', opt:color () )
  2075.  
  2076.             menu._settings = false
  2077.         end )
  2078.  
  2079.         local opt = menu:create ( 'Selection: Indent' )
  2080.         opt:type ( 'number' )
  2081.         opt:number ( data:get ( 'menu.' .. self:name () .. '.setup.options.indent' ) or 0 )
  2082.         opt:min ( 0 ):max ( 10 )
  2083.         opt:update ( function ( opt )
  2084.             data:set ( 'menu.' .. self:name () .. '.setup.options.indent', opt:number () )
  2085.  
  2086.             menu._settings = false
  2087.         end )
  2088.  
  2089.         local opt = menu:create ( 'Selection: Background' )
  2090.         opt:type ( 'color' )
  2091.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.selection.background' ) or colors.white )
  2092.         opt:update ( function ( opt )
  2093.             data:set ( 'menu.' .. self:name () .. '.setup.selection.background', opt:color () )
  2094.            
  2095.             menu._settings = false
  2096.         end )
  2097.  
  2098.         local opt = menu:create ( 'Selection: Text' )
  2099.         opt:type ( 'color' )
  2100.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.selection.text' ) or colors.black )
  2101.         opt:update ( function ( opt )
  2102.             data:set ( 'menu.' .. self:name () .. '.setup.selection.text', opt:color () )
  2103.  
  2104.             menu._settings = false
  2105.         end )
  2106.  
  2107.         local opt = menu:create ( 'Options: Background' )
  2108.         opt:type ( 'color' )
  2109.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.options.background' ) or colors.black )
  2110.         opt:update ( function ( opt )
  2111.             data:set ( 'menu.' .. self:name () .. '.setup.options.background', opt:color () )
  2112.            
  2113.             menu._settings = false
  2114.         end )
  2115.  
  2116.         local opt = menu:create ( 'Options: Text' )
  2117.         opt:type ( 'color' )
  2118.         opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.options.text' ) or colors.white )
  2119.         opt:update ( function ( opt )
  2120.             data:set ( 'menu.' .. self:name () .. '.setup.options.text', opt:color () )
  2121.  
  2122.             menu._settings = false
  2123.         end )
  2124.  
  2125.        
  2126.  
  2127.         menu:run ()
  2128.         self._settings = false
  2129.  
  2130.         menu = nil
  2131.         return true
  2132.     end,
  2133. }
  2134.             ]],
  2135.             ['class/menu.basic/bool.lua'] = [[
  2136. local width, height = term.getSize ()
  2137.  
  2138. return {
  2139.     ['_selected'] = function ( self )
  2140.     end,
  2141.  
  2142.     ['_bool'] = true,
  2143.     ['bool'] = function ( self, bool )
  2144.         if bool == nil then return self._bool end
  2145.         if bool == true then
  2146.             self._bool = true
  2147.         else
  2148.             self._bool = false
  2149.         end
  2150.  
  2151.         if type ( self._update ) == 'function' then self._update ( self ) end
  2152.         return self
  2153.     end,
  2154.  
  2155.     ['_readonly'] = false,
  2156.     ['readonly'] = function ( self, bool )
  2157.         if bool == nil then return self._bool end
  2158.         if bool == true then
  2159.             self._bool = true
  2160.         else
  2161.             self._bool = false
  2162.         end
  2163.  
  2164.         return self
  2165.     end,
  2166.  
  2167.     ['event'] = {
  2168.         ['key'] = {
  2169.             [205] = function ( self )
  2170.                 self:bool ( true )
  2171.                 return true
  2172.             end,
  2173.             [203] = function ( self )
  2174.                 self:bool ( false )
  2175.                 return true
  2176.             end,
  2177.         }
  2178.     },
  2179.  
  2180.     ['toString'] = function ( self )
  2181.         local str = string.rep ( ' ', self._parent:settings ().options.indent ) .. self:name ()
  2182.         if #str > math.max ( 0, width - 7 - #str - (#tostring ( self:bool() ) + 2 )) or true then
  2183.             str:sub ( 1, math.max ( 0, width - 7 - #str - (#tostring ( self:bool() ) + 2 )) )
  2184.         end
  2185.  
  2186.         return str .. string.rep ( ' ', math.max ( 0, width - 7 - #str - (#tostring ( self:bool() ) + 2 )) ) ..' '.. tostring ( self:bool() )
  2187.     end,
  2188. }
  2189.             ]],
  2190.             ['class/menu.basic/color.lua'] = [[
  2191. return {
  2192.     ['_selected'] = function ( self )
  2193.         if i.settings:get ( 'menu.tutorial.color.show' ) ~= false then
  2194.             self._parent:help ( {
  2195.                 '',
  2196.                 ' Help (Menu option selection)',
  2197.                 '',
  2198.                 '   Color selector',
  2199.                 '  Use [Left]/[Right] to change color',
  2200.             } )
  2201.  
  2202.             i.settings:set ( 'menu.tutorial.color.show', false )
  2203.         end
  2204.     end,
  2205.  
  2206.     ['__colors'] = {
  2207.         [colors.white] = true,
  2208.         [colors.orange] = false,
  2209.         [colors.magenta] = false,
  2210.         [colors.lightBlue] = false,
  2211.         [colors.yellow] = false,
  2212.         [colors.lime] = false,
  2213.         [colors.pink] = false,
  2214.         [colors.gray] = true,
  2215.         [colors.lightGray] = true,
  2216.         [colors.cyan] = false,
  2217.         [colors.purple] = false,
  2218.         [colors.blue] = false,
  2219.         [colors.brown] = false,
  2220.         [colors.green] = false,
  2221.         [colors.red] = false,
  2222.         [colors.black] = true,
  2223.     },
  2224.     ['_color'] = colors.white,
  2225.     ['color'] = function ( self, color )
  2226.         if color == nil then return self._color end
  2227.         if self.__colors [color] == nil then return false end
  2228.         if term.isColor () == false and self.__colors [color] == false then return false end
  2229.  
  2230.         self._color = color
  2231.  
  2232.         if type ( self._update ) == 'function' then self._update ( self ) end
  2233.         return self
  2234.     end,
  2235.     ['event'] = {
  2236.         ['key'] = {
  2237.             [205] = function ( self )
  2238.                 local current = self:color ()
  2239.                 local _next = false
  2240.  
  2241.                 for color in pairs ( self.__colors ) do
  2242.                     if term.isColor () == false then
  2243.                         if self.__colors [color] == true then
  2244.                             if _next == true then
  2245.                                 self:color ( color )
  2246.                                 break
  2247.                             end
  2248.  
  2249.                             if current == color then
  2250.                                 _next = true
  2251.                             end
  2252.                         end
  2253.                     else
  2254.                         if _next == true then
  2255.                             self:color ( color )
  2256.                             break
  2257.                         end
  2258.  
  2259.                         if current == color then
  2260.                             _next = true
  2261.                         end
  2262.                     end
  2263.                 end
  2264.  
  2265.                 return true
  2266.             end,
  2267.             [203] = function ( self )
  2268.                 local current = self:color ()
  2269.                 local _prev = false
  2270.  
  2271.                 for color in pairs ( self.__colors ) do
  2272.                     if term.isColor () == false then
  2273.                         if self.__colors [color] == true then
  2274.                             if current == color then
  2275.                                 self:color ( _prev )
  2276.                                 break
  2277.                             end
  2278.  
  2279.                             _prev = color
  2280.                         end
  2281.                     else
  2282.                         if current == color then
  2283.                             self:color ( _prev )
  2284.                             break
  2285.                         end
  2286.  
  2287.                         _prev = color
  2288.                     end
  2289.                 end
  2290.  
  2291.                 return true
  2292.             end,
  2293.         }
  2294.     },
  2295.  
  2296.     ['draw'] = function ( self )
  2297.         local width = self._parent:settings ().width
  2298.  
  2299.         local str = string.rep ( ' ', self._parent:settings ().options.indent ) .. self:toString ()
  2300.         str = str:sub ( 1, width - 14 )
  2301.         if #str < width - 12 then
  2302.             str = str .. string.rep ( ' ', width - #str - 13 )
  2303.         end
  2304.  
  2305.         local color = term.getBackgroundColor ()
  2306.         term.write ( str .. '[' )
  2307.         term.setBackgroundColor ( self:color () )
  2308.         term.write ( '    ' )
  2309.  
  2310.         term.setBackgroundColor ( color )
  2311.         term.write ( ']' )
  2312.     end,
  2313.  
  2314.     ['toString'] = function ( self )
  2315.         return self:name ()
  2316.     end,
  2317. }
  2318.             ]],
  2319.             ['class/menu.basic/execute.lua'] = [[
  2320. return {
  2321.     ['_run'] = false,
  2322.     ['run'] = function ( self, input )
  2323.         if input == nil then return self._run end
  2324.         self._run = input
  2325.  
  2326.         return self
  2327.     end,
  2328.  
  2329.     ['event'] = {
  2330.         ['key'] = {
  2331.             [28] = function ( self, event ) -- [Enter]
  2332.                 local run = self:run ()
  2333.                 if run == false or run == nil then return true end
  2334.  
  2335.                 if type ( run ) == 'function' then
  2336.                     run ( self, event )
  2337.                 elseif type ( run ) == 'string' then
  2338.                     if run:sub ( 1, 4 ) == 'http' then
  2339.                         i.files:run ( run )
  2340.                     elseif fs.exists ( run ) == true then
  2341.                         loadfile ( run ) ()
  2342.                     end
  2343.                 end
  2344.  
  2345.                 return true
  2346.             end,
  2347.         }
  2348.     }
  2349. }
  2350.             ]],
  2351.             ['class/menu.basic/number.lua'] = [[
  2352. local width, height = term.getSize ()
  2353.  
  2354. return {
  2355.     ['_selected'] = function ( self )
  2356.         if i.settings:get ( 'menu.tutorial.number.show' ) ~= false then
  2357.             self._parent:help ( {
  2358.                 '',
  2359.                 ' Help (Menu option selection)',
  2360.                 '',
  2361.                 '   Number selector',
  2362.                 '  Use [Left] to select false',
  2363.                 '  Use [Right] to select true',
  2364.             } )
  2365.  
  2366.             i.settings:set ( 'menu.tutorial.number.show', false )
  2367.         end
  2368.     end,
  2369.  
  2370.     ['_number'] = 1,
  2371.     ['number'] = function ( self, number )
  2372.         if number == nil then return self._number end
  2373.         if type(number) ~= 'number' then return false end
  2374.  
  2375.         if number > self:max () then
  2376.             number = self:max ()
  2377.         elseif number < self:min () then
  2378.             number = self:min ()
  2379.         end
  2380.  
  2381.         self._number = number
  2382.  
  2383.         if type ( self._update ) == 'function' then self._update ( self ) end
  2384.         return self
  2385.     end,
  2386.  
  2387.     ['_step'] = 1,
  2388.     ['step'] = function ( self, number )
  2389.         if number == nil then return self._step end
  2390.         if type(number) ~= 'number' then return false end
  2391.  
  2392.         self._step = number
  2393.         return self
  2394.     end,
  2395.  
  2396.     ['_max'] = 1/0,
  2397.     ['max'] = function ( self, number )
  2398.         if number == nil then return self._max end
  2399.         if type(number) ~= 'number' then return false end
  2400.         self._max = number
  2401.  
  2402.         if self:number () > number then
  2403.             self:number ( number )
  2404.         end
  2405.  
  2406.         return self
  2407.     end,
  2408.  
  2409.     ['_min'] = 0 - 1/0,
  2410.     ['min'] = function ( self, number )
  2411.         if number == nil then return self._min end
  2412.         if type(number) ~= 'number' then return false end
  2413.         self._min = number
  2414.  
  2415.         if self:number () < number then
  2416.             self:number ( number )
  2417.         end
  2418.  
  2419.         return self
  2420.     end,
  2421.  
  2422.     ['_readonly'] = false,
  2423.     ['readonly'] = function ( self, bool )
  2424.         if bool == nil then return self._readonly end
  2425.         if bool == true then
  2426.             self._readonly = true
  2427.         else
  2428.             self._readonly = false
  2429.         end
  2430.  
  2431.         return self
  2432.     end,
  2433.  
  2434.     ['_shift'] = false,
  2435.     ['_ctrl'] = false,
  2436.  
  2437.     ['event'] = {
  2438.         ['key'] = {
  2439.             [205] = function ( self )
  2440.                 if self:readonly () == false then
  2441.                     local multiplier = 1
  2442.                     if self._shift == true then multiplier = multiplier * 10 end
  2443.                     if self._ctrl == true then multiplier = multiplier * 100 end
  2444.                    
  2445.                     self:number ( self:number () + (self:step () * multiplier) )
  2446.                 end
  2447.             end,
  2448.             [203] = function ( self )
  2449.                 if self:readonly () == false then
  2450.                     local multiplier = 1
  2451.                     if self._shift == true then multiplier = multiplier * 10 end
  2452.                     if self._ctrl == true then multiplier = multiplier * 100 end
  2453.  
  2454.                     self:number ( self:number () - (self:step () * multiplier) )
  2455.                 end
  2456.             end,
  2457.             [211] = function ( self )
  2458.                 if self:readonly () == false then
  2459.                     self:number ( math.max ( self:min (), 1 ) )
  2460.                 end
  2461.             end,
  2462.  
  2463.             [42] = function ( self )
  2464.                 self._shift = true
  2465.             end,
  2466.             [29] = function ( self )
  2467.                 self._ctrl = true
  2468.             end,
  2469.         },
  2470.         ['key_up'] = {
  2471.             [42] = function ( self )
  2472.                 self._shift = false
  2473.             end,
  2474.             [29] = function ( self )
  2475.                 self._ctrl = false
  2476.             end,
  2477.         }
  2478.     },
  2479.  
  2480.     ['toString'] = function ( self )
  2481.         local str = string.rep ( ' ', self._parent:settings ().options.indent ) .. self:name ()
  2482.         if #str > math.max ( 0, width - 7 - #str - (#tostring ( self:number() ) + 2 )) or true then
  2483.             str:sub ( 1, math.max ( 0, width - 7 - #str - (#tostring ( self:number() ) + 2 )) )
  2484.         end
  2485.  
  2486.         return str .. string.rep ( ' ', math.max ( 0, width - 7 - #str - (#tostring ( self:number() ) + 2 )) ) ..' '.. self:number()
  2487.     end,
  2488. }
  2489.             ]],
  2490.            
  2491.  
  2492.         },
  2493.  
  2494.         ['get'] = function ( self, file )
  2495.             if file == nil then
  2496.                 error ( 'files.get, no file name provided' )
  2497.                 return false
  2498.             end
  2499.  
  2500.             if self._data [file] == nil then
  2501.                 local h = http.get ( self._url .. file )
  2502.                 if h == nil then
  2503.                     error ( 'files.run, file not found (' .. file ..')' )
  2504.                     return false
  2505.                 end
  2506.  
  2507.                 self._data [file] = h.readAll ()
  2508.             end
  2509.  
  2510.             return self._data [file]
  2511.         end,
  2512.  
  2513.         ['run'] = function ( self, file )
  2514.             if file == nil then
  2515.                 error ( 'files.run, no file name provided' )
  2516.                 return false
  2517.             end
  2518.  
  2519.             local content = self:get ( file )
  2520.             if content == false then
  2521.                 error ( 'files.run, file not found' )
  2522.                 return false
  2523.             end
  2524.  
  2525.             local func, message = assert ( load ( content, '=' .. file, 't', _G ) )
  2526.             return func ()
  2527.         end,
  2528.  
  2529.         ['clear'] = function ( self, file )
  2530.             self._data [file] = nil
  2531.         end,
  2532.     },
  2533.  
  2534.     ['settings'] = {
  2535.         ['_path'] = '/.settings',
  2536.         ['_data'] = false,
  2537.  
  2538.         ['_init'] = function ( self )
  2539.             if self._data == false then
  2540.                 if fs.exists ( self._path ) == true then
  2541.                     local f = fs.open ( self._path, 'r' )
  2542.                     local content = f.readAll ()
  2543.                     f.close ()
  2544.  
  2545.                     self._data = textutils.unserialize ( content )
  2546.                     if type ( self._data ) ~= 'table' then
  2547.                         self._data = {}
  2548.                     end
  2549.                 else
  2550.                     self._data = {}
  2551.                 end
  2552.             end
  2553.         end,
  2554.  
  2555.         ['get'] = function ( self, key )
  2556.             self:_init ()
  2557.  
  2558.             return self._data [key]
  2559.         end,
  2560.  
  2561.         ['set'] = function ( self, key, value )
  2562.             self:_init ()
  2563.             self._data [key] = value
  2564.  
  2565.             local content = textutils.serialize ( self._data )
  2566.             local f = fs.open ( self._path, 'w' )
  2567.             f.write ( content )
  2568.             f.close ()
  2569.  
  2570.             return self
  2571.         end,
  2572.     },
  2573. }
  2574.  
  2575. _G ['_event'] = {}
  2576.  
  2577. i.map           = i.files:run ( 'class/map.lua' )
  2578. i.turtle        = i.files:run ( 'class/turtle.lua' )
  2579. i.items         = i.files:run ( 'class/items.lua' )
  2580. i.timer         = i.files:run ( 'class/timer.lua' )
  2581. i.timer:init ( _G ['_event'] )
  2582.  
  2583.  
  2584. local menu = i.files:run ( 'class/menu.basic.lua' )
  2585. menu:name ( 'GPS Tower builder' )
  2586. menu:verifyQuit ( true )
  2587. menu:settings ().options.indent = 1
  2588.  
  2589. menu:create ( 'Current Position:' )
  2590. menu:create ( ' x' ):type ( 'number' ):number ( i.turtle.location.x ):selected ( function () menu:status ( '' ) end )
  2591. menu:create ( ' y' ):type ( 'number' ):number ( i.turtle.location.y ):selected ( function () menu:status ( '' ) end )
  2592. menu:create ( ' z' ):type ( 'number' ):number ( i.turtle.location.z ):selected ( function () menu:status ( '' ) end )
  2593. menu:create ( '' ):selected ( function () menu:status ( '' ) end )
  2594. menu:create ( 'Place tower at' ):type ( 'number' ):min ( -1 ):number ( -1 ):selected ( function ()
  2595.     menu:status ( '-1 for max height possibly' )
  2596. end )
  2597. menu:create  ( 'Dig if needed' ):type ( 'bool' ):bool ( true ):selected ( function ()
  2598.     menu:status ( '[Left] False, [Right] True' )
  2599. end )
  2600.  
  2601. menu:create ( 'Start building' ):type ( 'execute' ):selected ( function () menu:status ( '' ) end ):run ( function ()
  2602.     local x = menu:option (2):number ()
  2603.     local y = menu:option (3):number ()
  2604.     local z = menu:option (4):number ()
  2605.     local height = menu:option (6):number ()
  2606.     local digAllowed = menu:option (7):bool ()
  2607.  
  2608.     local startY = y
  2609.     local menu = i.files:run ( 'class/menu.basic.lua' )
  2610.     menu:settings ().options.indent = 1
  2611.  
  2612.     menu:name ( 'Checking inventory' )
  2613.     menu:create ( ' - Can dig' )
  2614.     menu:create ( ' - Fuel' )
  2615.     menu:create ( ' - Disk Drive' ):type ( 'number' ):number ( 1 )
  2616.     menu:create ( ' - Computer' ):type ( 'number' ):number ( 4 )
  2617.     menu:create ( ' - Wireless modem' ):type ( 'number' ):number ( 4 )
  2618.     menu:create ( ' - Floppy disk' ):type ( 'number' ):number ( 1 )
  2619.     menu:draw ()
  2620.  
  2621.     i.turtle.inventory:stack ()
  2622.     menu:option (1):type ( 'bool' ):bool ( false )
  2623.     local snapshot = i.turtle.inventory:snapshot ()
  2624.     local state, message = turtle.digUp ()
  2625.     if state == true then
  2626.         snapshot.compare:current ():each ( function ( slot )
  2627.             turtle.select ( slot )
  2628.             turtle.placeUp ()
  2629.         end )
  2630.  
  2631.         menu:option (1):type ( 'bool' ):bool ( digAllowed )
  2632.         if digAllowed == false then
  2633.             menu:option (3):number (4)
  2634.             menu:status ( 'Blocks in the way, please clear up' )
  2635.  
  2636.             menu:run ()
  2637.             return
  2638.         end
  2639.     else
  2640.         if message == 'No tool to dig with' then
  2641.             menu:option (1):type ( 'bool' ):bool ( false )
  2642.         else
  2643.             menu:option (1):type ( 'bool' ):bool ( true )
  2644.         end
  2645.     end
  2646.     if menu:option (1):bool () == false then
  2647.         local item = i.turtle.inventory:select ( 'Diamond Pickaxe' )
  2648.         if item ~= false then
  2649.             if turtle.equipLeft () == false then
  2650.                 if turtle.equipRight () ~= false then
  2651.                     menu:option (1):bool ( true )
  2652.                 end
  2653.             else
  2654.                 menu:option (1):bool ( true )
  2655.             end
  2656.         end
  2657.     end
  2658.     if menu:option (1):bool () == false then
  2659.         menu:option (1):bool ( true )
  2660.         menu:option (3):number (4)
  2661.     end
  2662.     local digCan = menu:option (1):bool () -- Giggle, digCan... its late,leave me alone
  2663.  
  2664.     menu:option (2):type ( 'bool' ):bool ( true )
  2665.     if i.turtle.inventory.select:fuel () == false then
  2666.         if turtle.getFuelLevel () ~= 'unlimited' and turtle.getFuelLevel () < 800 then
  2667.             menu:option (2):type ( 'bool' ):bool ( false )
  2668.         else
  2669.             menu:option (2):bool ( true )
  2670.         end
  2671.     else
  2672.         if turtle.getFuelLevel () == 'unlimited' then
  2673.             menu:option (2):type ( 'bool' ):bool ( true )
  2674.         else
  2675.             menu:option (2):type ( 'number' ):number ( turtle.getFuelLevel () )
  2676.  
  2677.             while i.turtle.inventory.select:fuel () ~= false do
  2678.                 turtle.refuel (1)
  2679.                 menu:option (2):type ( 'number' ):number ( math.max ( 0, 800 - turtle.getFuelLevel () ) )
  2680.                 menu:draw ()
  2681.  
  2682.                 if turtle.getFuelLevel () > 800 then
  2683.                     break
  2684.                 end
  2685.             end
  2686.  
  2687.             if turtle.getFuelLevel () <= 800 then
  2688.                 menu:option (2):type ( 'bool' ):bool ( false )
  2689.             else
  2690.                 menu:option (2):type ( 'bool' ):bool ( true )
  2691.             end
  2692.         end
  2693.     end
  2694.  
  2695.  
  2696.     local item = i.turtle.inventory:select ( 'Disk Drive', false )
  2697.     if item ~= false then
  2698.         menu:option (3):number ( math.max ( 0, menu:option (3):number () - item.count ) )
  2699.     end
  2700.  
  2701.     local item = i.turtle.inventory:select ( 'Computer', false )
  2702.     if item ~= false then
  2703.         menu:option (4):number ( math.max ( 0, menu:option (4):number () - item.count ) )
  2704.     end
  2705.  
  2706.     local item = i.turtle.inventory:select ( 'Advanced Computer', false )
  2707.     if item ~= false then
  2708.         menu:option (4):number ( math.max ( 0, menu:option (4):number () - item.count ) )
  2709.     end
  2710.  
  2711.     local item = i.turtle.inventory:select ( 'Wireless modem', false )
  2712.     if item ~= false then
  2713.         menu:option (5):number ( math.max ( 0, menu:option (5):number () - item.count ) )
  2714.     end
  2715.  
  2716.     local item = i.turtle.inventory:select ( 'Floppy disk', false )
  2717.     if item ~= false then
  2718.         menu:option (6):number ( math.max ( 0, menu:option (6):number () - item.count ) )
  2719.     end
  2720.  
  2721.     local item = i.turtle.inventory:select ( 'Floppy disk - Expanded', false )
  2722.     if item ~= false then
  2723.         menu:option (6):number ( math.max ( 0, menu:option (6):number () - item.count ) )
  2724.     end
  2725.  
  2726.  
  2727.  
  2728.     if menu:option (6):number () == 0 then table.remove ( menu:option (), 6 ) end
  2729.     if menu:option (5):number () == 0 then table.remove ( menu:option (), 5 ) end
  2730.     if menu:option (4):number () == 0 then table.remove ( menu:option (), 4 ) end
  2731.     if menu:option (3):number () == 0 then table.remove ( menu:option (), 3 ) end
  2732.     if menu:option (2):bool () == true then table.remove ( menu:option (), 2 ) end
  2733.     if menu:option (1):bool () == true then table.remove ( menu:option (), 1 ) end
  2734.  
  2735.     if #menu:option () > 0 then
  2736.         menu:name ( 'Missing items')
  2737.  
  2738.         for i = 1, #menu:option () do
  2739.             menu:option (i):readonly ( true )
  2740.         end
  2741.  
  2742.         i.timer:start ( 5, function ()
  2743.             menu:status ( 'Press [Backspace] to try again.' )
  2744.         end )
  2745.         menu:run ()
  2746.         return
  2747.     end
  2748.  
  2749.     i.turtle.location.x = x
  2750.     i.turtle.location.y = y
  2751.     i.turtle.location.z = z
  2752.  
  2753.     local selected = false
  2754.     menu:clear ()
  2755.     menu:name ( 'The turtle is facing' )
  2756.     menu:create ( 'East' ):type ( 'execute' ):run ( function ()
  2757.         i.turtle.facing = 1
  2758.  
  2759.         selected = true
  2760.         menu:abort ()
  2761.     end )
  2762.     menu:create ( 'North' ):type ( 'execute' ):run ( function ()
  2763.         i.turtle.facing = 2
  2764.  
  2765.         selected = true
  2766.         menu:abort ()
  2767.     end )
  2768.     menu:create ( 'West' ):type ( 'execute' ):run ( function ()
  2769.         i.turtle.facing = 3
  2770.  
  2771.         selected = true
  2772.         menu:abort ()
  2773.     end )
  2774.     menu:create ( 'South' ):type ( 'execute' ):run ( function ()
  2775.         i.turtle.facing = 4
  2776.  
  2777.         selected = true
  2778.         menu:abort ()
  2779.     end )
  2780.     menu:select ( i.turtle.facing or 2 )
  2781.  
  2782.     while selected == false do menu:run () end
  2783.  
  2784.  
  2785.     menu:clear ()
  2786.     menu:name ( 'Moving' )
  2787.     if height == -1 then
  2788.         menu:create ( 'Detecting max height' )
  2789.     else
  2790.         menu:create ( 'Moving to height' )
  2791.     end
  2792.     menu:create ( 'Y' ):type ( 'number' ):number ( i.turtle.location.y )
  2793.     menu:draw ()
  2794.  
  2795.     local placeGuide = {
  2796.         -1,
  2797.         -1,
  2798.     }
  2799.  
  2800.     i.turtle:face ( 'south' )
  2801.     local node = i.turtle:location ()
  2802.     local nodes = {
  2803.         [node.x ..','.. node.y ..','.. node.z] = node,
  2804.     }
  2805.  
  2806.     while true do
  2807.         if height ~= -1 and i.turtle.location.y >= height then
  2808.             break
  2809.         end
  2810.  
  2811.         if digAllowed == true then
  2812.             if turtle.detectUp () == true then
  2813.                 local snapshot = i.turtle.inventory:snapshot ()
  2814.                 if turtle.getSelectedSlot () ~= 1 then turtle.select (1) end
  2815.                 turtle.digUp ()
  2816.  
  2817.                 snapshot.compare:current ():each ( function ( slot, item )
  2818.                     node:up ().item = item
  2819.  
  2820.                     return true
  2821.                 end )
  2822.             end
  2823.         end
  2824.        
  2825.         local moves, message = i.turtle:up ()
  2826.         if moves ~= 0 then
  2827.             node = node:up ()
  2828.             nodes [ node.x ..','.. node.y ..','.. node.z ] = node
  2829.         end
  2830.         menu:option (2):number ( i.turtle.location.y )
  2831.         menu:draw ()
  2832.  
  2833.         if digAllowed == true then
  2834.             local item = node:down ().item
  2835.             if item ~= nil then
  2836.                 i.turtle.inventory:select ( item )
  2837.                 turtle.placeDown ()
  2838.             end
  2839.         end
  2840.  
  2841.         if message == 'Movement obstructed' then break end
  2842.         if message == 'Too high to move' then
  2843.             i.turtle:down ()
  2844.             node = node:down ()
  2845.  
  2846.             break
  2847.         end
  2848.     end
  2849.     nodes [ node.x ..','.. node.y ..','.. node.z ] = node
  2850.  
  2851.  
  2852.     menu:name ( 'Deploying' )
  2853.     menu:clear ()
  2854.     menu:create ( 'Computer 1' ):type ( 'bool' ):bool ( false )
  2855.     menu:create ( 'Computer 2' ):type ( 'bool' ):bool ( false )
  2856.     menu:create ( 'Computer 3' ):type ( 'bool' ):bool ( false )
  2857.     menu:create ( 'Computer 4' ):type ( 'bool' ):bool ( false )
  2858.  
  2859.  
  2860.     for t = 1,4 do
  2861.         menu:select ( t )
  2862.         menu:draw ()
  2863.  
  2864.         if t == 1 then
  2865.             i.turtle:face ( 'south' )
  2866.         elseif t == 2 then
  2867.             i.turtle:face ( 'north' )
  2868.         elseif t == 3 then
  2869.             local node = i.turtle:location ()
  2870.             node = nodes [ node.x ..','.. node.y ..','.. node.z ]
  2871.  
  2872.             for a = 1,3 do
  2873.                 if digAllowed == true then
  2874.                     if turtle.detectDown () == true then
  2875.                         local snapshot = i.turtle.inventory:snapshot ()
  2876.                         if turtle.getSelectedSlot () ~= 1 then turtle.select (1) end
  2877.                         turtle.digDown ()
  2878.  
  2879.                         snapshot.compare:current ():each ( function ( slot, item )
  2880.                             node:down ().item = item
  2881.  
  2882.                             return true
  2883.                         end )
  2884.                     end
  2885.                 end
  2886.  
  2887.                 local moves, message = i.turtle:down ()
  2888.                 if moves ~= 0 then
  2889.                     node = node:down ()
  2890.                     nodes [ node.x ..','.. node.y ..','.. node.z ] = node
  2891.                 end
  2892.  
  2893.                 if digAllowed == true then
  2894.                     local item = node:up ().item
  2895.                     if item ~= nil then
  2896.                         i.turtle.inventory:select ( item )
  2897.                         turtle.placeUp ()
  2898.                     end
  2899.                 end
  2900.             end
  2901.  
  2902.             i.turtle:face ( 'east' )
  2903.         elseif t == 4 then
  2904.             i.turtle:face ( 'west' )
  2905.         end
  2906.         local node = i.turtle:location ()
  2907.         node = nodes [ node.x ..','.. node.y ..','.. node.z ]
  2908.  
  2909.         for a = 1,2 do
  2910.             node = node [ i.turtle.direction:forward () ] ( node )
  2911.             nodes [ node.x ..','.. node.y ..','.. node.z ] = node
  2912.  
  2913.             if digAllowed == true then
  2914.                 if turtle.detect () == true then
  2915.                     local snapshot = i.turtle.inventory:snapshot ()
  2916.                     if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
  2917.                     local _, message = turtle.dig ()
  2918.                     if message == 'Unbreakable block detected' then error ( 'Well this fucking sucks, i dont even....' ) end
  2919.  
  2920.                     snapshot.compare:current ():each ( function ( slot, item )
  2921.                         node.item = item
  2922.  
  2923.                         return true
  2924.                     end )
  2925.                 end
  2926.             end
  2927.  
  2928.             i.turtle:forward ()
  2929.         end
  2930.  
  2931.         local coordNode = node [ i.turtle.direction:forward () ] ( node )
  2932.         local wirelessNode = node
  2933.  
  2934.         if turtle.detect () == true then
  2935.             local snapshot = i.turtle.inventory:snapshot ()
  2936.             if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
  2937.             turtle.dig ()
  2938.             snapshot.compare:current ():each ( function ( slot, item )
  2939.                 turtle.select ( slot )
  2940.                 turtle.drop ( item.count )
  2941.             end )
  2942.         end
  2943.  
  2944.         if i.turtle.inventory:select ( 'Computer' ) == false then
  2945.             i.turtle.inventory:select ( 'Advanced Computer' )
  2946.         end
  2947.         turtle.place ()
  2948.  
  2949.         if turtle.detectDown () == true then
  2950.             local snapshot = i.turtle.inventory:snapshot ()
  2951.             if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
  2952.             turtle.digDown ()
  2953.  
  2954.             local node = node:down ()
  2955.             nodes [ node.x ..','.. node.y ..','.. node.z ] = node
  2956.  
  2957.             snapshot.compare:current ():each ( function ( slot, item )
  2958.                 node.item = item
  2959.  
  2960.                 return true
  2961.             end )
  2962.         end
  2963.  
  2964.         i.turtle:down ()
  2965.         node = node:down ()
  2966.  
  2967.         if turtle.detect () == true then
  2968.             local snapshot = i.turtle.inventory:snapshot ()
  2969.             if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
  2970.             turtle.dig ()
  2971.  
  2972.             local node = node [ i.turtle.direction:forward () ] ( node )
  2973.             nodes [ node.x ..','.. node.y ..','.. node.z ] = node
  2974.  
  2975.             snapshot.compare:current ():each ( function ( slot, item )
  2976.                 node.item = item
  2977.  
  2978.                 return true
  2979.             end )
  2980.         end
  2981.  
  2982.         i.turtle.inventory:select ( 'Disk Drive' )
  2983.         turtle.place ()
  2984.  
  2985.         if i.turtle.inventory:select ( 'Floppy Disk' ) == false then
  2986.             i.turtle.inventory:select ( 'Floppy Disk - Extended' )
  2987.         end
  2988.         turtle.drop ()
  2989.  
  2990.         local file = fs.open ( 'disk/startup', 'w' )
  2991.         file.write ([[
  2992. -- Inspired by http://www.computercraft.info/forums2/index.php?/topic/9528-gps-deploy-11-updated-04012014/
  2993. -- Also, there's not really that many ways of doing this
  2994. fs.delete ( 'startup' )
  2995. fs.copy ('/disk/install', 'startup' )
  2996. if fs.exists ( 'disk/custom' ) == true then
  2997.     fs.copy ( 'disk/custom', 'custom' )
  2998. end
  2999.  
  3000. term.clear ()
  3001. term.setCursorPos ( 3,3 )
  3002. term.write ( 'Sleeping...' )
  3003. os.sleep (5)
  3004. os.reboot ()
  3005. ]])
  3006.         file.close ()
  3007.  
  3008.         fs.delete ( 'disk/install' )
  3009.         local file = fs.open ( 'disk/install', 'w' )
  3010.         file.write ([[
  3011. -- Hi, http://www.computercraft.info/forums2/index.php?/topic/9528-gps-deploy-11-updated-04012014/
  3012. term.clear ()
  3013. if fs.exists ( 'custom' ) == true then
  3014.     shell.run ( 'custom', 'host', ]] .. coordNode.x ..',' .. coordNode.y ..','.. coordNode.z .. [[ )
  3015. else
  3016.     shell.run ( 'gps', 'host', ]] .. coordNode.x ..',' .. coordNode.y ..','.. coordNode.z .. [[ )
  3017. end
  3018. ]])
  3019.         file.close ()
  3020.  
  3021.         i.turtle:up ()
  3022.         local wrap = peripheral.wrap ( 'front' )
  3023.         if wrap.isOn () == true then wrap.shutdown () end
  3024.         wrap.turnOn ()
  3025.  
  3026.         i.turtle:down ()
  3027.         if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
  3028.         turtle.suck ()
  3029.         turtle.dig ()
  3030.  
  3031.         local item = node [ i.turtle.direction:forward () ] ( node ).item
  3032.         if item ~= nil then
  3033.             i.turtle.inventory:select ( item )
  3034.             turtle.place ()
  3035.         end
  3036.  
  3037.         i.turtle:up ()
  3038.         local item = node.item
  3039.         if item ~= nil then
  3040.             i.turtle.inventory:select ( item )
  3041.             turtle.placeDown ()
  3042.         end
  3043.  
  3044.         node = coordNode [ i.turtle.direction:back () ] ( coordNode )
  3045.         for a = 1,2 do
  3046.             i.turtle:back ()
  3047.  
  3048.             if a == 1 then
  3049.                 i.turtle.inventory:select ( 'Wireless modem' )
  3050.                 turtle.place ()
  3051.  
  3052.                 menu:option (t):bool ( true )
  3053.                 menu:draw ()
  3054.             end
  3055.  
  3056.             if digAllowed == true then
  3057.                 if node.item ~= nil then
  3058.                     i.turtle.inventory:select ( node.item )
  3059.                     if turtle.place () == false then
  3060.                         turtle.drop (1)
  3061.                     end
  3062.                 end
  3063.  
  3064.                 node = node [ i.turtle.direction:back () ] ( node )
  3065.             end
  3066.         end
  3067.     end
  3068.     i.turtle.inventory:stack ()
  3069.  
  3070.     menu:clear ()
  3071.     menu:name ( 'Moving back to start position' )
  3072.     menu:create ( 'Y' ):type ( 'number' ):number ( i.turtle.location.y )
  3073.  
  3074.     while true do
  3075.         if i.turtle.location.y <= startY then break end
  3076.  
  3077.         if digAllowed == true then
  3078.             if turtle.detectDown () == true then
  3079.                 local snapshot = i.turtle.inventory:snapshot ()
  3080.                 if turtle.getSelectedSlot () ~= 1 then turtle.select (1) end
  3081.                 turtle.digDown ()
  3082.  
  3083.                 snapshot.compare:current ():each ( function ( slot, item )
  3084.                     node:down ().item = item
  3085.  
  3086.                     return true
  3087.                 end )
  3088.             end
  3089.         end
  3090.        
  3091.         local moves, message = i.turtle:down ()
  3092.         if moves ~= 0 then
  3093.             node = node:down ()
  3094.             nodes [ node.x ..','.. node.y ..','.. node.z ] = node
  3095.         end
  3096.         menu:option (1):number ( i.turtle.location.y )
  3097.         menu:draw ()
  3098.  
  3099.         if digAllowed == true then
  3100.             local item = node:up ().item
  3101.             if item ~= nil then
  3102.                 i.turtle.inventory:select ( item )
  3103.                 turtle.placeUp ()
  3104.             end
  3105.         end
  3106.  
  3107.         if message == 'Movement obstructed' then break end
  3108.     end
  3109. end )
  3110.  
  3111. menu:run ()
Advertisement
Add Comment
Please, Sign In to add comment