· 6 years ago · Apr 18, 2020, 04:44 PM
1for key, value in pairs({ ["os/programs/recklessFiller/main.lua"] = "\nui.input.term=term\nlocal _x,_y,_w,_h=1,1,term.getSize()local pathPart=\"os/programs/recklessFiller/\"local success,set=fs.doFile(pathPart..\"/data/settings.set\")set=set or{}set.size=set.size or 0\nset.height=set.height or 0\nset.fuelLimit=set.fuelLimit or 800\nset.fuelSource=set.fuelSource or 1\nset.blockSource=set.blockSource or 1\nset.blockType=set.blockType or 1\nlocal fuelSource= {\"Player\",\"Ender Chest\"}local blockSource= {\"Player\",\"Ender Chest\"}local blockType= {\"Any\",\"Same\"}local input=ui.input.new()local drawer=ui.drawer.new(input,_x,_y,_w,_h)ui.buffer.fill(drawer.buffer,\" \",colors.white,colors.white)ui.label.new(drawer,\"Reckless Filler\",theme.label1,_x,_y,_w-3,1)local button_exit=ui.button.new(drawer,\"<\",theme.button2,_x+_w-3,_y,3,1)ui.label.new(drawer,\"Size: Height: Fuel Limit:\",theme.label2,_x,_y+1,_w,1)local iField_size=ui.inputField.new(drawer,nil,tostring(set.size),false,theme.iField2,_x,_y+2,11,1)local iField_height=ui.inputField.new(drawer,nil,tostring(set.height),false,theme.iField2,_x+12,_y+2,11,1)local iField_fuelLimit=ui.inputField.new(drawer,nil,tostring(set.fuelLimit),false,theme.iField2,_x+24,_y+2,11,1)ui.label.new(drawer,\"Fuel Source\",theme.label2,_x,_y+4,12,1)local button_fuelSource=ui.button.new(drawer,fuelSource[set.fuelSource],theme.button1,_x+13,_y+4,13,1)ui.label.new(drawer,\"Block Source\",theme.label2,_x,_y+5,12,1)local button_blockSource=ui.button.new(drawer,blockSource[set.blockSource],theme.button1,_x+13,_y+5,13,1)ui.label.new(drawer,\"Block Type\",theme.label2,_x,_y+6,12,1)local button_blockType=ui.button.new(drawer,blockType[set.blockType],theme.button1,_x+13,_y+6,13,1)local text_info=ui.text.new(drawer,\" \\n \\n \\n \\n \",theme.label2,1,_y+8,_w,_h-8)text_info.scaleH=false\nui.label.new(drawer,\"\",theme.label1,1,_h,_w,1)local button_start=ui.button.new(drawer,\"Start\",theme.button1,_x+_w-7,_h,7,1)local button_saveSettings=ui.button.new(drawer,\"Save Settings\",theme.button1,_x,_h,15,1)local group_menu=drawer.selectionManager:addNewGroup()group_menu.current=button_exit\nlocal group_iField=drawer.selectionManager:addNewGroup()group_iField.current=iField_size\nlocal group_main=drawer.selectionManager:addNewGroup()group_main.current=button_fuelSource\nlocal group_save=drawer.selectionManager:addNewGroup()group_save.current=button_start\ngroup_menu.previous=group_save\ngroup_iField.previous=group_menu\ngroup_main.previous=group_iField\ngroup_save.previous=group_main\ngroup_menu.next=group_iField\ngroup_iField.next=group_main\ngroup_main.next=group_save\ngroup_save.next=group_menu\ngroup_menu:addElement(button_exit,nil,nil,nil,iField_size)group_iField:addElement(iField_size,nil,group_menu,iField_height,group_main)group_iField:addElement(iField_height,iField_size,group_menu,iField_fuelLimit,group_main)group_iField:addElement(iField_fuelLimit,iField_height,group_menu,nil,group_main)group_main:addElement(button_fuelSource,nil,group_iField,nil,button_blockSource)group_main:addElement(button_blockSource,nil,button_fuelSource,nil,button_blockType)group_main:addElement(button_blockType,nil,button_blockSource,nil,group_save)group_save:addElement(button_saveSettings,nil,button_blockType,button_start,nil)group_save:addElement(button_start,button_saveSettings,button_blockType,nil,nil)drawer.selectionManager:select(iField_size,\"code\",not term.isColor())local function updateInfoText()local text=\"\"if set.fuelSource==1 then\ntext=text..\"Insert [tc=red]fuel[tc=clear] in [tc=red]slot 1[tc=clear]. \"else\ntext=text..\"Insert the [tc=red]fuel Ender Chest[tc=clear] in [tc=red]slot 1[tc=clear]. \"end\nif set.blockSource==1 then\ntext=text..\"Insert the [tc=red]building blocks[tc=clear] in [tc=red]all remaining slots[tc=clear]. \"else\ntext=text..\"Insert the [tc=red]block Ender Chest[tc=clear] in [tc=red]slot 2[tc=clear]. \"end\nif set.blockType==1 then\ntext=text..\"Use any block type.\"else\ntext=text..\"Use the same block type.\"end\ntext_info.text=text\ntext_info:recalculate()text_info:repaint(\"this\")end\nupdateInfoText()local function updateStart()local canStart=false\nif(tonumber(iField_size.text)or 0) >=1 and(tonumber(iField_height.text)or 0) >=1 then\nbutton_start:changeMode(1,true)group_save.current=button_start\nelse\nbutton_start:changeMode(2,true)group_save.current=button_saveSettings\nend\nend\nupdateStart()function button_exit:onClick()input:exit()end\nfunction iField_size:onTextEdit(event,text)if event==\"change\"then\nupdateStart()set.size=tonumber(text)or 0\nend\nend\nfunction iField_height:onTextEdit(event,text)if event==\"change\"then\nupdateStart()set.height=tonumber(text)or 0\nend\nend\nfunction button_fuelSource:onClick(event)input:callFunction(function()local x,y,w,h=self:getGlobalRect()local name,index=sys.listBox({drawer=drawer,label=\"Fuel Source\",x=x-1,y=y,w=15,buttons=fuelSource,select=event.name==\"key_up\"})if name then\nset.fuelSource=index[1]self.text=\"\" ..name\nself:recalculate()updateInfoText()end\nself:repaint(\"all\")end)end\nfunction button_blockSource:onClick(event)input:callFunction(function()local x,y,w,h=self:getGlobalRect()local name,index=sys.listBox({drawer=drawer,label=\"Block Source\",x=x-1,y=y,w=15,buttons=blockSource,select=event.name==\"key_up\"})if name then\nset.blockSource=index[1]self.text=\"\" ..name\nself:recalculate()updateInfoText()end\nself:repaint(\"all\")end)end\nfunction button_blockType:onClick(event)input:callFunction(function()local x,y,w,h=self:getGlobalRect()local name,index=sys.listBox({drawer=drawer,label=\"Block Type\",x=x-1,y=y,w=15,buttons=blockType,select=event.name==\"key_up\"})if name then\nset.blockType=index[1]self.text=\"\" ..name\nself:recalculate()updateInfoText()end\nself:repaint(\"all\")end)end\nfunction button_saveSettings:onClick(event)table.save(set,pathPart..\"data/settings.set\")end\nfunction button_start:onClick(event)input:callFunction(function()term.clear()fs.delete(pathPart..\"data/move.set\")table.save(set,pathPart..\"data/data.set\")local file=fs.open(\"os/startup/50-recklessFiller.lua\",\"w\")file.write('dofile(\"' .. pathPart .. 'filler.lua\")')file.close()dofile(pathPart..\"filler.lua\")input:exit()end)end\ndrawer:draw()input:eventLoop({[term] =drawer.event})\n",["os/programs/recklessFiller/filler.lua"] = "ui.input.term=term\nlocal _x,_y,_w,_h=1,1,term.getSize()local pathPart=\"os/programs/recklessFiller/\"local savePath=pathPart..\"data/move.set\"local setPath=pathPart..\"data/data.set\"local startPath=\"os/startup/50-recklessFiller.lua\"local set=dofile(setPath)local move= {}local inMove=false\nlocal stop=false\nlocal function getData()if fs.exists(savePath)then\nmove=dofile(savePath)vector.convert(move.pos)vector.convert(move.facing)if move.next then\nvector.convert(move.next)end\nelse\nmove.pos=vector.zero:copy()move.facing=vector.forward:copy()end\nend\ngetData()local function getFacingText()if move.facing.x>0 then\nreturn \"Forward\"elseif move.facing.x<0 then\nreturn \"Back\"elseif move.facing.y>0 then\nreturn \"Right\"else\nreturn \"Left\"end\nend\nlocal input=ui.input.new()local drawer=ui.drawer.new(input,_x,_y,_w,_h)ui.buffer.fill(drawer.buffer,\" \",colors.white,colors.white)ui.label.new(drawer,\"Reckless Filler\",theme.label1,_x,_y,_w,1)local label_pos=ui.label.new(drawer,\"Position: \",theme.label2,_x,_y+1,10,1)local label_posX=ui.label.new(drawer,\"X: \" ..move.pos.x,theme.label2,_x+10,_y+1,8,1)local label_posY=ui.label.new(drawer,\"Y: \" ..move.pos.y,theme.label2,_x+19,_y+1,8,1)local label_posZ=ui.label.new(drawer,\"Z: \" ..move.pos.z,theme.label2,_x+28,_y+1,8,1)local label_facing=ui.label.new(drawer,\"Facing: \" ..getFacingText(),theme.label2,_x,_y+2,_w,1)ui.label.new(drawer,\"Size: Height: Fuel Limit:\",theme.label2,_x,_y+4,_w,1)ui.label.new(drawer,tostring(set.size),theme.label2,_x,_y+5,11,1)ui.label.new(drawer,tostring(set.height),theme.label2,_x+12,_y+5,11,1)ui.label.new(drawer,tostring(set.fuelLimit),theme.label2,_x+24,_y+5,11,1)ui.label.new(drawer,\"Fuel Level:\",theme.label2,_x,_y+6,11,1)local label_fuelLevel=ui.label.new(drawer,tostring(turtle.getFuelLevel()),theme.label2,_x+12,_y+6,_w-12,1)local text_mode=ui.text.new(drawer,\"Mode:\\n\\n\\n\",theme.label2,_x,_h-4,_w,3)text_mode.scaleH=false\nfunction text_mode:setText(text)self.text=text\nself:recalculate()self:repaint(\"this\")end\nui.label.new(drawer,\"\",theme.label1,_x,_h,_w,1)local button_pause=ui.button.new(drawer,IF(move.pause,\"Resume\",\"Pause\"),theme.button1,_x,_h,8,1)local button_exit=ui.button.new(drawer,\"Exit\",theme.button1,_x+_w-6,_h,6,1)local group_main=drawer.selectionManager:addNewGroup()group_main:addElement(button_pause,nil,nil,button_exit,nil)group_main:addElement(button_exit,button_pause,nil,nil,nil)drawer.selectionManager:select(button_pause,\"code\",not term.isColor())local function save()table.save(move,savePath)end\nlocal function deleteFiles()if fs.exists(savePath)then\nfs.delete(savePath)end\nif fs.exists(setPath)then\nfs.delete(setPath)end\nif fs.exists(startPath)then\nfs.delete(startPath)end\nend\nlocal function update(f,p,m)if m then\ninMove=true\nend\nif f then\nmove.facing:set(move.facing.y*f.x,move.facing.x*f.y)save()label_facing.text=\"Facing: \" ..getFacingText()label_facing:recalculate()label_facing:repaint(\"this\")end\nif p then\nmove.pos:set(move.pos.x+ (p.x*move.facing.x+p.y*move.facing.y),move.pos.y+ (p.x*move.facing.y+p.y*move.facing.x),move.pos.z+p.z)save()label_posX.text=\"X: \" ..move.pos.x\nlabel_posY.text=\"Y: \" ..move.pos.y\nlabel_posZ.text=\"Z: \" ..move.pos.z\nlabel_posX:recalculate()label_posY:recalculate()label_posZ:recalculate()label_posX:repaint(\"this\")label_posY:repaint(\"this\")label_posZ:repaint(\"this\")end\ninMove=m\nend\nlocal function getNextPos(current,size)local v=current\nlocal elevation\nelevation=math.min((v.z) %2,1) *2-1\nlocal direction= (v.y%2*2-1) * -elevation\nlocal x,y,z=0,0,0\nif(direction<0 and v.x<size)or(direction>0 and v.x>0)then\nx= -direction\nelseif(elevation<0 and v.y<size)or(elevation>0 and v.y>0)then\ny= -elevation\nelse\nz=1\nend\nreturn vector.new(current.x+x,current.y+y,current.z+z)end\nlocal function gotoDestination(v)return turtle.move.go(v-move.pos,update,move.facing)end\nlocal function setMode(mode)move.mode=mode\nsave()if mode==\"refill_build\"then\nif set.blockSource==1 then\nelse\nif not move.placed then\nturtle.select(3)turtle.digUp()turtle.drop()turtle.select(2)turtle.placeUp()move.placed=true\nsave()end\nfor i=3,16 do\nif turtle.getItemCount(i) ==0 then\nturtle.select(i)turtle.suckUp()end\nend\nturtle.select(2)turtle.digUp()move.placed=nil\nend\nelseif mode==\"refuel\"then\nturtle.select(1)if set.fuelSource==1 then\nif turtle.refuel(1)then\nrepeat\nif turtle.getFuelLevel() >=set.fuelLimit then\nbreak\nend\nuntil turtle.refuel(1)else\nend\nelse\nif not move.placed then\nturtle.digUp()turtle.placeUp()move.placed=true\nsave()end\nwhile turtle.getFuelLevel() <set.fuelLimit do\nturtle.suckUp(1)if not turtle.refuel(1)and turtle.getFuelLevel() >0 then\nbreak\nend\nend\nturtle.digUp()move.placed=nil\nend\nend\nturtle.select(1)move.mode=nil\nsave()end\nlocal function placeDown()if not turtle.detectDown()then\nlocal start=IF(set.blockSource==1,2,3)for i=start,16 do\nlocal data=turtle.getItemDetail(i)if data then\nturtle.select(i)if(move.blockName==nil or data.name==move.blockName)and turtle.placeDown()then\nreturn\nelse\nturtle.drop()end\nend\nend\nsetMode(\"refill_build\")placeDown()end\nend\nlocal function checkFuel()if turtle.getFuelLimit() ==0 then\nreturn true\nend\nif turtle.getFuelLevel() ==0 then\nsetMode(\"refuel\")end\nlabel_fuelLevel.text=tostring(turtle.getFuelLevel())end\nlocal function fill()if move.mode then\nsetMode(move.mode)end\nturtle.select(3)while move.pos.z<=set.height do\nplaceDown()checkFuel()if not gotoDestination(getNextPos(move.pos,set.size-1))then\nturtle.move.up(update)end\nend\nend\nlocal checkPause=true\nlocal function waitForPause()while checkPause or inMove==true do\ncoroutine.yield()end\nmove.pause=not move.pause\ncheckPause=true\nsave()if move.pause==true then\nbutton_pause.text=\"Resume\"button_pause:recalculate()button_pause:repaint(\"this\")else\nbutton_pause.text=\"Pause\"button_pause:recalculate()button_pause:repaint(\"this\")end\nend\nfunction button_pause:onClick(event)checkPause=false\nend\nfunction button_exit:onClick(event)deleteFiles()input:exit()end\nlocal function execute()input:eventLoop({[term] =drawer.event})end\ndrawer:draw()if not move.blockName and set.blockType==2 then\nrepeat\nlocal data=turtle.getItemDetail(3)if data then\nmove.blockName=data.name\nbreak\nend\nsleep(1)until false\nend\nwhile true do\nif move.pause then\nif parallel.waitForAny(waitForPause,execute) ==2 then\nbreak\nend\nelse\nlocal exit=parallel.waitForAny(fill,waitForPause,execute)if exit==1 then\nbutton_pause:changeMode(2,true)button_exit:changeMode(1,true)execute()break\nelseif exit==3 then\nbreak\nend\nend\nend\n" }) do
2local s, e = key:find(".*/")
3if s then
4local path = key:sub(s, e)
5if not fs.exists(path) then
6fs.makeDir(path)
7end
8end
9local file = io.open(key, "w+")
10file:write(value)
11file:close()
12end
13sys.require("[1.0.1]Turtle Move API")