-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite-icons.lua
More file actions
82 lines (72 loc) · 1.97 KB
/
Copy pathwrite-icons.lua
File metadata and controls
82 lines (72 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local iterate_collection = require("iterate-collection")
local state = require("state")
local write_data = require("write-data")
return function()
local sprite_surface = game.create_surface("lab-sprite")
-- Calculate sprite sheet width (height determined by # of loop iterations)
local width = math.max(math.ceil((#state.icons) ^ 0.5), 8)
local x_position = width - 1 + (width / 64)
local x_resolution = (width * 64) + width
local x = 0
local y = 0
local function process_icon(i, icon)
rendering.draw_sprite(
{
sprite = icon.sprite,
x_scale = icon.scale,
y_scale = icon.scale,
target = {x = (x * 2) + (x / 32), y = (y * 2) + (y / 32)},
surface = sprite_surface
}
)
table.insert(
state.data.icons,
{
id = icon.sprite,
x = (x * 64) + x,
y = (y * 64) + y
}
)
x = x + 1
if x == width then
y = y + 1
x = 0
end
end
local function finalize_icons()
if x == 0 then
y = y - 1
end
local rows = y + 1
local y_resolution = (rows * 64) + rows
local y_position = rows - 1 + (rows / 64)
game.take_screenshot(
{
player = state.player,
by_player = state.player,
surface = sprite_surface,
position = {x_position, y_position},
resolution = {x_resolution, y_resolution},
zoom = 1,
quality = 100,
daytime = 1,
path = "icons.png",
show_gui = false,
show_entity_info = false,
anti_alias = false
}
)
script.on_event(
defines.events.on_tick,
function()
game.delete_surface("lab-sprite")
script.on_event(defines.events.on_tick, write_data)
end
)
end
local icon_map = {}
for _, icon in ipairs(state.icons) do
icon_map[icon.sprite] = icon
end
iterate_collection(icon_map, process_icon, finalize_icons)
end