z_mirror/BottleneckLite

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

Caleb Heuerfix: Add indicators to flipped mining drillse4cdc1e

trunk
3.3 KiB124 linesraw
1local flib_bounding_box = require("__flib__.bounding-box")
2
3if not settings.startup["bnl-enable"].value then
4	return
5end
6
7local additional_vertical_offset = 0.1
8
9local horizontal_position = 0.3
10
11local ignored_entities = {
12	-- Mining Drones
13	["mining-depot"] = true,
14	-- Space Exploration
15	["se-core-miner"] = true,
16	["se-rocket-launch-pad-silo"] = true,
17	-- Transport Drones
18	["buffer-depot"] = true,
19	["fluid-depot"] = true,
20	["fuel-depot"] = true,
21	["request-depot"] = true,
22	["supply-depot"] = true,
23}
24
25local sizes = {
26	tiny = 0.075,
27	small = 0.15,
28	medium = 0.2,
29	large = 0.25,
30	huge = 0.5,
31}
32
33--- @type table<string, Color>
34local status_colors = {}
35for name, spec in pairs(settings.startup) do
36	local key = string.match(name, "^bnl%-color%-(.-)$")
37	if key then
38		status_colors[key] = util.premul_color(spec.value --[[@as Color]])
39	end
40end
41
42local enable_glow = settings.startup["bnl-glow"].value --[[@as boolean]]
43local size = sizes[settings.startup["bnl-indicator-size"].value] --[[@as double]]
44
45local function add_indicator(prototype, graphics_set)
46	if not graphics_set then
47		return
48	end
49
50	graphics_set.status_colors = status_colors
51
52	local working_visualisations = graphics_set.working_visualisations
53	if not working_visualisations then
54		working_visualisations = {}
55		graphics_set.working_visualisations = working_visualisations
56	end
57
58	local box = prototype.selection_box or prototype.collision_box
59	if not box then
60		return
61	end
62	box = flib_bounding_box.ensure_explicit(box)
63	local positions = {
64		north_south = {},
65		east_west = {},
66	}
67	for _, pos in pairs(positions) do
68		pos.x = box.left_top.x + (flib_bounding_box.width(box) * horizontal_position)
69		pos.y = box.right_bottom.y - size - additional_vertical_offset
70		box = flib_bounding_box.rotate(box)
71	end
72
73	working_visualisations[#working_visualisations + 1] = {
74		always_draw = true,
75		apply_tint = "status",
76		render_layer = "light-effect",
77		animation = {
78			filename = "__BottleneckLite__/graphics/solid.png",
79			flags = { "icon" },
80			size = 64,
81			scale = size,
82			line_length = 1,
83			frame_count = 1,
84			animation_speed = 1,
85			draw_as_glow = enable_glow,
86		},
87		north_position = positions.north_south,
88		east_position = positions.east_west,
89		south_position = positions.north_south,
90		west_position = positions.east_west,
91	}
92end
93
94for _, type in pairs({ "assembling-machine", "furnace", "rocket-silo" }) do
95	for name, crafter in pairs(data.raw[type]) do
96		if not ignored_entities[name] then
97			if crafter.bottleneck_ignore then
98				crafter.bottleneck_ignore = nil --- @diagnostic disable-line:inject-field
99			else
100				add_indicator(crafter, crafter.graphics_set)
101				add_indicator(crafter, crafter.graphics_set_flipped)
102			end
103		end
104	end
105end
106
107if not settings.startup["bnl-include-mining-drills"].value then
108	return
109end
110
111for name, drill in pairs(data.raw["mining-drill"]) do
112	if not ignored_entities[name] then
113		--- @diagnostic disable-next-line:undefined-field
114		if drill.bottleneck_ignore then
115			drill.bottleneck_ignore = nil --- @diagnostic disable-line:inject-field
116		else
117			--- @diagnostic disable-next-line:undefined-field
118			add_indicator(drill, drill.graphics_set)
119			add_indicator(drill, drill.graphics_set_flipped)
120			add_indicator(drill, drill.wet_mining_graphics_set)
121			add_indicator(drill, drill.wet_mining_graphics_set_flipped)
122		end
123	end
124end