From c367e806413c6dc501370ca2777283ab95513afb Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sun, 6 Apr 2025 23:33:56 +0900 Subject: [PATCH 1/6] Improve Bonus Gui (#379) * Update bonus.lua * Update bonus.lua * Update bonus.lua * Update bonus.lua * Update bonus.lua * Update bonus.lua * Update exp_legacy/module/modules/gui/bonus.lua Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> * Recalculate limit on role change --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> --- exp_legacy/module/config/bonus.lua | 2 + exp_legacy/module/modules/gui/bonus.lua | 172 ++++++++---------------- 2 files changed, 59 insertions(+), 115 deletions(-) diff --git a/exp_legacy/module/config/bonus.lua b/exp_legacy/module/config/bonus.lua index 7c9289a4..88516939 100644 --- a/exp_legacy/module/config/bonus.lua +++ b/exp_legacy/module/config/bonus.lua @@ -18,6 +18,8 @@ return { ]] pts = { base = 260, + increase_percentage_per_role_level = 0.03, + role_name = "Member", }, gui_display_width = { half = 150, diff --git a/exp_legacy/module/modules/gui/bonus.lua b/exp_legacy/module/modules/gui/bonus.lua index d75a2396..c57b4a6b 100644 --- a/exp_legacy/module/modules/gui/bonus.lua +++ b/exp_legacy/module/modules/gui/bonus.lua @@ -9,6 +9,7 @@ local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles local config = require("modules.exp_legacy.config.bonus") --- @dep config.bonus local vlayer = require("modules.exp_legacy.modules.control.vlayer") local format_number = require("util").format_number --- @dep util + local bonus_container --- @param player LuaPlayer @@ -33,8 +34,9 @@ local function bonus_gui_pts_needed(player, container) end --- @param player LuaPlayer -local function apply_bonus(player) - if not Roles.player_allowed(player, "gui/bonus") then +--- @param reset boolean? +local function apply_bonus(player, reset) + if reset or not Roles.player_allowed(player, "gui/bonus") then for k, v in pairs(config.player_bonus) do player[k] = 0 @@ -101,9 +103,17 @@ local function apply_periodic_bonus(player) end end +local bonus_data_score_limit = {} +local function get_bonus_score_limit(player) + if not bonus_data_score_limit[player] then + bonus_data_score_limit[player] = math.floor(config.pts.base * (1 + config.pts.increase_percentage_per_role_level * (Roles.get_role_by_name(config.pts.role_name).index - Roles.get_player_highest_role(player).index))) + end + return bonus_data_score_limit[player] +end + --- Control label for the bonus points available --- @element bonus_gui_control_pts_a -local bonus_gui_control_pts_a = Gui.element("bonus_gui_control_pts_a") +-- @element bonus_gui_control_pts +local bonus_gui_control_pts = Gui.element("bonus_gui_control_pts") :draw{ type = "label", name = Gui.property_from_name, @@ -113,58 +123,17 @@ local bonus_gui_control_pts_a = Gui.element("bonus_gui_control_pts_a") width = config.gui_display_width["half"], } -local bonus_gui_control_pts_a_count = Gui.element("bonus_gui_control_pts_a_count") +local bonus_gui_control_pts_count = Gui.element("bonus_gui_control_pts_count") :draw{ - type = "label", + type = "progressbar", name = Gui.property_from_name, - caption = config.pts.base, - style = "heading_2_label", - }:style{ - width = config.gui_display_width["half"], - } - ---- Control label for the bonus points needed --- @element bonus_gui_control_pts_n -local bonus_gui_control_pts_n = Gui.element("bonus_gui_control_pts_n") - :draw{ - type = "label", - name = Gui.property_from_name, - caption = { "bonus.control-pts-n" }, - style = "heading_2_label", - }:style{ - width = config.gui_display_width["half"], - } - -local bonus_gui_control_pts_n_count = Gui.element("bonus_gui_control_pts_n_count") - :draw{ - type = "label", - name = Gui.property_from_name, - caption = "0", - style = "heading_2_label", - }:style{ - width = config.gui_display_width["half"], - } - ---- Control label for the bonus points remaining --- @element bonus_gui_control_pts_r -local bonus_gui_control_pts_r = Gui.element("bonus_gui_control_pts_r") - :draw{ - type = "label", - name = Gui.property_from_name, - caption = { "bonus.control-pts-r" }, - style = "heading_2_label", - }:style{ - width = config.gui_display_width["half"], - } - -local bonus_gui_control_pts_r_count = Gui.element("bonus_gui_control_pts_r_count") - :draw{ - type = "label", - name = Gui.property_from_name, - caption = "0", - style = "heading_2_label", + caption = "0 / 0", + value = 0, + style = "electric_satisfaction_statistics_progressbar", }:style{ width = config.gui_display_width["half"], + font = "heading-2", + color = { 1, 0, 0 }, } --- A button used for pts calculations @@ -183,21 +152,17 @@ local bonus_gui_control_reset = Gui.element("bonus_gui_control_reset") for k, v in pairs(config.conversion) do local s = "bonus_display_" .. k .. "_slider" 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, false) .. " %" - else - disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value, false) - end + disp[disp[s].tags.counter].caption = (config.player_bonus[v].is_percentage and (format_number(disp[s].slider_value * 100, false) .. " %")) or format_number(disp[s].slider_value, false) 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, false) - local r = bonus_gui_pts_needed(player) - element.parent[bonus_gui_control_pts_n_count.name].caption = r - element.parent[bonus_gui_control_pts_r_count.name].caption = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - r + local n = bonus_gui_pts_needed(player) + local limit = get_bonus_score_limit(player) + element.parent[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit + element.parent[bonus_gui_control_pts_count.name].value = n / limit end) --- A button used for pts apply @@ -211,11 +176,11 @@ local bonus_gui_control_apply = Gui.element("bonus_gui_control_apply") width = config.gui_display_width["half"], }:on_click(function(def, player, element) local n = bonus_gui_pts_needed(player) - element.parent[bonus_gui_control_pts_n_count.name].caption = n - local r = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - n - element.parent[bonus_gui_control_pts_r_count.name].caption = r + local limit = get_bonus_score_limit(player) + element.parent[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit + element.parent[bonus_gui_control_pts_count.name].value = n / limit - if r >= 0 then + if n <= limit then apply_bonus(player) end end) @@ -227,15 +192,8 @@ local bonus_control_set = Gui.element("bonus_control_set") local bonus_set = parent.add{ type = "flow", direction = "vertical", name = name } local disp = Gui.elements.scroll_table(bonus_set, config.gui_display_width["half"] * 2, 2, "disp") - bonus_gui_control_pts_a(disp) - bonus_gui_control_pts_a_count(disp) - - bonus_gui_control_pts_n(disp) - bonus_gui_control_pts_n_count(disp) - - bonus_gui_control_pts_r(disp) - bonus_gui_control_pts_r_count(disp) - + bonus_gui_control_pts(disp) + bonus_gui_control_pts_count(disp) bonus_gui_control_reset(disp) bonus_gui_control_apply(disp) @@ -254,14 +212,6 @@ local bonus_gui_slider = Gui.element("bonus_gui_slider") } label.style.width = config.gui_display_width["label"] - local value = bonus.value - - if bonus.is_percentage then - value = format_number(value * 100, false) .. " %" - else - value = format_number(value, false) - end - local slider = parent.add{ type = "slider", name = name .. "_slider", @@ -281,7 +231,7 @@ local bonus_gui_slider = Gui.element("bonus_gui_slider") local count = parent.add{ type = "label", name = name .. "_count", - caption = value, + caption = (bonus.is_percentage and format_number(bonus.value * 100, false) .. " %") or format_number(bonus.value, false), style = "heading_2_label", } count.style.width = config.gui_display_width["count"] @@ -289,17 +239,13 @@ local bonus_gui_slider = Gui.element("bonus_gui_slider") return slider end) :on_value_changed(function(def, player, element) - if element.tags.is_percentage then - 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, false) - end - - local r = bonus_gui_pts_needed(player) + element.parent[element.tags.counter].caption = (element.tags.is_percentage and format_number(element.slider_value * 100, false) .. " %") or format_number(element.slider_value, false) local container = Gui.get_left_element(bonus_container, player) local disp = container.frame["bonus_st_1"].disp.table - disp[bonus_gui_control_pts_n_count.name].caption = r - disp[bonus_gui_control_pts_r_count.name].caption = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - r + local n = bonus_gui_pts_needed(player) + local limit = get_bonus_score_limit(player) + disp[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit + disp[bonus_gui_control_pts_count.name].value = n / limit end) --- A vertical flow containing all the bonus data @@ -313,8 +259,7 @@ local bonus_data_set = Gui.element("bonus_data_set") bonus_gui_slider(disp, "bonus_display_" .. k, { "bonus.display-" .. k }, { "bonus.display-" .. k .. "-tooltip" }, config.player_bonus[v]) end - bonus_gui_slider(disp, "bonus_display_personal_battery_recharge", { "bonus.display-personal-battery-recharge" }, { "bonus.display-personal-battery-recharge-tooltip" }, - config.player_special_bonus["personal_battery_recharge"]) + bonus_gui_slider(disp, "bonus_display_personal_battery_recharge", { "bonus.display-personal-battery-recharge" }, { "bonus.display-personal-battery-recharge-tooltip" }, config.player_special_bonus["personal_battery_recharge"]) return bonus_set end) @@ -331,9 +276,9 @@ bonus_container = Gui.element("bonus_container") local disp = container["bonus_st_1"].disp.table local n = bonus_gui_pts_needed(player, container.parent) - disp[bonus_gui_control_pts_n_count.name].caption = n - local r = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - n - disp[bonus_gui_control_pts_r_count.name].caption = r + local limit = get_bonus_score_limit(player) + disp[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit + disp[bonus_gui_control_pts_count.name].value = n / limit return container.parent end) @@ -364,33 +309,30 @@ Event.add(defines.events.on_player_created, function(event) end end) -Event.add(Roles.events.on_role_assigned, function(event) - apply_bonus(game.players[event.player_index]) -end) - -Event.add(Roles.events.on_role_unassigned, function(event) - apply_bonus(game.players[event.player_index]) -end) - ---- When a player respawns re-apply bonus -Event.add(defines.events.on_player_respawned, function(event) +local function recalculate_bonus(event) local player = game.players[event.player_index] + if event.name == Roles.events.on_role_assigned or event.name == Roles.events.on_role_unassigned then + -- If the player's roles changed then we need to recalculate their limit + bonus_data_score_limit[player] = nil + end + local container = Gui.get_left_element(bonus_container, player) local disp = container.frame["bonus_st_1"].disp.table local n = bonus_gui_pts_needed(player) - disp[bonus_gui_control_pts_n_count.name].caption = n - local r = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - n - disp[bonus_gui_control_pts_r_count.name].caption = r + local limit = get_bonus_score_limit(player) + disp[bonus_gui_control_pts_count.name].caption = n .. " / " .. limit + disp[bonus_gui_control_pts_count.name].value = n / limit - if r >= 0 then - apply_bonus(player) - end -end) + apply_bonus(player, n > limit) +end + +Event.add(Roles.events.on_role_assigned, recalculate_bonus) +Event.add(Roles.events.on_role_unassigned, recalculate_bonus) +Event.add(defines.events.on_player_respawned, recalculate_bonus) --- When a player dies allow them to have instant respawn Event.add(defines.events.on_player_died, function(event) local player = game.players[event.player_index] - if Roles.player_has_flag(player, "instant-respawn") then player.ticks_to_respawn = 120 end From e200533c6cfa9422cbc073c9bdcebf6047f6119f Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sun, 6 Apr 2025 23:36:42 +0900 Subject: [PATCH 2/6] GUI Production (#380) * Update production.lua * Update production.lua * Update production.lua * Update production.lua * Update production.lua * Update production.lua * Update production.lua * Update production.lua * Fix table size * Update gui.cfg * Update gui.cfg --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> --- exp_legacy/module/locale/en/gui.cfg | 3 +- exp_legacy/module/locale/zh-CN/gui.cfg | 3 +- exp_legacy/module/locale/zh-TW/gui.cfg | 3 +- exp_legacy/module/modules/gui/production.lua | 108 ++++++++----------- 4 files changed, 52 insertions(+), 65 deletions(-) diff --git a/exp_legacy/module/locale/en/gui.cfg b/exp_legacy/module/locale/en/gui.cfg index e471bcc0..074a05a4 100644 --- a/exp_legacy/module/locale/en/gui.cfg +++ b/exp_legacy/module/locale/en/gui.cfg @@ -310,7 +310,8 @@ cursor-none=You need to hold the blueprint in cursor main-tooltip=Production GUI label-prod=Production label-con=Consumption -label-bal=Balance (sec) +label-bal=Balance +tooltip-per-second=Items per second [surveillance] main-tooltip=Surveillance GUI diff --git a/exp_legacy/module/locale/zh-CN/gui.cfg b/exp_legacy/module/locale/zh-CN/gui.cfg index 09aa6dda..47c99c4f 100644 --- a/exp_legacy/module/locale/zh-CN/gui.cfg +++ b/exp_legacy/module/locale/zh-CN/gui.cfg @@ -310,7 +310,8 @@ cursor-none=您需要將藍圖保持在遊標處 main-tooltip=製造介面 label-prod=製造 label-con=消耗 -label-bal=淨值 (秒) +label-bal=淨值 +tooltip-per-second=物品每秒 [surveillance] main-tooltip=監控介面 diff --git a/exp_legacy/module/locale/zh-TW/gui.cfg b/exp_legacy/module/locale/zh-TW/gui.cfg index 06eec4bd..9429cfb2 100644 --- a/exp_legacy/module/locale/zh-TW/gui.cfg +++ b/exp_legacy/module/locale/zh-TW/gui.cfg @@ -310,7 +310,8 @@ cursor-none=您需要將藍圖保持在遊標處 main-tooltip=製造介面 label-prod=製造 label-con=消耗 -label-bal=淨值 (秒) +label-bal=淨值 +tooltip-per-second=物品每秒 [surveillance] main-tooltip=監控介面 diff --git a/exp_legacy/module/modules/gui/production.lua b/exp_legacy/module/modules/gui/production.lua index 8da29140..30d761dc 100644 --- a/exp_legacy/module/modules/gui/production.lua +++ b/exp_legacy/module/modules/gui/production.lua @@ -16,21 +16,33 @@ local precision = { } local font_color = { - -- positive - [1] = { r = 0.3, g = 1, b = 0.3 }, - -- negative - [2] = { r = 1, g = 0.3, b = 0.3 }, + ["positive"] = { r = 0.3, g = 1, b = 0.3 }, + ["negative"] = { r = 1, g = 0.3, b = 0.3 }, } -local function format_n(n) - local _i, _j, m, i, f = tostring(n):find("([-]?)(%d+)([.]?%d*)") - i = i:reverse():gsub("(%d%d%d)", "%1,") - - if f ~= "" then - return m .. i:reverse():gsub("^,", "") .. f - else - return m .. i:reverse():gsub("^,", "") .. ".0" +local function format_n(amount) + if math.abs(amount) < 0.009 then + return "0.00" end + local suffix = "" + local suffix_list = { + [" G"] = 1e9, + [" M"] = 1e6, + [" k"] = 1e3 + } + local scale = 1 + for letter, limit in pairs(suffix_list) do + if math.abs(amount) >= limit then + scale = limit + suffix = letter + break + end + end + local formatted = string.format("%.2f%s", amount / scale, suffix) + -- Split into integer and fractional parts + local integer_part, fractional_part = formatted:match("^(%-?%d+)%.(%d+)(.*)$") + -- Add commas to integer part + return string.format("%s.%s%s", (integer_part or formatted):reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", ""):gsub("-,", "-"), fractional_part or "00", suffix) end --- Display group @@ -58,35 +70,15 @@ local production_data_group = Gui.element("production_data_group") item.style.width = 32 end - local data_1 = parent.add{ - type = "label", - name = "production_" .. i .. "_1", - caption = "0.0", - style = "heading_2_label", - } - data_1.style.width = 90 - data_1.style.horizontal_align = "right" - data_1.style.font_color = font_color[1] - - local data_2 = parent.add{ - type = "label", - name = "production_" .. i .. "_2", - caption = "0.0", - style = "heading_2_label", - } - data_2.style.width = 90 - data_2.style.horizontal_align = "right" - data_2.style.font_color = font_color[2] - - local data_3 = parent.add{ - type = "label", - name = "production_" .. i .. "_3", - caption = "0.0", - style = "heading_2_label", - } - data_3.style.width = 90 - data_3.style.horizontal_align = "right" - data_3.style.font_color = font_color[1] + for j = 1, 3 do + local data = parent.add{ + type = "label", + name = "production_" .. i .. "_" .. j, + caption = "0.00", + style = "heading_2_label", + } + data.style.font_color = font_color["positive"] + end return item end) @@ -96,27 +88,27 @@ local production_data_group = Gui.element("production_data_group") local production_data_set = Gui.element("production_data_set") :draw(function(_, parent, name) local production_set = parent.add{ type = "flow", direction = "vertical", name = name } - local disp = Gui.elements.scroll_table(production_set, 350, 4, "disp") - + local disp = Gui.elements.scroll_table(production_set, 320, 4, "disp") + for i = 2, 4 do + disp.style.column_alignments[i] = "right" + end production_data_group(disp, 0) - disp["production_0_1"].caption = { "production.label-prod" } + disp["production_0_1"].tooltip = { "production.tooltip-per-second" } disp["production_0_2"].caption = { "production.label-con" } + disp["production_0_2"].tooltip = { "production.tooltip-per-second" } disp["production_0_3"].caption = { "production.label-bal" } - + disp["production_0_3"].tooltip = { "production.tooltip-per-second" } for i = 1, 8 do production_data_group(disp, i) end - return production_set end) production_container = Gui.element("production_container") :draw(function(def, parent) - local container = Gui.elements.container(parent, 350) - + local container = Gui.elements.container(parent, 320) production_data_set(container, "production_st") - return container.parent end) @@ -138,30 +130,22 @@ Event.on_nth_tick(60, function() local stat = player.force.get_item_production_statistics(player.surface) -- Allow remote view local precision_value = precision[container.frame["production_st"].disp.table["production_0_e"].selected_index] local table = container.frame["production_st"].disp.table - for i = 1, 8 do local production_prefix = "production_" .. i local item = table[production_prefix .. "_e"].elem_value --[[ @as string ]] - if item then local add = math.floor(stat.get_flow_count{ name = item, category = "input", precision_index = precision_value, count = false } / 6) / 10 local minus = math.floor(stat.get_flow_count{ name = item, category = "output", precision_index = precision_value, count = false } / 6) / 10 local sum = add - minus - table[production_prefix .. "_1"].caption = format_n(add) table[production_prefix .. "_2"].caption = format_n(minus) table[production_prefix .. "_3"].caption = format_n(sum) - - if sum < 0 then - table[production_prefix .. "_3"].style.font_color = font_color[2] - else - table[production_prefix .. "_3"].style.font_color = font_color[1] - end + table[production_prefix .. "_3"].style.font_color = (sum < 0 and font_color["negative"]) or font_color["positive"] else - table[production_prefix .. "_1"].caption = "0.0" - table[production_prefix .. "_2"].caption = "0.0" - table[production_prefix .. "_3"].caption = "0.0" - table[production_prefix .. "_3"].style.font_color = font_color[1] + table[production_prefix .. "_1"].caption = "0.00" + table[production_prefix .. "_2"].caption = "0.00" + table[production_prefix .. "_3"].caption = "0.00" + table[production_prefix .. "_3"].style.font_color = font_color["positive"] end end end From d5b889146b61415f9a1308376834dad2d30b8a70 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sun, 6 Apr 2025 23:37:53 +0900 Subject: [PATCH 3/6] Add description to vlayer combinator (#382) * Update vlayer.lua * Update vlayer.lua * Update vlayer.lua * Use rich text for description --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> --- exp_legacy/module/modules/control/vlayer.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/exp_legacy/module/modules/control/vlayer.lua b/exp_legacy/module/modules/control/vlayer.lua index 0bdb9ba3..0820c09e 100644 --- a/exp_legacy/module/modules/control/vlayer.lua +++ b/exp_legacy/module/modules/control/vlayer.lua @@ -333,6 +333,7 @@ end -- @treturn LuaEntity The entity that was created for the interface function vlayer.create_input_interface(surface, position, circuit, last_user) local interface = surface.create_entity{ name = "storage-chest", position = position, force = "neutral" } + interface.storage_filter = { name = "deconstruction-planner", quality = "normal" } table.insert(vlayer_data.entity_interfaces.storage_input, interface) if last_user then @@ -541,6 +542,12 @@ function vlayer.get_circuits() } end +local vlayer_circuits_string = "" + +for key, value in pairs(vlayer.get_circuits()) do + vlayer_circuits_string = vlayer_circuits_string .. string.format("[virtual-signal=%s] = %s\n", value, key:gsub("_", " ")) +end + --- Create a new circuit interface -- @tparam LuaSurface surface The surface to place the interface onto -- @tparam MapPosition position The position on the surface to place the interface at @@ -577,7 +584,11 @@ local function handle_circuit_interfaces() if not interface.valid then vlayer_data.entity_interfaces.circuit[index] = nil else - local circuit_oc = interface.get_or_create_control_behavior().sections[1] + local circuit_oc = interface.get_or_create_control_behavior() + if circuit_oc.sections_count == 0 then + circuit_oc.add_section() + end + circuit_oc = circuit_oc.sections[1] local signal_index = 1 local circuit = vlayer.get_circuits() @@ -610,6 +621,8 @@ local function handle_circuit_interfaces() circuit_oc.clear_slot(clear_index) end + + interface.combinator_description = vlayer_circuits_string end end end From 994bfba6ed8f4f32ee1b9edecf8011a12c7e62d2 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sun, 6 Apr 2025 15:39:18 +0100 Subject: [PATCH 4/6] Disallow rocket gui This gui has been causing too many issues in space age. --- exp_legacy/module/config/expcore/roles.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exp_legacy/module/config/expcore/roles.lua b/exp_legacy/module/config/expcore/roles.lua index 9ad1a593..d03933b2 100644 --- a/exp_legacy/module/config/expcore/roles.lua +++ b/exp_legacy/module/config/expcore/roles.lua @@ -283,7 +283,7 @@ local default = Roles.new_role("Guest", "") "command/data-preference", "command/connect", "gui/player-list", - "gui/rocket-info", + --"gui/rocket-info", "gui/science-info", "gui/task-list", "gui/warp-list", From 3dbdb2071fefc86ad3ab39d9f6d6b571578c5cc5 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sun, 6 Apr 2025 16:03:58 +0100 Subject: [PATCH 5/6] Update deps --- exp_groups/package.json | 6 +++--- exp_legacy/package.json | 4 ++-- exp_scenario/package.json | 10 +++++----- exp_util/package.json | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exp_groups/package.json b/exp_groups/package.json index ce171ce0..a358141d 100644 --- a/exp_groups/package.json +++ b/exp_groups/package.json @@ -14,8 +14,8 @@ "@clusterio/lib": "^2.0.0-alpha.19" }, "devDependencies": { - "@clusterio/lib": "^2.0.0-alpha.19", - "@clusterio/web_ui": "^2.0.0-alpha.19", + "@clusterio/lib": "2.0.0-alpha.20", + "@clusterio/web_ui": "2.0.0-alpha.20.b", "@types/fs-extra": "^11.0.4", "@types/node": "^20.4.5", "@types/react": "^18.2.21", @@ -23,7 +23,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "typescript": "^5.5.3", - "webpack": "^5.88.2", + "webpack": "^5.98.0", "webpack-cli": "^5.1.4", "webpack-merge": "^5.9.0" }, diff --git a/exp_legacy/package.json b/exp_legacy/package.json index b44413d3..089d643c 100644 --- a/exp_legacy/package.json +++ b/exp_legacy/package.json @@ -16,9 +16,9 @@ "@clusterio/lib": "^2.0.0-alpha.19" }, "devDependencies": { - "typescript": "^5.5.3", + "@clusterio/lib": "2.0.0-alpha.20", "@types/node": "^20.4.5", - "@clusterio/lib": "^2.0.0-alpha.19" + "typescript": "^5.5.3" }, "dependencies": { "@expcluster/lib_commands": "workspace:*", diff --git a/exp_scenario/package.json b/exp_scenario/package.json index 00112927..963df025 100644 --- a/exp_scenario/package.json +++ b/exp_scenario/package.json @@ -16,17 +16,17 @@ "@clusterio/lib": "^2.0.0-alpha.19" }, "devDependencies": { - "typescript": "^5.5.3", + "@clusterio/lib": "2.0.0-alpha.20", + "@clusterio/web_ui": "2.0.0-alpha.20.b", "@types/node": "^20.4.5", "@types/react": "^18.2.21", "antd": "^5.13.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "webpack": "^5.88.2", + "typescript": "^5.5.3", + "webpack": "^5.98.0", "webpack-cli": "^5.1.4", - "webpack-merge": "^5.9.0", - "@clusterio/web_ui": "^2.0.0-alpha.19", - "@clusterio/lib": "^2.0.0-alpha.19" + "webpack-merge": "^5.9.0" }, "dependencies": { "@expcluster/lib_commands": "workspace:*", diff --git a/exp_util/package.json b/exp_util/package.json index 3e6ec017..ea90794e 100644 --- a/exp_util/package.json +++ b/exp_util/package.json @@ -16,7 +16,7 @@ "@clusterio/lib": "^2.0.0-alpha.19" }, "devDependencies": { - "@clusterio/lib": "^2.0.0-alpha.19", + "@clusterio/lib": "2.0.0-alpha.20", "@types/node": "^20.14.9", "typescript": "^5.5.3" }, From aedc3cff6b480ff69142bc20765ac4c41680b72f Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sun, 6 Apr 2025 17:05:40 +0100 Subject: [PATCH 6/6] Fix lint errors on new luals version (#384) --- .github/workflows/fmtk.yml | 4 ++-- exp_groups/module/module_exports.lua | 3 ++- exp_gui/module/data.lua | 4 ++-- exp_gui/module/iter.lua | 2 ++ exp_legacy/module/expcore/permission_groups.lua | 2 +- exp_scenario/module/commands/connect.lua | 2 +- exp_util/module/module_exports.lua | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/fmtk.yml b/.github/workflows/fmtk.yml index 13fa984f..80ee4575 100644 --- a/.github/workflows/fmtk.yml +++ b/.github/workflows/fmtk.yml @@ -20,12 +20,12 @@ jobs: jq -s '.[0] * .[1].settings' temp.luarc.json ${{ github.workspace }}/factorio/config.json > check.luarc.json - name: Install LuaLS run: | - wget https://github.com/LuaLS/lua-language-server/releases/download/3.13.2/lua-language-server-3.13.2-linux-x64.tar.gz -q -O lusls.tar.gz + wget https://github.com/LuaLS/lua-language-server/releases/download/3.13.9/lua-language-server-3.13.9-linux-x64.tar.gz -q -O lusls.tar.gz mkdir luals && tar -xf lusls.tar.gz -C luals && rm lusls.tar.gz - name: Run Lint Report shell: bash run: | - ./luals/bin/lua-language-server --check=. --logpath=. --configpath=check.luarc.json --checklevel=Information + ./luals/bin/lua-language-server --check=. --logpath=. --configpath=check.luarc.json --checklevel=Information --check_out_path=check.json # Credit to https://github.com/Krealle/luals-check-action/blob/main/action.yml # Although some minor fixes were needed diff --git a/exp_groups/module/module_exports.lua b/exp_groups/module/module_exports.lua index 6f84f4da..56518bc8 100644 --- a/exp_groups/module/module_exports.lua +++ b/exp_groups/module/module_exports.lua @@ -216,9 +216,10 @@ end --- @param actions_names string[] An array of action names --- @return defines.input_action[] local function names_to_actions(actions_names) + --- @type defines.input_action[], number[], number local actions, invalid, invalid_i = {}, {}, 1 for i, action_name in ipairs(actions_names) do - local action = defines.input_action[action_name] + local action = defines.input_action[action_name] --[[ @as defines.input_action? ]] if action then actions[i] = action else diff --git a/exp_gui/module/data.lua b/exp_gui/module/data.lua index c792fcdb..bae2488b 100644 --- a/exp_gui/module/data.lua +++ b/exp_gui/module/data.lua @@ -87,7 +87,7 @@ function GuiData._metatable.__index(self, key) -- Check a given child table based on the object type assert(type(key) == "userdata", "Index type '" .. ExpUtil.get_class_name(key) .. "' given to GuiData. Must be of type userdata.") - local object_name = key.object_name + local object_name = key.object_name --- @diagnostic disable-line assign-type-mismatch if object_name == "LuaGuiElement" then local data = self._raw.element_data local player_elements = data and data[key.player_index] @@ -110,7 +110,7 @@ end --- @param value unknown function GuiData._metatable.__newindex(self, key, value) assert(type(key) == "userdata", "Index type '" .. ExpUtil.get_class_name(key) .. "' given to GuiData. Must be of type userdata.") - local object_name = key.object_name + local object_name = key.object_name --- @diagnostic disable-line assign-type-mismatch if object_name == "LuaGuiElement" then local data = self.element_data local player_elements = data[key.player_index] diff --git a/exp_gui/module/iter.lua b/exp_gui/module/iter.lua index 450a7a52..388bf8ef 100644 --- a/exp_gui/module/iter.lua +++ b/exp_gui/module/iter.lua @@ -37,6 +37,7 @@ local function nop() return nil, nil end local function next_valid_element(elements, prev_index) local element_index, element = next(elements, prev_index) while element and not element.valid do + --- @cast element_index -nil elements[element_index] = nil element_index, element = next(elements, element_index) end @@ -61,6 +62,7 @@ local function next_valid_player(scope_elements, players, prev_index, online) if index == nil then return nil, nil, nil end + --- @cast player -nil if online == nil or player.connected == online then local player_elements = scope_elements[player.index] diff --git a/exp_legacy/module/expcore/permission_groups.lua b/exp_legacy/module/expcore/permission_groups.lua index 9181e614..6df8f468 100644 --- a/exp_legacy/module/expcore/permission_groups.lua +++ b/exp_legacy/module/expcore/permission_groups.lua @@ -142,7 +142,7 @@ group:set_action('toggle_map_editor', false) ]] function PermissionsGroups._prototype:set_action(action, state) - local input_action = defines.input_action[action] + local input_action = defines.input_action[action] --[[ @as defines.input_action? ]] if input_action == nil then input_action = action end assert(type(input_action) == "number", tostring(action) .. " is not a valid input action") self.actions[input_action] = state diff --git a/exp_scenario/module/commands/connect.lua b/exp_scenario/module/commands/connect.lua index 5cb4b4f0..b935b45d 100644 --- a/exp_scenario/module/commands/connect.lua +++ b/exp_scenario/module/commands/connect.lua @@ -34,7 +34,7 @@ local function get_server_id(server) if server_count > 1 then return false, { "exp-commands_connect.too-many-matching", concat(server_names, ", ") } elseif server_count == 1 then - local server_id, server_details = next(servers) + local server_id, server_details = next(servers) --- @cast server_details -nil local status = External.get_server_status(server_id) if server_id == current_server.id then return false, { "exp-commands_connect.same-server", server_details.name } diff --git a/exp_util/module/module_exports.lua b/exp_util/module/module_exports.lua index e1deb308..e6394bae 100644 --- a/exp_util/module/module_exports.lua +++ b/exp_util/module/module_exports.lua @@ -42,7 +42,7 @@ local function check_type(value, type_name) if type_name == "userdata" then return false, value_type end - value_type = value.object_name + value_type = value.object_name --- @diagnostic disable-line assign-type-mismatch elseif value_type == "table" then if type_name == "table" then return false, value_type