This commit is contained in:
Igor Timofeev 2018-06-15 01:41:50 +03:00
parent 1a28f00c3e
commit 7c5313fbe9
3 changed files with 66 additions and 4 deletions

View File

@ -1,6 +1,8 @@
local component = require("component") local component = require("component")
local GUI = require("GUI") local GUI = require("GUI")
local color = require("color")
local computer = require("computer")
local filesystem = require("filesystem") local filesystem = require("filesystem")
local MineOSPaths = require("MineOSPaths") local MineOSPaths = require("MineOSPaths")
@ -11,7 +13,7 @@ local modem = component.modem
local port = 512 local port = 512
config = { local config = {
glassesX = 0, glassesX = 0,
glassesY = 0, glassesY = 0,
glassesZ = 0, glassesZ = 0,
@ -101,7 +103,7 @@ end
layout:addChild(GUI.button(1, 1, width, 3, 0xC3C3C3, 0xFFFFFF, 0x969696, 0xFFFFFF, "Scan")).onTouch = function() layout:addChild(GUI.button(1, 1, width, 3, 0xC3C3C3, 0xFFFFFF, 0x969696, 0xFFFFFF, "Scan")).onTouch = function()
saveConfig() saveConfig()
broadcast("scan", table.toString({ broadcast("scan", table.toString({
width = config.width, width = config.width,
height = config.height, height = config.height,
@ -125,7 +127,12 @@ layout.eventHandler = function(mainContainer, layout, e1, e2, e3, e4, e5, e6, e7
for i = 1, #result.blocks[x][y][z] do for i = 1, #result.blocks[x][y][z] do
local cube = glasses.addCube3D() local cube = glasses.addCube3D()
cube.setVisibleThroughObjects(true) cube.setVisibleThroughObjects(true)
cube.setColor(0, 0.6, 1)
local maxHue = 240
local hue = (1 - result.blocks[x][y][z][i] / config.maxDensity) * maxHue
local r, g, b = color.HSBToRGB(hue, 1, 1)
cube.setColor(r / 255, g / 255, b / 255)
cube.setAlpha(0.5) cube.setAlpha(0.5)
cube.set3DPos( cube.set3DPos(
config.robotX - config.glassesX + result.x + x, config.robotX - config.glassesX + result.x + x,
@ -133,6 +140,8 @@ layout.eventHandler = function(mainContainer, layout, e1, e2, e3, e4, e5, e6, e7
config.robotZ - config.glassesZ + result.z + z config.robotZ - config.glassesZ + result.z + z
) )
end end
computer.pullSignal(0)
end end
end end
end end

View File

@ -0,0 +1,51 @@
local robot = component.proxy(component.list("robot")())
local redstone = component.proxy(component.list("redstone")())
local gpu = component.proxy(component.list("gpu")())
local width, height = gpu.getResolution()
local tryCatchTime = 30
local startSleepTime = 3
local catchSleepTime = 3
local side = 0
local useTime = 1
local function print(text)
gpu.copy(1, 1, width, height, 0, -1)
gpu.set(1, height, text)
end
local function sleep(timeout)
local deadline = computer.uptime() + (timeout or 0)
while computer.uptime() < deadline do
computer.pullSignal(deadline - computer.uptime())
end
end
local function pushRod()
print("Pushing rod...")
robot.use(side, true, useTime)
sleep(startSleepTime)
end
local function pullRod()
print("Pulling rod...")
robot.use(side, true, useTime)
sleep(catchSleepTime)
end
pushRod()
while true do
local e = {computer.pullSignal(tryCatchTime)}
if e[1] == "redstone_changed" then
if e[5] == 0 then
pullRod()
pushRod()
end
elseif not e[1] then
pullRod()
pushRod()
end
end

View File

@ -130,10 +130,12 @@ local function newThing(x, y, width, height)
end end
local function dial(address) local function dial(address)
local success = stargate.dial(address) local success, reason = stargate.dial(address)
if success then if success then
mainContainer.fuelProgressBar.value = math.ceil(stargate.energyToDial(address) / stargate.energyAvailable() * 100) mainContainer.fuelProgressBar.value = math.ceil(stargate.energyToDial(address) / stargate.energyAvailable() * 100)
mainContainer:drawOnScreen() mainContainer:drawOnScreen()
else
GUI.alert("Failed to dial: " .. tostring(reason))
end end
end end