1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/Diggy/Feature/DiggyTileStress.lua

67 lines
1.5 KiB
Lua
Raw Normal View History

2018-09-14 14:15:25 +02:00
--[[-- info
2018-09-19 18:55:07 +02:00
Provides the ability to show stress values on the map.
2018-09-14 14:15:25 +02:00
]]
-- dependencies
local Event = require 'utils.event'
2018-09-19 18:55:07 +02:00
local StressMap = require 'map_gen.Diggy.StressMap'
2018-09-14 14:15:25 +02:00
-- this
2018-09-19 18:55:07 +02:00
local DiggyTileStress = {}
2018-09-14 14:15:25 +02:00
--[[--
Registers all event handlers.]
@param config Table {@see Diggy.Config}.
]]
2018-09-19 18:55:07 +02:00
function DiggyTileStress.register(config)
Event.add(StressMap.events.on_stress_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(100 * event.value) / 100
local color = { r = r, g = g, b = 0}
2018-09-14 21:42:58 +02:00
local text_entity = event.surface.find_entity('flying-text', event.position)
2018-09-14 14:15:25 +02:00
2018-09-14 21:42:58 +02:00
if text_entity then
if text == 0 then
text_entity.destroy()
return
end
2018-09-14 21:42:58 +02:00
text_entity.text = text
text_entity.color = color
return
end
if (text == 0) then
return
end
2018-09-14 21:42:58 +02:00
event.surface.create_entity{
name = 'flying-text',
color = color,
text = text,
position = event.position
}.active = false
2018-09-14 14:15:25 +02:00
end)
end
--[[--
Initializes the Feature.
@param config Table {@see Diggy.Config}.
]]
2018-09-19 18:55:07 +02:00
function DiggyTileStress.initialize(config)
2018-09-14 14:15:25 +02:00
end
2018-09-19 18:55:07 +02:00
return DiggyTileStress