Resolve all Luals warnings

This commit is contained in:
Cooldude2606
2024-11-08 15:40:21 +00:00
parent 4b6872c14c
commit 48f55b0547
14 changed files with 123 additions and 93 deletions

View File

@@ -5,9 +5,9 @@
-- @config Permission-Groups
-- local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event
local Permission_Groups = require("modules.exp_legacy.expcore.permission_groups") --- @dep expcore.permission_groups
local Groups = require("modules.exp_legacy.expcore.permission_groups") --- @dep expcore.permission_groups
Permission_Groups.new_group("Admin")
Groups.new_group("Admin")
:allow_all()
:disallow{
"add_permission_group", -- admin
@@ -24,7 +24,7 @@ Permission_Groups.new_group("Admin")
"set_infinity_pipe_filter",
}
Permission_Groups.new_group("Trusted")
Groups.new_group("Trusted")
:allow_all()
:disallow{
"add_permission_group", -- admin
@@ -42,7 +42,7 @@ Permission_Groups.new_group("Trusted")
"admin_action", -- trusted
}
Permission_Groups.new_group("Standard")
Groups.new_group("Standard")
:allow_all()
:disallow{
"add_permission_group", -- admin
@@ -64,7 +64,7 @@ Permission_Groups.new_group("Standard")
"set_rocket_silo_send_to_orbit_automated_mode",
}
Permission_Groups.new_group("Guest")
Groups.new_group("Guest")
:allow_all()
:disallow{
"add_permission_group", -- admin
@@ -99,7 +99,7 @@ Permission_Groups.new_group("Guest")
"flush_opened_entity_specific_fluid",
}
Permission_Groups.new_group("Restricted")
Groups.new_group("Restricted")
:disallow_all()
:allow("write_to_console")

View File

@@ -210,8 +210,8 @@ Roles.new_role("Veteran", "Vet")
return true
else
local stats = Statistics:get(player, {})
local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
return playTime - afkTime >= hours250 and mapCount >= 25
local playtime, afk_time, map_count = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
return playtime - afk_time >= hours250 and map_count >= 25
end
end)
@@ -259,8 +259,8 @@ Roles.new_role("Regular", "Reg")
return true
else
local stats = Statistics:get(player, {})
local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
return playTime - afkTime >= hours15 and mapCount >= 5
local playtime, afk_time, map_count = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0
return playtime - afk_time >= hours15 and map_count >= 5
end
end)

View File

@@ -76,9 +76,12 @@ function Public.add_compilatron(entity, name)
end
Public.compilatrons[name] = entity
local message =
entity.surface.create_entity
{ name = "compi-speech-bubble", text = messages[name][1], position = { 0, 0 }, source = entity }
local message = entity.surface.create_entity{
name = "compi-speech-bubble",
text = messages[name][1],
position = { 0, 0 },
source = entity,
}
Public.current_messages[name] = { message = message, msg_number = 1 }
end

View File

