Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Project info:
- Name: uTurtle
- Creator: Jesusthekiller
- Language: Lua (CC)
- Website: None
- License: GNU GPL
- License file can be fount at www.jesusthekiller.com/license-gpl.html
- Version: 0.1 Beta
- ]]--
- --[[
- Changelog:
- 0.1:
- Initial Release
- ]]--
- --[[
- LICENSE:
- uTurtle
- Copyright (c) 2013 Jesusthekiller
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- ]]--
- local ar = {...}
- if #ar < 2 then
- print("Usage: uturtle <file in> <file out> [line]")
- return
- end
- local s = " "
- if ar[3] == "line" then
- s = "\n"
- end
- if ar[1] == ar[2] then
- error("<file in> is same as <file out>", 0)
- end
- local fin = fs.open(ar[1], "r") or error("Error while opening file "..ar[1], 0)
- local fout = fs.open(ar[2], "w") or error("Error while opening file "..ar[2], 0)
- local function p(s)
- fout.write(s)
- end
- local c = {
- [";go"] = "turtle.forward()",
- [";back"] = "turtle.back()",
- [';left'] = "turtle.turnLeft()",
- [';l'] = "turtle.turnLeft()",
- [';right'] = "turtle.turnRight()",
- [';r'] = "turtle.turnRight()",
- [';up'] = "turtle.up()",
- [';down'] = "turtle.down()",
- -- Loop
- [';gol'] = "while not turtle.forward() do sleep(0.8) end",
- [';backl'] = "while not turtle.back() do sleep(0.8) end",
- [';upl'] = "while not turtle.up() do sleep(0.8) end",
- [';downl'] = "while not turtle.down() do sleep(0.8) end",
- -- Dig
- [';dig'] = "turtle.dig()",
- [';digup'] = "turtle.digUp()",
- [';digdown'] = "turtle.digDown()",
- -- Dig Loop
- [';god'] = "while not turtle.forward() do turtle.dig() end",
- [';backd'] = "turtle.turnLeft() turtle.turnLeft() while not turtle.forward() do turtle.dig() end turtle.turnLeft() turtle.turnLeft()",
- [';upd'] = "while not turtle.up() do turtle.digUp() end",
- [';downd'] = "while not turtle.down() do turtle.digDown() end",
- -- Attack
- [';att'] = "turtle.attack()",
- [';attup'] = "turtle.attackUp()",
- [';attdown'] = "turtle.attackDown()",
- -- Attack Suck
- [';atts'] = "turtle.attack() turtle.suck()",
- [';attups'] = "turtle.attackUp() turtle.suckUp()",
- [';attdowns'] = "turtle.attackDown() turtle.suckDown()",
- -- Attack Loop
- [';goa'] = "while not turtle.forward() do turtle.attack() end",
- [';backa'] = "turtle.turnLeft() turtle.turnLeft() while not turtle.forward() do turtle.attack() end turtle.turnLeft() turtle.turnLeft()",
- [';upa'] = "while not turtle.up() do turtle.attackUp() end",
- [';downa'] = "while not turtle.down() do turtle.attackDown() end",
- -- Suck
- [';suck'] = "turtle.suck()",
- [';suckup'] = "turtle.suckUp()",
- [';suckdown'] = "turtle.suckDown()",
- [';sucka'] = "turtle.suck() turtle.suckUp() turtle.suckDown()",
- -- Detect
- [';detect'] = "turtle.detect()",
- [';detectup'] = "turtle.detectUp()",
- [';detectdown'] = "turtle.detectDown()",
- -- Place
- [';pl'] = "turtle.place()",
- [';plup'] = "turtle.placeUp()",
- [';pldown'] = "turtle.placeDown()",
- -- Compare
- [';comp'] = "turtle.compare()",
- [';compup'] = "turtle.compareUp()",
- [';compdown'] = "turtle.compareDown()",
- -- Fuel
- [';fuel'] = "turtle.getFuelLevel()",
- -- Multi functions
- -- Slot
- [';sel'] = true,
- [';count'] = true,
- [';space'] = true,
- [';transfer'] = true,
- [';compto'] = true, --
- [';craft'] = true,
- -- Fuel
- [';refuel'] = true, --
- -- Drop
- [';drop'] = true,
- [';dropup'] = true,
- [';dropdown'] = true,
- }
- local t = {}
- local sin = fin.readAll()
- for v in string.gmatch(sin, "[^%s]+") do -- Explode
- table.insert(t, v)
- end
- fin.close()
- while true do
- local v = table.remove(t, 1) -- FIFO
- if v == nil then break end -- If end of table, break
- if c[v] then
- if c[v] == true then
- if v == ';sel' then
- p("turtle.select("..table.remove(t, 1)..")") -- ;sel slot
- elseif v == ';count' then
- p("turtle.getItemCount("..table.remove(t, 1)..")") -- ;count slot
- elseif v == ';space' then
- p("turtle.getItemSpace("..table.remove(t, 1)..")") -- ;space slot
- elseif v == ';refuel' then
- p("turtle.refuel("..table.remove(t, 1)..")") -- ;refuel qty
- elseif v == ';transfer' then
- p("turtle.transferTo("..table.remove(t, 1)..", "..table.remove(t, 1)..")") -- ;transfer slot qty
- elseif v == ";drop" then
- p("turtle.drop("..table.remove(t, 1)..")") -- ;drop qty
- elseif v == ";dropup" then
- p("turtle.dropUp("..table.remove(t, 1)..")") -- ;dropup qty
- elseif v == ";dropdown" then
- p("turtle.dropDown("..table.remove(t, 1)..")") -- ;dropdown qty
- elseif v == ";compto" then
- p("turtle.compareTo("..table.remove(t, 1)..")") -- ;compto slot
- elseif v == ";craft" then
- p("turtle.craft("..table.remove(t, 1)..")") -- ;craft qty
- end
- else
- p(c[v])
- end
- else
- p(v)
- end
- p(s)
- end
- print(#c)
- fin.close()
- fout.close()
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement