1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-20 03:29:26 +02:00
RedMew/Diggy/Feature/DiggyTilePressure.lua

61 lines
1.4 KiB
Lua
Raw Normal View History

2018-09-14 14:15:25 +02:00
--[[-- info
Provides the ability to show pressure values on the map.
2018-09-14 14:15:25 +02:00
]]
-- dependencies
local Event = require 'utils.event'
local PressureMap = require 'Diggy.PressureMap'
-- this
local DiggyTilePressure = {}
--[[--
Registers all event handlers.]
@param config Table {@see Diggy.Config}.
]]
function DiggyTilePressure.register(config)
Event.add(PressureMap.events.on_pressure_changed, function(event)
2018-09-14 14:15:25 +02:00
local r = event.value
local g = 1 - event.value
if r < 0 then r = 0 end
if r > 1 then r = 1 end
if g < 0 then g = 0 end
if g > 1 then g = 1 end
local text = math.floor(1000 * event.value) / 1000
local color = { r = r, g = g, b = 0}
local e = event.surface.find_entity("flying-text", event.position)
2018-09-14 14:15:25 +02:00
if e then
e.text = text
e.color = color
else
local e = event.surface.create_entity{
name ="flying-text",
color = color,
text = text,
position = event.position
}
e.active = false
end
2018-09-14 14:15:25 +02:00
end)
end
--[[--
Initializes the Feature.
@param config Table {@see Diggy.Config}.
]]
function DiggyTilePressure.initialize(config)
end
return DiggyTilePressure