Code cleanup

This commit is contained in:
LemADEC 2015-10-06 00:37:17 +02:00
parent 70dd051b49
commit 0db08b62c4

View file

@ -1,8 +1,5 @@
monitor_textScale = 0.5
-- set alarm side if you need this
alarm_side = "top"
Style = {
CDefault = colors.white,
BGDefault = colors.blue,
@ -152,24 +149,24 @@ function ShowTitle(text)
SetColorDefault()
end
function ShowMenu(Text)
Write(Text)
function ShowMenu(text)
Write(text)
local xt, yt = term.getCursorPos()
for i = xt, 51 do
Write(" ")
end
SetCursorPos(1, yt+1)
SetCursorPos(1, yt + 1)
end
local clearWarningTick = -1
function ShowWarning(Text)
function ShowWarning(text)
SetColorWarning()
SetCursorPos((51 - Text:len() - 2) / 2, 19)
Write(" "..Text.." ")
SetCursorPos((51 - text:len() - 2) / 2, 19)
Write(" " .. text .. " ")
SetColorDefault()
clearWarningTick = 5
end
function ClearWarning(Text)
function ClearWarning(text)
if clearWarningTick > 0 then
clearWarningTick = clearWarningTick - 1
elseif clearWarningTick == 0 then
@ -401,256 +398,6 @@ function redstone_event()
end
end
----------- Cloaking support
cloaking_highTier = false
cloaking_currentKey = 1
function cloaking_key(keycode)
if keycode == 31 then -- S
cloaking_start()
return true
elseif keycode == 25 then -- P
cloaking_stop()
return true
elseif keycode == 20 then -- T
cloaking_highTier = not cloaking_highTier
return true
end
return false
end
function cloaking_page()
ShowTitle(label .. " - Cloaking status")
local cloakingcore = nil
if cloakingcores ~= nil then
if cloaking_currentKey > #cloakingcores then
cloaking_currentKey = 1
end
cloakingcore = cloakingcores[cloaking_currentKey]
end
SetCursorPos(1, 2)
if #cloakingcores == 0 then
SetColorDisabled()
Write("No cloaking core detected...")
elseif cloakingcore == nil then
SetColorWarning()
Write("Cloaking core " .. cloaking_currentKey .. " of " .. #cloakingcores .. " is invalid")
else
SetColorDefault()
Write("Cloaking core " .. cloaking_currentKey .. " of " .. #cloakingcores)
local isAssemblyValid = cloakingcore.isAssemblyValid()
local energy, energyMax = cloakingcore.energy()
local isEnabled = cloakingcore.enable()
if not isAssemblyValid then
SetColorWarning()
SetCursorPos(1, 3)
Write("Invalid assembly!")
SetColorDefault()
SetCursorPos(1, 4)
print("In each direction, you need to place exactly 2 Cloaking device coils, for a total of 12 coils.")
print("The 6 inner coils shall be exactly one block away from the core.")
print("The cloaking field will extend 5 blocks past the outer 6 coils.")
print("Power consumption scales with the amount of cloaked blocks.")
else
SetCursorPos(1, 4)
Write("Assembly is valid")
if energy < 50000 then
SetColorWarning()
else
SetColorDefault()
end
SetCursorPos(1, 6)
Write("Energy level is " .. energy .. " EU")
SetCursorPos(1, 8)
if isEnabled then
if energy <= 100 then
SetColorWarning()
else
SetColorSuccess()
end
Write("Cloak is enabled")
else
SetColorNormal()
Write("Cloak is disabled")
end
end
end
sleep(0.1)
cloaking_currentKey = cloaking_currentKey + 1
SetColorDefault()
SetCursorPos(1, 12)
Write(" -----------------------------------------------")
SetCursorPos(1, 13)
if cloaking_highTier then
Write("Cloak tier: HIGH")
else
Write("Cloak tier: low")
end
SetColorTitle()
SetCursorPos(1, 16)
ShowMenu("S - Start cloaking, P - stoP cloaking")
SetCursorPos(1, 17)
ShowMenu("T - change low/high Tier")
end
function cloaking_start()
for key,cloakingcore in pairs(cloakingcores) do
cloakingcore.enable(false)
if cloaking_highTier then
cloakingcore.tier(2)
else
cloakingcore.tier(1)
end
cloakingcore.enable(true)
end
end
function cloaking_stop()
for key,cloakingcore in pairs(cloakingcores) do
cloakingcore.enable(false)
end
end
----------- Mining lasers support
mining_currentKey = 1
mining_layerOffset = 1
mining_mineAll = true
mining_useDeuterium = false
function mining_key(keycode)
if keycode == 31 then -- S
mining_start()
return true
elseif keycode == 25 then -- P
mining_stop()
return true
elseif keycode == 30 then -- A
mining_mineAll = not mining_mineAll
return true
elseif keycode == 32 then -- D
mining_useDeuterium = not mining_useDeuterium
return true
elseif keycode == 74 then -- -
mining_layerOffset = mining_layerOffset - 1
if mining_layerOffset < 1 then
mining_layerOffset = 1
end
return true
elseif keycode == 78 then -- +
mining_layerOffset = mining_layerOffset + 1
return true
elseif keycode == 46 then -- C
mining_page_config()
return true
end
return false
end
function mining_page()
ShowTitle(label .. " - Mining status")
local mininglaser = nil
if mininglasers ~= nil then
if mining_currentKey > #mininglasers then
mining_currentKey = 1
end
mininglaser = mininglasers[mining_currentKey]
end
SetCursorPos(1, 2)
if #mininglasers == 0 then
SetColorDisabled()
Write("No mining laser detected...")
elseif mininglaser == nil then
SetColorWarning()
Write("Mining laser " .. mining_currentKey .. " of " .. #mininglasers .. " is invalid")
else
SetColorDefault()
Write("Mining laser " .. mining_currentKey .. " of " .. #mininglasers)
local status, energy, currentLayer, mined, total = mininglaser.state()
SetCursorPos(1, 3)
Write("Status: " .. status .. " ")
SetCursorPos(1, 5)
Write("Energy level is " .. energy .. " EU")
SetCursorPos(1, 7)
Write("Mined " .. mined .. " out of " .. total .. " blocks at layer " .. currentLayer .. " ")
end
sleep(0.1)
mining_currentKey = mining_currentKey + 1
SetColorDefault()
SetCursorPos(1, 11)
Write(" -----------------------------------------------")
SetCursorPos(1, 12)
Write("Layer offset: " .. mining_layerOffset)
SetCursorPos(1, 13)
Write("Mine all: " .. boolToYesNo(mining_mineAll))
SetCursorPos(1, 14)
Write("Use Deuterium: " .. boolToYesNo(mining_useDeuterium))
SetColorTitle()
SetCursorPos(1, 16)
ShowMenu("S - Start mining, P - stoP mining, A - mine All")
SetCursorPos(1, 17)
ShowMenu("D - use Deuterium, +/-/C - adjust offset")
end
function mining_page_config()
ShowTitle(label .. " - Mining configuration")
Write(" Layer offset (".. mining_layerOffset ..") : ")
mining_layerOffset = readInputNumber(mining_layerOffset)
if mining_layerOffset < 1 then
mining_layerOffset = 1
end
end
function mining_start()
for key,mininglaser in pairs(mininglasers) do
if not mininglaser.isMining() then
mininglaser.offset(mining_layerOffset)
if mining_mineAll then
if mining_useDeuterium then
mininglaser.quarry(mining_useDeuterium)
else
mininglaser.quarry()
end
else
if mining_useDeuterium then
mininglaser.mine(mining_useDeuterium)
else
mininglaser.mine()
end
end
end
end
end
function mining_stop()
if #mininglasers == 0 then
SetColorWarning()
Write("No mining laser detected")
else
for key,mininglaser in pairs(mininglasers) do
SetCursorPos(1, 2 + key)
if not mininglaser.isMining() then
SetColorDisabled()
Write("Mining laser " .. key .. " of " .. #mininglasers .. " is already stopped")
else
mininglaser.stop()
SetColorSuccess()
Write("Mining laser " .. key .. " of " .. #mininglasers .. " has been stopped")
end
end
end
end
----------- Configuration
function data_save()