Improved environmental sensor default LUA script

This commit is contained in:
LemADEC 2021-01-24 15:37:36 +01:00
parent 52fb302f7c
commit 00967b63e7
2 changed files with 131 additions and 15 deletions

View file

@ -33,6 +33,10 @@ if noExit then
local isRunning = true
repeat
for key, environmentalSensor in pairs(environmentalSensors) do
local isSuccessAtmosphere, isBreathable, airConcentration = environmentalSensor.getAtmosphere()
local isSuccessBiome, biomeName, biomeTag1, biomeTag2, biomeTag3 = environmentalSensor.getBiome()
local isSuccessHumidity, humidityCategory, biomeRainfall = environmentalSensor.getHumidity()
local isSuccessTemperature, biomeTemperatureCategory, biomeTemperature = environmentalSensor.getTemperature()
local isSuccessWeather, currentWeather, nextWeatherSeconds = environmentalSensor.getWeather()
local isSuccessWorldTime, day, hours, minutes, totalSeconds = environmentalSensor.getWorldTime()
@ -57,35 +61,95 @@ if noExit then
else
-- show failure message
term.setTextColor(colors.red)
term.write("Local weather is ? (" .. currentWeather .. ")")
term.write("Local weather is ? (" .. currentWeather .. ").")
end
term.setCursorPos(1, 5)
if isSuccessWorldTime then
if hours >= 6 and hours < 18 then
term.setTextColor(colors.white)
if isSuccessAtmosphere then
if isBreathable then
term.setTextColor(colors.green)
term.write("Atmosphere is breathable (" .. airConcentration .. " air concentration).")
else
term.setTextColor(colors.lightGray)
term.setTextColor(colors.orange)
term.write("Atmosphere is NON-breathable (" .. airConcentration .. " air concentration).")
end
term.write("Day " .. day)
else
-- show failure message
term.setTextColor(colors.red)
term.write("Day ? (" .. day .. ")")
term.write("Atmosphere is ? (" .. isBreathable .. ").")
end
term.setCursorPos(1, 7)
if isSuccessBiome then
if biomeTag1 == nil then
biomeTag1 = ""
end
if biomeTag2 == nil then
biomeTag2 = ""
end
if biomeTag3 == nil then
biomeTag3 = ""
end
term.setTextColor(colors.white)
term.write("Biome is " .. biomeName .. " [" .. biomeTag1 .. " " .. biomeTag2 .. " " .. biomeTag3 .. " ...].")
else
-- show failure message
term.setTextColor(colors.red)
term.write("Biome is ? (" .. biomeName .. ").")
end
term.setCursorPos(1, 9)
if isSuccessHumidity then
if humidityCategory == "DRY" then
term.setTextColor(colors.yellow)
elseif humidityCategory == "WET" then
term.setTextColor(colors.blue)
else
term.setTextColor(colors.white)
end
term.write("Humidity is " .. string.format("%.2f", biomeRainfall) .. " in " .. humidityCategory .. " category.")
else
-- show failure message
term.setTextColor(colors.red)
term.write("Humidity is ? (" .. humidityCategory .. ").")
end
term.setCursorPos(1, 11)
if isSuccessTemperature then
term.setTextColor(colors.white)
term.write("Temperature is " .. string.format("%.3f", biomeTemperature) .. " in " .. biomeTemperatureCategory .. " category.")
else
-- show failure message
term.setTextColor(colors.red)
term.write("Temperature is ? (" .. biomeTemperatureCategory .. ").")
end
term.setCursorPos(1, 13)
if isSuccessWorldTime then
if hours >= 6 and hours < 18 then
term.setTextColor(colors.white)
else
term.setTextColor(colors.lightGray)
end
term.write("Local time is " .. string.format("%02d", hours) .. ":" .. string.format("%02d", minutes))
term.write("World day is " .. day .. ".")
else
-- show failure message
term.setTextColor(colors.red)
term.write("Local time is ? (" .. day .. ")")
term.write("World day is ? (" .. day .. ").")
end
term.setCursorPos(1, 15)
if isSuccessWorldTime then
if hours >= 6 and hours < 18 then
term.setTextColor(colors.white)
else
term.setTextColor(colors.lightGray)
end
term.write("Local time is " .. string.format("%02d", hours) .. ":" .. string.format("%02d", minutes) .. ".")
else
-- show failure message
term.setTextColor(colors.red)
term.write("Local time is ? (" .. day .. ").")
end
os.sleep(1)

View file

