z_mirror/BottleneckLite

git clone https://git.raiguard.me/z_mirror/BottleneckLite

Caleb HeuerAdjust colors in default stylece25749

new-style
3.5 KiB127 linesraw
1local bounding_box = require("__flib__/bounding-box")
2
3local constants = require("__BottleneckLite__/constants")
4
5if not settings.startup["bnl-enable"].value then
6  return
7end
8
9local enable_glow = settings.startup["bnl-glow"].value
10local size = constants.sizes[settings.startup["bnl-indicator-size"].value]
11local style = settings.startup["bnl-indicator-style"].value
12local animation
13if style == "default" then
14  animation = {
15    filename = "__flib__/graphics/indicators.png",
16    flags = { "icon" },
17    y = 32,
18    size = 32,
19    scale = size * 4,
20    line_length = 1,
21    frame_count = 1,
22    animation_speed = 1,
23    direction_count = 1,
24  }
25elseif style == "solid" then
26  animation = {
27    filename = "__BottleneckLite__/graphics/solid.png",
28    flags = { "icon" },
29    size = 64,
30    scale = size,
31    line_length = 1,
32    frame_count = 1,
33    animation_speed = 1,
34    direction_count = 1,
35  }
36end
37
38local status_colors = {}
39for name, spec in pairs(settings.startup) do
40  local matched, _, key = string.find(name, "^bnl%-color%-(.-)$")
41  if matched then
42    status_colors[key] = constants.colors[style][spec.value]
43  end
44end
45
46local function build_indicator(prototype)
47  -- Calculate shift for the indicator
48  local box = bounding_box.ensure_explicit(prototype.selection_box or prototype.collision_box or prototype.drawing_box)
49  local positions = {
50    north_south = {},
51    east_west = {},
52  }
53  for _, tbl in pairs(positions) do
54    tbl[1] = box.left_top.x + (bounding_box.width(box) * constants.horizontal_position) -- X
55    tbl[2] = box.right_bottom.y - size - constants.additional_vertical_offset -- Y
56    box = bounding_box.rotate(box)
57  end
58
59  return {
60    always_draw = true,
61    apply_tint = "status",
62    draw_as_light = enable_glow,
63    draw_as_sprite = true,
64    render_layer = "light-effect",
65    animation = animation,
66    north_position = positions.north_south,
67    east_position = positions.east_west,
68    south_position = positions.north_south,
69    west_position = positions.east_west,
70  }
71end
72
73local function add_to_wv(prototype, wv_root)
74  wv_root = wv_root or prototype
75
76  -- Set status colors
77  wv_root.status_colors = status_colors
78
79  -- Get or create working visualisations table
80  local wv = wv_root.working_visualisations
81  if not wv then
82    wv = {}
83    wv_root.working_visualisations = wv
84  end
85
86  -- Add indicator to working visualisations
87  wv[#wv + 1] = build_indicator(prototype)
88end
89
90for _, type in pairs({ "assembling-machine", "furnace", "rocket-silo" }) do
91  for name, crafter in pairs(data.raw[type]) do
92    if not constants.ignored_entities[name] then
93      if crafter.bottleneck_ignore then
94        -- Remove the property to avoid pollution with some debugging features
95        crafter.bottleneck_ignore = nil
96      else
97        add_to_wv(crafter)
98      end
99    end
100  end
101end
102
103if settings.startup["bnl-include-mining-drills"].value then
104  for name, drill in pairs(data.raw["mining-drill"]) do
105    if not constants.ignored_entities[name] then
106      if drill.bottleneck_ignore then
107        -- Remove the property to avoid pollution with some debugging features
108        drill.bottleneck_ignore = nil
109      else
110        drill.status_colors = status_colors
111
112        -- Ensure the drill has a graphics set
113        if not drill.graphics_set then
114          drill.graphics_set = {
115            animation = drill.animations,
116          }
117        end
118
119        add_to_wv(drill, drill.graphics_set)
120
121        if drill.wet_mining_graphics_set then
122          add_to_wv(drill, drill.wet_mining_graphics_set)
123        end
124      end
125    end
126  end
127end