2022-08-01 16:05:39 +00:00
|
|
|
-- Reactor Core View Graphics Element
|
|
|
|
|
|
|
|
local util = require("scada-common.util")
|
|
|
|
|
|
|
|
local core = require("graphics.core")
|
|
|
|
local element = require("graphics.element")
|
|
|
|
|
|
|
|
---@class core_map_args
|
2022-08-02 14:46:21 +00:00
|
|
|
---@field reactor_l integer reactor length
|
|
|
|
---@field reactor_w integer reactor width
|
2022-08-01 16:05:39 +00:00
|
|
|
---@field parent graphics_element
|
|
|
|
---@field id? string element id
|
|
|
|
---@field x? integer 1 if omitted
|
|
|
|
---@field y? integer 1 if omitted
|
|
|
|
|
|
|
|
-- new core map box
|
|
|
|
---@param args core_map_args
|
|
|
|
---@return graphics_element element, element_id id
|
|
|
|
local function core_map(args)
|
2022-08-02 14:46:21 +00:00
|
|
|
assert(util.is_int(args.reactor_l), "graphics.elements.indicators.coremap: reactor_l is a required field")
|
|
|
|
assert(util.is_int(args.reactor_w), "graphics.elements.indicators.coremap: reactor_w is a required field")
|
2022-08-01 16:05:39 +00:00
|
|
|
|
2022-09-12 17:53:39 +00:00
|
|
|
-- require max dimensions
|
|
|
|
args.width = 18
|
|
|
|
args.height = 18
|
2022-08-02 14:46:21 +00:00
|
|
|
|
|
|
|
-- inherit only foreground color
|
|
|
|
args.fg_bg = core.graphics.cpair(args.parent.get_fg_bg().fgd, colors.gray)
|
2022-08-01 16:05:39 +00:00
|
|
|
|
|
|
|
-- create new graphics element base object
|
|
|
|
local e = element.new(args)
|
|
|
|
|
|
|
|
local alternator = true
|
|
|
|
|
2022-09-12 18:38:48 +00:00
|
|
|
local core_l = args.reactor_l - 2
|
|
|
|
local core_w = args.reactor_w - 2
|
|
|
|
|
|
|
|
local shift_x = 8 - math.floor(core_l / 2)
|
|
|
|
local shift_y = 8 - math.floor(core_w / 2)
|
2022-08-01 16:05:39 +00:00
|
|
|
|
2022-09-12 17:53:39 +00:00
|
|
|
local start_x = 2 + shift_x
|
|
|
|
local start_y = 2 + shift_y
|
2022-08-02 14:46:21 +00:00
|
|
|
|
2022-09-12 18:38:48 +00:00
|
|
|
local inner_width = core_l
|
|
|
|
local inner_height = core_w
|
2022-08-02 14:46:21 +00:00
|
|
|
|
2022-09-12 17:53:39 +00:00
|
|
|
-- create coordinate grid and frame
|
|
|
|
local function draw_frame()
|
|
|
|
e.window.setTextColor(colors.white)
|
2022-08-02 14:46:21 +00:00
|
|
|
|
2022-09-12 17:53:39 +00:00
|
|
|
for x = 0, (inner_width - 1) do
|
|
|
|
e.window.setCursorPos(x + start_x, 1)
|
|
|
|
e.window.write(util.sprintf("%X", x))
|
|
|
|
end
|
2022-08-02 14:46:21 +00:00
|
|
|
|
2022-09-12 17:53:39 +00:00
|
|
|
for y = 0, (inner_height - 1) do
|
|
|
|
e.window.setCursorPos(1, y + start_y)
|
|
|
|
e.window.write(util.sprintf("%X", y))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- even out bottom edge
|
|
|
|
e.window.setTextColor(e.fg_bg.bkg)
|
|
|
|
e.window.setBackgroundColor(args.parent.get_fg_bg().bkg)
|
|
|
|
e.window.setCursorPos(1, e.frame.h)
|
|
|
|
e.window.write(util.strrep("\x8f", e.frame.w))
|
|
|
|
e.window.setTextColor(e.fg_bg.fgd)
|
|
|
|
e.window.setBackgroundColor(e.fg_bg.bkg)
|
|
|
|
end
|
2022-08-02 14:46:21 +00:00
|
|
|
|
2022-08-01 16:05:39 +00:00
|
|
|
-- draw the core
|
2022-08-02 14:46:21 +00:00
|
|
|
---@param t number temperature in K
|
2022-09-12 17:53:39 +00:00
|
|
|
local function draw_core(t)
|
2022-08-01 16:05:39 +00:00
|
|
|
local i = 1
|
2022-08-02 14:46:21 +00:00
|
|
|
local back_c = "F"
|
|
|
|
local text_c = "8"
|
2022-08-01 16:05:39 +00:00
|
|
|
|
|
|
|
-- determine fuel assembly coloring
|
|
|
|
if t <= 300 then
|
|
|
|
-- gray
|
2022-08-02 14:46:21 +00:00
|
|
|
text_c = "8"
|
2022-08-01 16:05:39 +00:00
|
|
|
elseif t <= 350 then
|
|
|
|
-- blue
|
2022-08-02 14:46:21 +00:00
|
|
|
text_c = "3"
|
2022-08-01 16:05:39 +00:00
|
|
|
elseif t < 600 then
|
|
|
|
-- green
|
2022-08-02 14:46:21 +00:00
|
|
|
text_c = "D"
|
2022-08-01 16:05:39 +00:00
|
|
|
elseif t < 1000 then
|
|
|
|
-- yellow
|
2022-08-02 14:46:21 +00:00
|
|
|
text_c = "4"
|
|
|
|
-- back_c = "8"
|
2022-08-01 16:05:39 +00:00
|
|
|
elseif t < 1200 then
|
|
|
|
-- orange
|
2022-08-02 14:46:21 +00:00
|
|
|
text_c = "1"
|
2022-08-01 16:05:39 +00:00
|
|
|
elseif t < 1300 then
|
|
|
|
-- red
|
2022-08-02 14:46:21 +00:00
|
|
|
text_c = "E"
|
2022-08-01 16:05:39 +00:00
|
|
|
else
|
|
|
|
-- pink
|
2022-08-02 14:46:21 +00:00
|
|
|
text_c = "2"
|
2022-08-01 16:05:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- draw pattern
|
|
|
|
for y = start_y, inner_height + (start_y - 1) do
|
|
|
|
e.window.setCursorPos(start_x, y)
|
2022-09-12 17:53:39 +00:00
|
|
|
for _ = 1, inner_width do
|
2022-08-01 16:05:39 +00:00
|
|
|
if alternator then
|
|
|
|
i = i + 1
|
2022-08-02 14:46:21 +00:00
|
|
|
e.window.blit("\x07", text_c, back_c)
|
2022-08-01 16:05:39 +00:00
|
|
|
else
|
2022-08-02 14:46:21 +00:00
|
|
|
e.window.blit("\x07", "7", "8")
|
2022-08-01 16:05:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
alternator = not alternator
|
|
|
|
end
|
|
|
|
|
|
|
|
if inner_width % 2 == 0 then alternator = not alternator end
|
|
|
|
end
|
2022-10-03 01:17:13 +00:00
|
|
|
|
|
|
|
-- reset alternator
|
|
|
|
alternator = true
|
2022-08-01 16:05:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- on state change
|
2022-08-02 14:46:21 +00:00
|
|
|
---@param temperature number temperature in Kelvin
|
2022-08-01 16:05:39 +00:00
|
|
|
function e.on_update(temperature)
|
2022-09-12 16:59:28 +00:00
|
|
|
e.value = temperature
|
2022-09-12 17:53:39 +00:00
|
|
|
draw_core(e.value)
|
2022-08-01 16:05:39 +00:00
|
|
|
end
|
|
|
|
|
2022-09-12 17:53:39 +00:00
|
|
|
-- set temperature to display
|
|
|
|
---@param val number degrees K
|
2022-09-12 16:59:28 +00:00
|
|
|
function e.set_value(val) e.on_update(val) end
|
|
|
|
|
2022-09-12 17:53:39 +00:00
|
|
|
-- resize reactor dimensions
|
|
|
|
---@param reactor_l integer reactor length (rendered in 2D top-down as width)
|
|
|
|
---@param reactor_w integer reactor width (rendered in 2D top-down as height)
|
|
|
|
function e.resize(reactor_l, reactor_w)
|
|
|
|
-- enforce possible dimensions
|
2022-09-12 18:38:48 +00:00
|
|
|
if reactor_l > 18 then reactor_l = 18 elseif reactor_l < 3 then reactor_l = 3 end
|
|
|
|
if reactor_w > 18 then reactor_w = 18 elseif reactor_w < 3 then reactor_w = 3 end
|
2022-09-12 17:53:39 +00:00
|
|
|
|
|
|
|
-- update dimensions
|
2022-09-12 18:38:48 +00:00
|
|
|
core_l = reactor_l - 2
|
|
|
|
core_w = reactor_w - 2
|
|
|
|
shift_x = 8 - math.floor(core_l / 2)
|
|
|
|
shift_y = 8 - math.floor(core_w / 2)
|
2022-09-12 17:53:39 +00:00
|
|
|
start_x = 2 + shift_x
|
|
|
|
start_y = 2 + shift_y
|
2022-09-12 18:38:48 +00:00
|
|
|
inner_width = core_l
|
|
|
|
inner_height = core_w
|
2022-09-12 17:53:39 +00:00
|
|
|
|
|
|
|
e.window.clear()
|
|
|
|
|
|
|
|
-- re-draw
|
|
|
|
draw_frame()
|
|
|
|
e.on_update(e.value)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- initial (one-time except for resize()) frame draw
|
|
|
|
draw_frame()
|
|
|
|
|
|
|
|
-- initial draw
|
|
|
|
e.on_update(0)
|
2022-09-12 16:59:28 +00:00
|
|
|
|
2022-08-01 16:05:39 +00:00
|
|
|
return e.get()
|
|
|
|
end
|
|
|
|
|
|
|
|
return core_map
|