Skip to content

Commit 2e20738

Browse files
update luals, again. side dish of minor refactoring (#153)
* update luals, again. side dish of minor refactoring
1 parent c4e70b4 commit 2e20738

5 files changed

Lines changed: 45 additions & 39 deletions

File tree

lib/autorecipes.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ local function modify_recipe_tables(item, items_table, previous_item_names, resu
208208
end
209209
end
210210

211-
--handles all adjustments for each ingredient and result changes in autorecipe
211+
---handles all adjustments for each ingredient and result changes in autorecipe
212+
---@param ingredients [data.IngredientPrototype]
213+
---@param results [data.ProductPrototype]
214+
---@param previous_ingredients [data.IngredientPrototype]
215+
---@param previous_results [data.ProductPrototype]
216+
---@return [data.IngredientPrototype], [data.ProductPrototype]
212217
local function recipe_item_builder(ingredients, results, previous_ingredients, previous_results)
213218
local ing_table = table.deepcopy(previous_ingredients)
214219
local result_table = table.deepcopy(previous_results)
@@ -235,7 +240,7 @@ local function recipe_item_builder(ingredients, results, previous_ingredients, p
235240
end
236241

237242
---Provides an interface to quickly build tiered recipes. See recipes-auto-brains.lua for an example
238-
---@param params table
243+
---@param params {name:RecipeID,category:RecipeCategoryID,subgroup:data.ItemSubGroupID,order:data.Order,main_product?:string,crafting_speed:double,allowed_module_categories:[data.ModuleCategoryID],number_icons:boolean,mats:[{name?:string,ingredients?:[data.IngredientPrototype],results?:[data.ProductPrototype],crafting_speed?:double,tech?:TechnologyID,icon?:data.FileName,icon_size?:integer,icons?:[data.IconData],main_product?:string}]}
239244
py.autorecipes = function(params)
240245
local previous_ingredients = {}
241246
local previous_results = {}

lib/color.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
py.tints = {
2+
[0] = {r = 0.5, g = 0.5, b = 0.5, a = 1.0},
23
{r = 1.0, g = 1.0, b = 0.0, a = 1.0},
34
{r = 1.0, g = 0.0, b = 0.0, a = 1.0},
45
{r = 0.223, g = 0.490, b = 0.858, a = 1.0},
56
{r = 1.0, g = 0.0, b = 1.0, a = 1.0}
67
}
78

8-
py.tints[0] = {r = 0.5, g = 0.5, b = 0.5, a = 1.0}
9-
109
py.light_tints = {}
1110
for i, tint in pairs(py.tints) do
1211
py.light_tints[i] = {}

lib/control-stage.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ require "compound-entities"
1010
---Draws a red error icon at the entity's position.
1111
---@param entity LuaEntity
1212
---@param sprite string
13-
---@param time_to_live integer
14-
---@param blink_interval integer?
13+
---@param time_to_live integer? default 60 ticks
14+
---@param blink_interval integer? default 30 ticks
15+
---@return LuaRenderObject
1516
py.draw_error_sprite = function(entity, sprite, time_to_live, blink_interval)
1617
return rendering.draw_sprite {
1718
sprite = sprite,
@@ -42,7 +43,7 @@ end
4243

4344
---Randomizes a position by a factor.
4445
---@param position MapPosition
45-
---@param factor number?
46+
---@param factor number? default 1
4647
---@return MapPosition
4748
py.randomize_position = function(position, factor)
4849
local x = position.x or position[1]
@@ -189,6 +190,7 @@ local si_prefixes = {
189190
---formats a number into the amount of energy. Requires 'W' or 'J' as the second parameter
190191
---@param energy number
191192
---@param watts_or_joules string
193+
---@return LocalisedString
192194
py.format_energy = function(energy, watts_or_joules)
193195
if watts_or_joules == "W" then
194196
watts_or_joules = "si-unit-symbol-watt"

lib/data-stage.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ end
168168

169169
---Returns a composite icon with a base icon and up to 4 child icons.
170170
---The child icons are placed in the corners of the base icon, and can be tinted with a shadow color.
171-
---@param base_prototype_string string
172-
---@param child_top_left string?
173-
---@param child_top_right string?
174-
---@param child_bottom_left string?
175-
---@param child_bottom_right string?
176-
---@param shadow_alpha number?
177-
---@param shadow_scale number?
178-
---@param child_scale number?
179-
---@param shift number?
171+
---@param base_prototype_string data.FileName
172+
---@param child_top_left data.FileName?
173+
---@param child_top_right data.FileName?
174+
---@param child_bottom_left data.FileName?
175+
---@param child_bottom_right data.FileName?
176+
---@param shadow_alpha number? default 0.6
177+
---@param shadow_scale number? default 0.6
178+
---@param child_scale number? default 0.5
179+
---@param shift number? default 10
180+
---@return [data.IconData]
180181
function py.composite_icon(base_prototype_string, child_top_left, child_top_right, child_bottom_left, child_bottom_right,
181182
shadow_alpha, shadow_scale, child_scale, shift)
182183
shadow_alpha = shadow_alpha or 0.6
@@ -359,6 +360,7 @@ end
359360
---adds a small icon to the top right corner of a recipe
360361
---@param recipe data.RecipePrototype
361362
---@param corner table
363+
---@return [data.IconData]
362364
py.add_corner_icon_to_recipe = function(recipe, corner)
363365
local icon, icon_size, icons
364366
local result
@@ -427,9 +429,8 @@ end
427429
---Retruns a version of graphics_set with the following properties:
428430
---The machine will follow a binary finite state machine (bfsm) to determine the current active animation.
429431
---Example (sinter machine): https://github.com/pyanodon/pybugreports/issues/588
430-
---@param states data.VisualState[]
431-
---@param raw_working_visualisations data.WorkingVisualisation[]
432-
---@param shadow data.Animation?
432+
---@param params {states:[data.VisualState], working_visualisations:[data.WorkingVisualisation], shadow:data.Animation?}
433+
---@return data.WorkingVisualisations
433434
py.finite_state_machine_working_visualisations = function(params)
434435
local states = params.states
435436

@@ -500,6 +501,7 @@ end
500501

501502
---Returns a flipped animation
502503
---@param animation4way data.Animation4Way
504+
---@return data.Animation4Way
503505
py.flip_4way_animation = function(animation4way)
504506
local inverse = {
505507
north = "south",

lib/pipe-connections.lua

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---Define pipe connection pipe pictures by coping from an existing entity in the base mod.
22
---@param pictures string
3-
---@param shift_north table?
4-
---@param shift_south table?
5-
---@param shift_west table?
6-
---@param shift_east table?
7-
---@param replacements table?
8-
---@return table
3+
---@param shift_north Vector?
4+
---@param shift_south Vector?
5+
---@param shift_west Vector?
6+
---@param shift_east Vector?
7+
---@param replacements {north:data.Sprite,east:data.Sprite,south:data.Sprite,west:data.Sprite}?
8+
---@return data.Sprite4Way
99
py.pipe_pictures = function(pictures, shift_north, shift_south, shift_west, shift_east, replacements)
1010
local new_pictures = {
1111
north = shift_north and
@@ -63,14 +63,14 @@ end
6363
---@param s boolean?
6464
---@param w boolean?
6565
---@param e boolean?
66-
---@return table
66+
---@return data.Sprite4Way
6767
py.pipe_covers = function(n, s, w, e)
6868
if (n == nil and s == nil and w == nil and e == nil) then
6969
n, s, e, w = true, true, true, true
7070
end
7171

72-
n =
73-
n and {
72+
return {
73+
north = n and {
7474
layers = {
7575
{
7676
filename = "__base__/graphics/entity/pipe-covers/pipe-cover-north.png",
@@ -88,9 +88,8 @@ py.pipe_covers = function(n, s, w, e)
8888
draw_as_shadow = true
8989
}
9090
}
91-
} or py.empty_image()
92-
e =
93-
e and {
91+
} or py.empty_image(),
92+
east = e and {
9493
layers = {
9594
{
9695
filename = "__base__/graphics/entity/pipe-covers/pipe-cover-east.png",
@@ -108,9 +107,8 @@ py.pipe_covers = function(n, s, w, e)
108107
draw_as_shadow = true
109108
}
110109
}
111-
} or py.empty_image()
112-
s =
113-
s and {
110+
} or py.empty_image(),
111+
south = s and {
114112
layers = {
115113
{
116114
filename = "__base__/graphics/entity/pipe-covers/pipe-cover-south.png",
@@ -128,9 +126,8 @@ py.pipe_covers = function(n, s, w, e)
128126
draw_as_shadow = true
129127
}
130128
}
131-
} or py.empty_image()
132-
w =
133-
w and {
129+
} or py.empty_image(),
130+
west = w and {
134131
layers = {
135132
{
136133
filename = "__base__/graphics/entity/pipe-covers/pipe-cover-west.png",
@@ -149,13 +146,13 @@ py.pipe_covers = function(n, s, w, e)
149146
}
150147
}
151148
} or py.empty_image()
152-
153-
return {north = n, south = s, east = e, west = w}
149+
}
154150
end
155151

156152
---Define nice looking pipe pictures based on the space age electromagnetic plant.
157153
---These do not come with pipe covers! However there is a frozen variant.
158154
---See seaweed-crop.lua in alien life for an example implementation.
155+
---@return data.Sprite4Way
159156
py.sexy_pipe_pictures = function()
160157
local function by_direction(pipe_direction)
161158
return {
@@ -184,6 +181,7 @@ py.sexy_pipe_pictures = function()
184181
end
185182

186183
---Define nice looking pipe frozen pictures based on the space age electromagnetic plant.
184+
---@return data.Sprite4Way
187185
py.sexy_pipe_pictures_frozen = function()
188186
local function by_direction(pipe_direction)
189187
return {

0 commit comments

Comments
 (0)