@ -51,6 +51,10 @@ if noExit then
local isRunning = true
repeat
for key, environmentalSensor in pairs(environmentalSensors) do
local isSuccessAtmosphere, isBreathable, airConcentration = environmentalSensor.getAtmosphere()
local isSuccessBiome, biomeName, biomeTag1, biomeTag2, biomeTag3 = environmentalSensor.getBiome()
local isSuccessHumidity, humidityCategory, biomeRainfall = environmentalSensor.getHumidity()
local isSuccessTemperature, biomeTemperatureCategory, biomeTemperature = environmentalSensor.getTemperature()
local isSuccessWeather, currentWeather, nextWeatherSeconds = environmentalSensor.getWeather()
local isSuccessWorldTime, day, hours, minutes, totalSeconds = environmentalSensor.getWorldTime()
@ -69,9 +73,57 @@ if noExit then
textOut(1, 3, "Local weather is " .. currentWeather .. ", changing in " .. string.format("%d", math.floor(nextWeatherSeconds)) .. " s.", colorText, 0x000000)
else
-- show failure message
textOut(1, 3, "Local weather is ? (" .. currentWeather .. ")", 0xFF0000, 0x000000)
textOut(1, 3, "Local weather is ? (" .. currentWeather .. ").", 0xFF0000, 0x000000)
end
if isSuccessAtmosphere then
if isBreathable then
textOut(1, 5, "Atmosphere is breathable (" .. airConcentration .. " air concentration).", 0x8080FF, 0x8080FF)
else
textOut(1, 5, "Atmosphere is NON-breathable (" .. airConcentration .. " air concentration).", 0xFF8080, 0x000000)
end
else
-- show failure message
textOut(1, 5, "Atmosphere is ? (" .. isBreathable .. ").", 0xFF0000, 0x000000)
end
if isSuccessBiome then
if biomeTag1 == nil then
biomeTag1 = ""
end
if biomeTag2 == nil then
biomeTag2 = ""
end
if biomeTag3 == nil then
biomeTag3 = ""
end
textOut(1, 7, "Biome is " .. biomeName .. " [" .. biomeTag1 .. " " .. biomeTag2 .. " " .. biomeTag3 .. " ...].", 0xFFFFFF, 0x000000)
else
-- show failure message
textOut(1, 7, "Biome is ? (" .. biomeName .. ").", 0xFF0000, 0x000000)
end
if isSuccessHumidity then
if humidityCategory == "DRY" then
colorText = 0xFFFF00
elseif humidityCategory == "WET" then
colorText = 0x8080FF
else
colorText = 0xFFFFFF
end
textOut(1, 9, "Humidity is " .. string.format("%.2f", biomeRainfall) .. " in " .. humidityCategory .. " category.", colorText, 0x000000)
else
-- show failure message
textOut(1, 9, "Humidity is ? (" .. humidityCategory .. ").", 0xFF0000, 0x000000)
end
if isSuccessTemperature then
textOut(1, 11, "Temperature is " .. string.format("%.3f", biomeTemperature) .. " in " .. biomeTemperatureCategory .. " category.", 0xFFFFFF, 0x000000)
else
-- show failure message
textOut(1, 11, "Temperature is ? (" .. biomeTemperatureCategory .. ").", 0xFF0000, 0x000000)
end
if isSuccessWorldTime then
local colorText
if hours >= 6 and hours < 18 then
@ -79,10 +131,10 @@ if noExit then
else
colorText = 0x808080
end
textOut(1, 5, "Day " .. string.format("%d", math.floor(day)), colorText, 0x000000)
textOut(1, 13, "Day " .. string.format("%d", math.floor(day)), colorText, 0x000000)
else
-- show failure message
textOut(1, 5, "Day ? (" .. day .. ")", 0xFF0000, 0x000000)
textOut(1, 13, "Day ? (" .. day .. ")", 0xFF0000, 0x000000)
end
if isSuccessWorldTime then
@ -91,10 +143,10 @@ if noExit then
else
colorText = 0x808080
end
textOut(1, 7, "Local time is " .. string.format("%02d", hours) .. ":" .. string.format("%02d", minutes), colorText, 0x000000)
textOut(1, 15, "Local time is " .. string.format("%02d", hours) .. ":" .. string.format("%02d", minutes), colorText, 0x000000)
else
-- show failure message
textOut(1, 7, "Local time is ? (" .. day .. ")", 0xFF0000, 0x000000)
textOut(1, 15, "Local time is ? (" .. day .. ")", 0xFF0000, 0x000000)
end
os.sleep(1)