2018-09-14 14:15:25 +02:00
|
|
|
--[[-- info
|
2018-09-14 15:18:23 +02:00
|
|
|
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 15:18:23 +02:00
|
|
|
|
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
|
2018-09-14 15:18:23 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-09-14 15:18:23 +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
|