@@ -56,7 +56,14 @@ if config.decon_area then
local items = e.surface.find_entities_filtered{ area = e.area, force = player.force }
if #items > 250 then
print_to_players(true, { "deconlog.decon", player.name, e.surface.name, pos_to_gps_string(e.area.left_top), pos_to_gps_string(e.area.right_bottom), format_number(#items) })
print_to_players(true, {
"deconlog.decon",
player.name,
e.surface.localised_name,
pos_to_gps_string(e.area.left_top),
pos_to_gps_string(e.area.right_bottom),
format_number(#items, false),
})
end
add_log(get_secs() .. "," .. player.name .. ",decon_area," .. e.surface.name .. "," .. pos_to_string(e.area.left_top) .. "," .. pos_to_string(e.area.right_bottom))

View File

@@ -15,10 +15,10 @@ local directions = {
["SW"] = 0.875,
}
local function Angle(entity)
local function get_direction(entity)
local angle = math.atan2(entity.position.y, entity.position.x) / math.pi
for direction, requiredAngle in pairs(directions) do
if angle < requiredAngle then
for direction, required_angle in pairs(directions) do
if angle < required_angle then
return direction
end
end
@@ -45,14 +45,14 @@ local function station_name_changer(event)
return
end
local boundingBox = entity.bounding_box
local bounding_box = entity.bounding_box
-- expanded box for recourse search:
local bounding2 = { { boundingBox.left_top.x - 100, boundingBox.left_top.y - 100 }, { boundingBox.right_bottom.x + 100, boundingBox.right_bottom.y + 100 } }
local bounding2 = { { bounding_box.left_top.x - 100, bounding_box.left_top.y - 100 }, { bounding_box.right_bottom.x + 100, bounding_box.right_bottom.y + 100 } }
-- gets all resources in bounding_box2:
local recourses = game.surfaces[1].find_entities_filtered{ area = bounding2, type = "resource" }
if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2
local closest_distance
local px, py = boundingBox.left_top.x, boundingBox.left_top.y
local px, py = bounding_box.left_top.x, bounding_box.left_top.y
local recourse_closed
-- Check which recourse is closest
@@ -77,7 +77,7 @@ local function station_name_changer(event)
entity.backer_name = config.station_name:gsub("__icon__", "[img=" .. item_type .. "." .. item_name .. "]")
:gsub("__item_name__", item_name2)
:gsub("__backer_name__", entity.backer_name)
:gsub("__direction__", Angle(entity))
:gsub("__direction__", get_direction(entity))
:gsub("__x__", math.floor(entity.position.x))
:gsub("__y__", math.floor(entity.position.y))
end

View File

@@ -40,7 +40,7 @@ Statistics:on_load(function(player_name, player_statistics)
if new_players[player_name] then
new_players[player_name] = nil
local ctn = player_statistics.MapsPlayed
player_statistics.MapsPlayed = ctn and ctn + 1 or 1
player_statistics["MapsPlayed"] = ctn and ctn + 1 or 1
end
return player_statistics

View File

@@ -20,8 +20,11 @@ local function bonus_gui_pts_needed(player)
total = total + (disp["bonus_display_" .. k .. "_slider"].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost)
end
total = total +
(disp["bonus_display_personal_battery_recharge_slider"].slider_value / config.player_special_bonus["personal_battery_recharge"].cost_scale * config.player_special_bonus["personal_battery_recharge"].cost)
total = total + (
disp["bonus_display_personal_battery_recharge_slider"].slider_value
/ config.player_special_bonus["personal_battery_recharge"].cost_scale
* config.player_special_bonus["personal_battery_recharge"].cost
)
return total
end
@@ -174,15 +177,15 @@ local bonus_gui_control_reset =
disp[s].slider_value = config.player_bonus[v].value
if config.player_bonus[v].is_percentage then
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100) .. " %"
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100, false) .. " %"
else
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value)
disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value, false)
end
end
local slider = disp["bonus_display_personal_battery_recharge_slider"]
slider.slider_value = config.player_special_bonus["personal_battery_recharge"].value
disp[slider.tags.counter].caption = format_number(slider.slider_value)
disp[slider.tags.counter].caption = format_number(slider.slider_value, false)
local r = bonus_gui_pts_needed(player)
element.parent[bonus_gui_control_pts_n_count.name].caption = r
@@ -246,9 +249,9 @@ local bonus_gui_slider =
local value = bonus.value
if bonus.is_percentage then
value = format_number(value * 100) .. " %"
value = format_number(value * 100, false) .. " %"
else
value = format_number(value)
value = format_number(value, false)
end
local slider = parent.add{
@@ -279,9 +282,9 @@ local bonus_gui_slider =
end)
:on_value_changed(function(player, element, _event)
if element.tags.is_percentage then
element.parent[element.tags.counter].caption = format_number(element.slider_value * 100) .. " %"
element.parent[element.tags.counter].caption = format_number(element.slider_value * 100, false) .. " %"
else
element.parent[element.tags.counter].caption = format_number(element.slider_value)
element.parent[element.tags.counter].caption = format_number(element.slider_value, false)
end
local r = bonus_gui_pts_needed(player)

View File

@@ -10,10 +10,10 @@ local rawset = rawset
local Public = {}
local luaObject = { "{", nil, ", name = '", nil, "'}" }
local luaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" }
local luaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" }
local luaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
local LuaObject = { "{", nil, ", name = '", nil, "'}" }
local LuaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" }
local LuaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" }
local LuaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
local function get(obj, prop)
return obj[prop]
@@ -59,25 +59,25 @@ local function inspect_process(item)
end
if obj_type == "LuaPlayer" then
luaPlayer[2] = item.name or "nil"
luaPlayer[4] = item.index or "nil"
LuaPlayer[2] = item.name or "nil"
LuaPlayer[4] = item.index or "nil"
return concat(luaPlayer)
return concat(LuaPlayer)
elseif obj_type == "LuaEntity" then
luaEntity[2] = item.name or "nil"
luaEntity[4] = item.unit_number or "nil"
LuaEntity[2] = item.name or "nil"
LuaEntity[4] = item.unit_number or "nil"
return concat(luaEntity)
return concat(LuaEntity)
elseif obj_type == "LuaGuiElement" then
local name = item.name
luaGuiElement[2] = gui_names and gui_names[name] or name or "nil"
LuaGuiElement[2] = gui_names and gui_names[name] or name or "nil"
return concat(luaGuiElement)
return concat(LuaGuiElement)
else
luaObject[2] = obj_type
luaObject[4] = get_name_safe(item)
LuaObject[2] = obj_type
LuaObject[4] = get_name_safe(item)
return concat(luaObject)
return concat(LuaObject)
end
end

View File

@@ -19,7 +19,7 @@ local label_width = {
local short_time_format = ExpUtil.format_time_factory_locale{ format = "short", coefficient = 3600, hours = true, minutes = true }
local function format_number_n(n)
return format_number(math.floor(n)) .. string.format("%.2f", n % 1):sub(2)
return format_number(math.floor(n), false) .. string.format("%.2f", n % 1):sub(2)
end
local PlayerStats = PlayerData.Statistics
@@ -96,7 +96,7 @@ local pd_data_set =
for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do
local child = PlayerData.Statistics[stat_name]
local metadata = child.metadata
local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0)
local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0, false)
label(disp, label_width["name"], metadata.name or { "exp-statistics." .. stat_name }, metadata.tooltip or { "exp-statistics." .. stat_name .. "-tooltip" })
label(disp, label_width["count"], { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name)
end
@@ -119,7 +119,7 @@ local function pd_update(table, player_name)
elseif metadata.stringify then
value = metadata.stringify(value or 0)
else
value = format_number(value or 0)
value = format_number(value or 0, false)
end
table[stat_name].caption = { "readme.data-format", value, metadata.unit or "" }
end

View File

@@ -372,7 +372,7 @@ define_tab({ "readme.data-tab" }, { "readme.data-tooltip" },
if metadata.stringify then
value = metadata.stringify(value)
else
value = format_number(value or 0)
value = format_number(value or 0, false)
end
Gui.centered_label(statistics, 150, metadata.name or { "exp-statistics." .. name }, metadata.tooltip or { "exp-statistics." .. name .. "-tooltip" })
Gui.centered_label(statistics, 130, { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. name .. "-tooltip" })

View File

@@ -144,12 +144,11 @@ local subfooter_frame =
style = "subfooter_frame",
}
end
):style
{
padding = 5,
use_header_filler = false,
horizontally_stretchable = true,
}
):style{
padding = 5,
use_header_filler = false,
horizontally_stretchable = true,
}
--- Label element preset
@@ -351,22 +350,21 @@ local task_message_textfield =
name = Gui.unique_static_name,
type = "text-box",
text = "",
}:style
{
maximal_width = 268,
minimal_height = 100,
horizontally_stretchable = true,
}
}:style{
maximal_width = 268,
minimal_height = 100,
horizontally_stretchable = true,
}
:on_text_changed(
function(player, element, _)
local isEditing = PlayerIsEditing:get(player)
local isCreating = PlayerIsCreating:get(player)
local is_editing = PlayerIsEditing:get(player)
local is_creating = PlayerIsCreating:get(player)
local valid = string.len(element.text) > 5
if isCreating then
if is_creating then
element.parent.actions[task_create_confirm_button.name].enabled = valid
elseif isEditing then
elseif is_editing then
element.parent.actions[task_edit_confirm_button.name].enabled = valid
end
end
@@ -676,8 +674,8 @@ PlayerSelected:on_update(
local task_list_element = frame.container.scroll.task_list
local view_flow = frame.container.view
local edit_flow = frame.container.edit
local isEditing = PlayerIsEditing:get(player)
local isCreating = PlayerIsCreating:get(player)
local is_editing = PlayerIsEditing:get(player)
local is_creating = PlayerIsCreating:get(player)
-- If the selection has an previous state re-enable the button list element
if prev_state then
@@ -692,12 +690,12 @@ PlayerSelected:on_update(
update_task_view_footer(player, curr_state)
-- If a player is creating then remove the creation dialogue
if isCreating then
if is_creating then
PlayerIsCreating:set(player, false)
end
-- Depending on if the player is currently editing change the current task edit footer to the current task
if isEditing then
if is_editing then
update_task_edit_footer(player, curr_state)
Tasks.set_editing(prev_state, player.name, nil)
Tasks.set_editing(curr_state, player.name, true)
@@ -756,8 +754,8 @@ local function role_update_event(event)
local has_permission = check_player_permissions(player)
local add_new_task_element = container.header.alignment[add_new_task.name]
add_new_task_element.visible = has_permission
local isCreating = PlayerIsCreating:get(player)
if isCreating and not has_permission then
local is_creating = PlayerIsCreating:get(player)
if is_creating and not has_permission then
PlayerIsCreating:set(player, false)
end
end

View File

@@ -487,14 +487,14 @@ Event.on_nth_tick(config.update_tick_gui, function(_)
local vlayer_display = {
[vlayer_gui_display_item_solar_count.name] = {
val = (items_alloc["solar-panel"] / math.max(items["solar-panel"], 1)),
cap = format_number(items_alloc["solar-panel"]) .. " / " .. format_number(items["solar-panel"]),
cap = format_number(items_alloc["solar-panel"], false) .. " / " .. format_number(items["solar-panel"], false),
},
[vlayer_gui_display_item_accumulator_count.name] = {
val = (items_alloc["accumulator"] / math.max(items["accumulator"], 1)),
cap = format_number(items_alloc["accumulator"]) .. " / " .. format_number(items["accumulator"]),
cap = format_number(items_alloc["accumulator"], false) .. " / " .. format_number(items["accumulator"], false),
},
[vlayer_gui_display_signal_remaining_surface_area_count.name] = {
cap = format_number(stats.remaining_surface_area),
cap = format_number(stats.remaining_surface_area, false),
},
[vlayer_gui_display_signal_sustained_count.name] = {
cap = format_energy(stats.energy_sustained, "W"),