Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- The MIT License (MIT)
- Copyright (c) 2014 Lyqyd
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- --]]
- if not location then if shell.resolveProgram("location") then os.loadAPI(shell.resolveProgram("location")) elseif fs.exists("usr/apis/location") then os.loadAPI("usr/apis/location") else error("Could not load location API!") end end
- local projectOffset = 1
- local projectCursor = 1
- local project, loc, buildLoc
- local display, handler
- local beginProject = false
- local headingNames = {"West", "North", "East", "South"}
- local posIsGPS = false
- local editingTable, editingKey, editingCursorPos
- local function constructEnv()
- local env = {requirements = project.requirements, shell = shell}
- setmetatable(env, {__index = _G})
- if env.requirements.locations then
- env.requirements.locations.start = loc
- env.requirements.locations.setup = buildLoc
- end
- return env
- end
- local function resetState()
- project = nil
- projectOffset = 1
- projectCursor = 1
- buildLoc = nil
- if not posIsGPS then loc = nil end
- beginProject = false
- editingTable, editingKey, editingCursorPos = nil, nil, nil
- end
- local projects = {}
- local projectDir = ""
- if fs.exists("/etc/projects") and fs.isDir("/etc/projects") then
- projectDir = "/etc/projects"
- elseif fs.getDir and fs.exists(fs.combine(fs.getDir(shell.getRunningProgram()), "projects")) and fs.isDir(fs.combine(fs.getDir(shell.getRunningProgram()), "projects")) then
- projectDir = fs.combine(fs.getDir(shell.getRunningProgram()), "projects")
- elseif fs.exists("/projects") and fs.isDir("/projects") then
- projectDir = "/projects"
- end
- if projectDir then
- for _, name in pairs(fs.list(projectDir)) do
- local file = fs.combine(projectDir, name)
- local usefulEnv = {shell = shell}
- setmetatable(usefulEnv, {__index = _G})
- local env = {}
- setmetatable(env, {__index = usefulEnv})
- local fn, err = loadfile(file)
- if fn then
- setfenv(fn, env)
- fn()
- --copy into project table
- projects[env.name] = {}
- for k, v in pairs(env) do
- projects[env.name][k] = v
- end
- end
- end
- else
- print("Could not find project folder!")
- return
- end
- local sortedProjects = {}
- for name in pairs(projects) do
- table.insert(sortedProjects, name)
- end
- table.sort(sortedProjects)
- local function printCenter(text)
- text = tostring(text)
- local x, y = term.getSize()
- local xCur, yCur = term.getCursorPos()
- term.setCursorPos((x - #text) / 2 + 1, yCur)
- term.write(text)
- end
- local function isSlotReady(slot)
- if project and project.requirements.slots then
- local slotReq = project.requirements.slots[slot]
- if slotReq.readyFunction then
- return slotReq.readyFunction()
- elseif slotReq.exactCount then
- return slotReq.minCount == slotReq.maxCount and slotReq.minCount == turtle.getItemCount(slot)
- else
- return turtle.getItemCount(slot) >= slotReq.minCount
- end
- else
- return false
- end
- end
- local function areAllSlotsReady()
- if project and project.requirements.slots then
- for i = 1, #project.requirements.slots do
- if not isSlotReady(i) then return false end
- end
- return true
- else
- return false
- end
- end
- local function areLocationsReady()
- if project and project.requirements.locations then
- if loc and loc.x and loc.y and loc.z and loc.y > 0 and buildLoc and buildLoc.x and buildLoc.y and buildLoc.z and buildLoc.y > 0 then
- return true
- else
- return false
- end
- else
- return true
- end
- end
- local function isFuelSufficient()
- if project and project.requirements.fuel then
- local fuelCost = project.requirements.fuel
- if type(project.requirements.fuel) == "function" then
- local env = constructEnv()
- setfenv(project.requirements.fuel, env)
- fuelCost = project.requirements.fuel()
- end
- local otherRequirements = true
- if project and project.requirements.other and type(project.requirements.other) == "function" then
- otherRequirements = project.requirements.other()
- end
- return turtle.getFuelLevel() >= fuelCost and otherRequirements
- else
- return false
- end
- end
- local function isReady()
- return project and areAllSlotsReady() and areLocationsReady() and isFuelSufficient()
- end
- local displayProjects, handleProjects, displayRequirements, handleRequirements, displaySlots, handleSlots, displayLocations, handleLocations, displayLocationOptions, handleLocationOptions, displayFueling, handleFueling
- function displayProjects()
- local x, y = term.getSize()
- local function projectLine(index)
- if term.isColor() then
- term.setBackgroundColor(index % 2 == 0 and colors.white or colors.lightGray)
- term.setTextColor(colors.black)
- else
- if index == projectCursor then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- end
- term.clearLine()
- local x, y = term.getCursorPos()
- term.setCursorPos(2, y)
- term.write(projects[sortedProjects[index]].name)
- end
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- printCenter("Project List")
- for i = 1, math.min(#sortedProjects, y - 2) do
- term.setCursorPos(1, i + 2)
- projectLine(projectOffset + i - 1)
- end
- end
- function handleProjects(event)
- local x, y = term.getSize()
- if event[1] == "mouse_click" then
- if event[4] >= 3 and event[4] <= y then
- --clicked somewhere in the places list
- if event[3] == x then
- --clicked the scroll bar.
- if event[4] == 3 then
- --up
- if projectOffset > 1 then
- projectOffset = projectOffset - 1
- end
- elseif event[4] == y then
- if projectOffset + y - 3 < #sortedProjects then
- projectOffset = projectOffset + 1
- end
- end
- else
- --clicked on a place!
- local index = projectOffset + event[4] - 3
- if index <= #sortedProjects then
- project = projects[sortedProjects[index]]
- display = displayRequirements
- handler = handleRequirements
- --we have a project selected, use projects[sortedProjects[index]] to access.
- end
- end
- end
- elseif event[1] == "key" and not term.isColor() then
- if event[2] == 200 then
- --up
- projectCursor = math.max(projectCursor - 1, 1)
- elseif event[2] == 208 then
- --down
- projectCursor = math.min(projectCursor + 1, #sortedProjects)
- elseif event[2] == 28 then
- --enter, selects a project
- project = projects[sortedProjects[projectCursor]]
- display = displayRequirements
- handler = handleRequirements
- end
- --attempt to keep cursor on screen
- if projectCursor < projectOffset then
- projectOffset = projectCursor
- elseif projectOffset + y - 2 < projectCursor then
- projectOffset = projectCursor - y + 2
- end
- end
- end
- local function drawRequirementsHeader()
- local function setColors(bool)
- if term.isColor() then
- term.setBackgroundColor(bool and colors.green or colors.red)
- term.setTextColor(colors.white)
- else
- term.setBackgroundColor(bool and colors.black or colors.white)
- term.setTextColor(bool and colors.white or colors.black)
- end
- end
- local x, y = term.getSize()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.clear()
- printCenter(project.name.." - Requirements")
- do
- if project.requirements.slots then
- term.setCursorPos(4, 3)
- setColors(areAllSlotsReady())
- term.write(" SLOTS ")
- end
- if project.requirements.locations then
- term.setCursorPos(14, 3)
- setColors(areLocationsReady())
- term.write(" LOCATIONS ")
- end
- if project.requirements.fuel then
- term.setCursorPos(27, 3)
- setColors(isFuelSufficient())
- term.write(" FUEL/ETC ")
- end
- end
- end
- local function handleRequirementsHeader(event)
- if event[1] == "mouse_click" and event[2] == 1 then
- if event[4] == 3 then
- if event[3] >= 4 and event[3] <= 10 then
- --clicked Slots
- display = displaySlots
- handler = handleSlots
- elseif event[3] >= 14 and event[3] <= 24 then
- --clicked Locations
- display = displayLocations
- handler = handleLocations
- elseif event[3] >= 28 and event[3] <= 36 then
- --clicked Fueling
- display = displayFueling
- handler = handleFueling
- end
- end
- elseif event[1] == "char" then
- if string.lower(event[2]) == "s" and project.requirements.slots then
- --slots
- display = displaySlots
- handler = handleSlots
- elseif string.lower(event[2]) == "l" and project.requirements.locations then
- --locations
- display = displayLocations
- handler = handleLocations
- elseif string.lower(event[2]) == "f" and project.requirements.fuel then
- --fueling
- display = displayFueling
- handler = handleFueling
- end
- end
- end
- function displayRequirements()
- drawRequirementsHeader()
- end
- function handleRequirements(event)
- handleRequirementsHeader(event)
- end
- function displaySlots()
- drawRequirementsHeader()
- local function setColors(bool)
- if term.isColor() then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(bool and colors.lime or colors.red)
- else
- term.setBackgroundColor(bool and colors.black or colors.white)
- term.setTextColor(bool and colors.white or colors.black)
- end
- end
- local x, y = term.getSize()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.clearLine()
- printCenter(project.name.." - Slots")
- do
- for i = 1, #project.requirements.slots do
- local slot = project.requirements.slots[i]
- if i > 8 then
- term.setCursorPos(math.ceil(x / 2), i - 4)
- else
- term.setCursorPos(2, i + 4)
- end
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.write(i..": ")
- setColors(isSlotReady(i))
- if slot.minCount == slot.maxCount then
- term.write(tostring(slot.minCount).." "..slot.name)
- else
- term.write(tostring(slot.minCount).."-"..tostring(slot.maxCount).." "..slot.name)
- end
- end
- end
- end
- function handleSlots(event)
- if event[1] == "mouse_click" then
- if event[4] <= 4 then
- return handleRequirementsHeader(event)
- end
- elseif event[1] == "char" then
- return handleRequirementsHeader(event)
- end
- end
- function displayLocations()
- drawRequirementsHeader()
- local x, y = term.getSize()
- local column = math.ceil(x / 2)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.clearLine()
- printCenter(project.name.." - Locations")
- do
- term.setCursorPos(2, 5)
- term.write("Current Position")
- term.setCursorPos(2, 6)
- term.write("X: ")
- if loc and loc.x then
- term.write(tostring(loc.x))
- end
- term.setCursorPos(2, 7)
- term.write("Y: ")
- if loc and loc.y then
- term.write(tostring(loc.y))
- end
- term.setCursorPos(2, 8)
- term.write("Z: ")
- if loc and loc.z then
- term.write(tostring(loc.z))
- end
- term.setCursorPos(2, 9)
- term.write("Facing: ")
- if loc and loc.h and headingNames[loc.h] then
- term.write(headingNames[loc.h])
- end
- end
- do
- term.setCursorPos(column, 5)
- term.write("Build Position")
- term.setCursorPos(column, 6)
- term.write("X: ")
- if buildLoc and buildLoc.x then
- term.write(tostring(buildLoc.x))
- end
- term.setCursorPos(column, 7)
- term.write("Y: ")
- if buildLoc and buildLoc.y then
- term.write(tostring(buildLoc.y))
- end
- term.setCursorPos(column, 8)
- term.write("Z: ")
- if buildLoc and buildLoc.z then
- term.write(tostring(buildLoc.z))
- end
- term.setCursorPos(column, 9)
- term.write("Facing: ")
- if buildLoc and buildLoc.h and headingNames[buildLoc.h] then
- term.write(headingNames[buildLoc.h])
- end
- if project.requirements.locations and #project.requirements.locations > 0 then
- term.setCursorPos((x - column - 9) / 2 + column, 11)
- term.write("(Options)")
- end
- end
- do
- if editingTable and editingKey and editingCursorPos then
- local columns = {[loc] = 2, [buildLoc] = column}
- local lines = {x = 6, y = 7, z = 8}
- term.setCursorPos(columns[editingTable] + 3, lines[editingKey])
- term.write(tostring(editingTable[editingKey]))
- term.setCursorPos(columns[editingTable] + 2 + editingCursorPos, lines[editingKey])
- term.setCursorBlink(true)
- else
- term.setCursorBlink(false)
- end
- end
- end
- local function numericRead(event)
- local function set(str)
- if #str == 0 then str = "0" end
- if tonumber(str) then
- editingTable[editingKey] = tonumber(str)
- end
- end
- local str = tostring(editingTable[editingKey])
- if event[1] == "char" then
- if event[2] == "-" then
- editingTable[editingKey] = editingTable[editingKey] * -1
- elseif tonumber(event[2]) ~= nil then
- if str == "0" then
- str = event[2]
- set(str)
- editingCursorPos = 2
- else
- local length = #str
- str = string.sub(str, 1, editingCursorPos - 1)..event[2]..string.sub(str, editingCursorPos)
- set(str)
- if #str > length then
- editingCursorPos = math.min(editingCursorPos + 1, #str + 1)
- end
- end
- else
- return handleRequirementsHeader(event)
- end
- elseif event[1] == "key" then
- if event[2] == 28 then
- editingTable = nil
- editingKey = nil
- editingCursorPos = nil
- elseif event[2] == 14 then
- --backspace
- local length = #str
- str = string.sub(str, 1, editingCursorPos - 2)..string.sub(str, editingCursorPos)
- if length > #str then
- editingCursorPos = math.max(editingCursorPos - 1, 1)
- end
- set(str)
- elseif event[2] == 211 then
- --delete
- str = string.sub(str, 1, editingCursorPos - 1)..string.sub(str, editingCursorPos + 1)
- set(str)
- elseif event[2] == 203 then
- --left
- editingCursorPos = math.max(editingCursorPos - 1, 1)
- elseif event[2] == 205 then
- --right
- editingCursorPos = math.min(editingCursorPos + 1, #str + 1)
- elseif event[2] == 199 then
- --home
- editingCursorPos = 1
- elseif event[2] == 207 then
- --end
- editingCursorPos = #str + 1
- end
- end
- end
- function handleLocations(event)
- local x, y = term.getSize()
- local column = math.ceil(x / 2)
- if event[1] == "mouse_click" then
- if event[4] <= 4 then
- handleRequirementsHeader(event)
- if display ~= displayLocations then
- term.setCursorBlink(false)
- editingTable, editingKey, editingCursorPos = nil, nil, nil
- return
- end
- elseif event[4] >= 6 and event[4] <= 8 then
- --clicked on one of the six xyz position entries.
- if event[3] >= 2 and event[3] <= column - 2 then
- --if GPS position, cannot edit starting positions.
- if posIsGPS then return end
- editingTable = loc
- elseif event[3] >= column and event[3] <= x - 1 then
- if not buildLoc then buildLoc = location.new() end
- editingTable = buildLoc
- end
- local keyLookup = {[6] = "x", [7] = "y", [8] = "z"}
- editingKey = keyLookup[event[4]]
- editingCursorPos = string.len(tostring(editingTable[editingKey])) + 1
- elseif event[4] == 9 then
- if event[3] >= 2 and event[3] <= column - 2 then
- --adjust start position facing unless position is GPS-based
- if posIsGPS then return end
- loc.h = loc.h + 1
- if loc.h == 5 then loc.h = 1 end
- elseif event[3] >= column and event[3] <= x - 1 then
- --adjust build position facing
- buildLoc.h = buildLoc.h + 1
- if buildLoc.h == 5 then buildLoc.h = 1 end
- end
- elseif event[4] == 11 then
- local optionsStart = (x - column - 9) / 2 + column
- if event[3] >= optionsStart and event[3] <= optionsStart + 8 and #project.requirements.locations > 0 then
- --clicked Options
- term.setCursorBlink(false)
- editingTable, editingKey, editingCursorPos = nil, nil, nil
- display = displayLocationOptions
- handler = handleLocationOptions
- end
- end
- elseif event[1] == "char" or event[1] == "key" then
- if event[1] == "key" and event[2] == 15 then
- --they hit tab
- if editingTable then
- if editingKey ~= "z" then
- editingKey = string.char(string.byte(editingKey) + 1)
- else
- editingKey = "x"
- if posIsGPS then
- editingTable = buildLoc
- else
- editingTable = editingTable == loc and buildLoc or loc
- end
- end
- else
- if posIsGPS then
- editingTable = buildLoc
- else
- editingTable = loc
- end
- editingKey = "x"
- editingCursorPos = string.len(tostring(editingTable[editingKey])) + 1
- end
- elseif editingTable and editingKey and editingCursorPos then
- numericRead(event)
- elseif event[1] == "char" then
- if event[2] == "h" then
- --loc facing
- if posIsGPS then return end
- loc.h = loc.h + 1
- if loc.h == 5 then loc.h = 1 end
- elseif event[2] == "H" then
- --buildLoc facing
- buildLoc.h = buildLoc.h + 1
- if buildLoc.h == 5 then buildLoc.h = 1 end
- elseif string.lower(event[2]) == "o" and #project.requirements.locations > 0 then
- --options
- term.setCursorBlink(false)
- editingTable, editingKey, editingCursorPos = nil, nil, nil
- display = displayLocationOptions
- handler = handleLocationOptions
- else
- return handleRequirementsHeader(event)
- end
- end
- end
- end
- function displayLocationOptions()
- drawRequirementsHeader()
- local x, y = term.getSize()
- local column = math.ceil(x / 2)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.clearLine()
- printCenter(project.name.." - Locations")
- do
- term.setCursorPos(2, 5)
- if project.requirements.locations.name then
- term.write(project.requirements.locations.name)
- else
- term.write("Location Options")
- end
- for i, locData in ipairs(project.requirements.locations) do
- term.setCursorPos(2, i + 5)
- if not term.isColor() then
- term.write(tostring(i)..": ")
- end
- term.write(locData.name)
- term.setCursorPos(column, i + 5)
- if type(locData.location) == "function" then
- local env = constructEnv()
- setfenv(locData.location, env)
- term.write(tostring(locData.location()))
- else
- term.write(tostring(locData.location))
- end
- end
- end
- end
- function handleLocationOptions(event)
- if event[1] == "mouse_click" then
- if event[4] <= 4 then
- return handleRequirementsHeader(event)
- elseif event[4] >= 6 and event[4] <= #project.requirements.locations + 5 then
- if type(project.requirements.locations[event[4] - 5].location) == "function" then
- buildLoc = project.requirements.locations[event[4] - 5].location()
- else
- buildLoc = project.requirements.locations[event[4] - 5].location
- end
- display = displayLocations
- handler = handleLocations
- end
- elseif event[1] == "char" then
- if tonumber(event[2]) then
- if type(project.requirements.locations[tonumber(event[2])].location) == "function" then
- buildLoc = project.requirements.locations[tonumber(event[2])].location()
- else
- buildLoc = project.requirements.locations[tonumber(event[2])].location
- end
- display = displayLocations
- handler = handleLocations
- else
- return handleRequirementsHeader(event)
- end
- end
- end
- function displayFueling()
- drawRequirementsHeader()
- local function setColors(bool)
- if term.isColor() then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(bool and colors.lime or colors.red)
- else
- term.setBackgroundColor(bool and colors.black or colors.white)
- term.setTextColor(bool and colors.white or colors.black)
- end
- end
- local x, y = term.getSize()
- local column = math.ceil(x / 2)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.clearLine()
- printCenter(project.name.." - Fueling")
- do
- local fuelCost = project.requirements.fuel
- if type(project.requirements.fuel) == "function" then
- local env = constructEnv()
- setfenv(project.requirements.fuel, env)
- fuelCost = project.requirements.fuel()
- end
- local fuel = turtle.getFuelLevel()
- term.setCursorPos(2, 5)
- term.write("Fuel ")
- if #project.requirements.slots < 16 then
- if term.isColor() then
- term.setTextColor(colors.lightGray)
- term.write("(Refuel)")
- else
- term.write("(")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write("R")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write("efuel)")
- end
- end
- term.setTextColor(colors.white)
- term.setCursorPos(2, 6)
- term.write("Available: ")
- setColors(fuel >= fuelCost)
- term.write(tostring(fuel))
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(2, 7)
- term.write("Required: "..fuelCost)
- end
- do
- if project.requirements.other and type(project.requirements.other) then
- local preReqs = {project.requirements.other()}
- if preReqs[1] == false then
- term.setCursorPos(column, 5)
- term.setTextColor(colors.white)
- term.write("Unmet Requirements:")
- for i = 2, #preReqs do
- term.setCursorPos(column, i + 4)
- term.write(preReqs[i])
- end
- end
- end
- end
- end
- function handleFueling(event)
- if event[1] == "mouse_click" then
- if event[4] <= 4 then
- return handleRequirementsHeader(event)
- elseif event[4] == 5 and event[3] >= 10 and event[3] <= 17 then
- --clicked Refuel
- for i = #project.requirements.slots + 1, 16 do
- turtle.select(i)
- turtle.refuel(64)
- end
- end
- elseif event[1] == "char" then
- if event[2] == "r" then
- for i = #project.requirements.slots + 1, 16 do
- turtle.select(i)
- turtle.refuel(64)
- end
- else
- return handleRequirementsHeader(event)
- end
- end
- end
- do
- local gpsVec = vector.new(gps.locate(0.5))
- if gpsVec.y > 0 then
- --if gps is already available, use those coordinates.
- loc = location.new(gpsVec.x, gpsVec.y, gpsVec.z, 0)
- if turtle.forward() then
- local secLoc = vector.new(gps.locate())
- local head = secLoc - gpsVec
- loc.h = location.getOrientation(head.x, head.z)
- if not turtle.back() then
- loc.x, loc.y, loc.z = secLoc.x, secLoc.y, secLoc.z
- end
- --set starting position to be unmodifiable.
- posIsGPS = true
- end
- else
- loc = location.new(0, 0, 0, 0)
- buildLoc = location.new(0, 0, 0, 0)
- end
- end
- display = displayProjects
- handler = handleProjects
- while not beginProject do
- display()
- if isReady() then
- local xCur, yCur = term.getCursorPos()
- local x, y = term.getSize()
- term.setCursorPos(1, y)
- term.setBackgroundColor(term.isColor() and colors.green or colors.black)
- term.setTextColor(colors.white)
- printCenter(" GO ")
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setCursorPos(xCur, yCur)
- end
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- local x, y = term.getSize()
- if event[4] == y and isReady() then
- local start = (x - 4) / 2 + 1
- if event[3] >= start and event[3] <= start + 3 then
- beginProject = true
- else
- handler(event)
- end
- elseif event[4] == 1 then
- display = displayProjects
- handler = handleProjects
- resetState()
- else
- handler(event)
- end
- elseif event[1] == "char" then
- if event[2] == "q" then
- break
- elseif event[2] == "p" then
- --reset project
- display = displayProjects
- handler = handleProjects
- resetState()
- elseif event[2] == "g" and isReady() then
- beginProject = true
- else
- handler(event)
- end
- else
- handler(event)
- end
- end
- if beginProject then
- setfenv(project.instructions, constructEnv())
- project.instructions()
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement