From 1d1a03cf6af649e63c4c44fd2ba56a4c3806db4f Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sun, 19 Jan 2025 00:30:27 +0000 Subject: [PATCH 1/5] Fix issues with format - Remove tailing 'join' - Remove 'and' with single unit - Pad time values to 2 digits --- exp_util/module/module_exports.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/exp_util/module/module_exports.lua b/exp_util/module/module_exports.lua index d8c5fed1..c4749a5d 100644 --- a/exp_util/module/module_exports.lua +++ b/exp_util/module/module_exports.lua @@ -247,6 +247,8 @@ function ExpUtil.format_any(value, options) end --- @alias Common.format_time_param_format "short" | "long" | "clock" +-- TODO a single common function for calculating units for format_time and format_time_locale +-- TODO fix nil times because {"days", "--"} is not a valid locale string --- @class Common.format_time_param_units --- @field days boolean? True if days are included @@ -274,11 +276,16 @@ function ExpUtil.format_time(ticks, format, units) if not units.days then rtn_hours = rtn_hours + rtn_days * 24 end if not units.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end - --- @diagnostic enable: cast-local-type end local rtn = {} if format == "clock" then + if ticks then + -- When ticks is not nil, all rtn values are numbers + local f = "%02d" + rtn_days, rtn_hours = f:format(rtn_days), f:format(rtn_hours) + rtn_minutes, rtn_seconds = f:format(rtn_minutes), f:format(rtn_seconds) + end -- Example 12:34:56 or --:--:-- if units.days then rtn[#rtn + 1] = rtn_days end if units.hours then rtn[#rtn + 1] = rtn_hours end @@ -298,7 +305,9 @@ function ExpUtil.format_time(ticks, format, units) if units.hours then rtn[#rtn + 1] = rtn_hours .. " hours" end if units.minutes then rtn[#rtn + 1] = rtn_minutes .. " minutes" end if units.seconds then rtn[#rtn + 1] = rtn_seconds .. " seconds" end - rtn[#rtn] = "and " .. rtn[#rtn] + if #rtn > 1 then + rtn[#rtn] = "and " .. rtn[#rtn] + end return concat(rtn, ", ") end end @@ -329,6 +338,12 @@ function ExpUtil.format_time_locale(ticks, format, units) local join = ", " --- @type LocalisedString if format == "clock" then -- Example 12:34:56 or --:--:-- + if ticks then + -- When ticks is not nil, all rtn values are numbers + local f = "%02d" + rtn_days, rtn_hours = f:format(rtn_days), f:format(rtn_hours) + rtn_minutes, rtn_seconds = f:format(rtn_minutes), f:format(rtn_seconds) + end if units.days then rtn[#rtn + 1] = rtn_days end if units.hours then rtn[#rtn + 1] = rtn_hours end if units.minutes then rtn[#rtn + 1] = rtn_minutes end @@ -347,7 +362,9 @@ function ExpUtil.format_time_locale(ticks, format, units) if units.hours then rtn[#rtn + 1] = { "hours", rtn_hours } end if units.minutes then rtn[#rtn + 1] = { "minutes", rtn_minutes } end if units.seconds then rtn[#rtn + 1] = { "seconds", rtn_seconds } end - rtn[#rtn] = { "", { "and" }, " ", rtn[#rtn] } + if #rtn > 1 then + rtn[#rtn] = { "", { "and" }, " ", rtn[#rtn] } + end end --- @type LocalisedString @@ -357,6 +374,9 @@ function ExpUtil.format_time_locale(ticks, format, units) joined[2 * k + 1] = join end + -- Remove the last element which is a join component + joined[#joined] = nil + return joined end From b666758a546c6667254a2ef26702eb0c4647eebe Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sun, 19 Jan 2025 23:47:22 +0000 Subject: [PATCH 2/5] Fix time format with nil plural --- exp_util/module/module_exports.lua | 151 +++++++++++++++-------------- 1 file changed, 77 insertions(+), 74 deletions(-) diff --git a/exp_util/module/module_exports.lua b/exp_util/module/module_exports.lua index c4749a5d..f7059c5f 100644 --- a/exp_util/module/module_exports.lua +++ b/exp_util/module/module_exports.lua @@ -247,8 +247,6 @@ function ExpUtil.format_any(value, options) end --- @alias Common.format_time_param_format "short" | "long" | "clock" --- TODO a single common function for calculating units for format_time and format_time_locale --- TODO fix nil times because {"days", "--"} is not a valid locale string --- @class Common.format_time_param_units --- @field days boolean? True if days are included @@ -256,55 +254,78 @@ end --- @field minutes boolean? True if minutes are included --- @field seconds boolean? True if seconds are included +--- @class Common.extract_time_units_return +--- @field days number? Amount of days represented +--- @field hours number? Amount of hours represented +--- @field minutes number? Amount of minutes represented +--- @field seconds number? Amount of seconds represented + +--- Extract different time units from an amount of ticks +--- @param ticks number The number of ticks which will be represented, can be any duration or time value +--- @param units Common.format_time_param_units A table selecting which units should be displayed, options are: days, hours, minutes, seconds +--- @return Common.extract_time_units_return +function ExpUtil.extract_time_units(ticks, units) + -- Calculate the values to be determine the display values + local max_days, max_hours, max_minutes, max_seconds = ticks / 5184000, ticks / 216000, ticks / 3600, ticks / 60 + + local rtn = { + day = floor(max_days), + hours = floor(max_hours - floor(max_days) * 24), + minutes = floor(max_minutes - floor(max_hours) * 60), + seconds = floor(max_seconds - floor(max_minutes) * 60), + } + + -- Remove units that are not requested + if not units.days then + rtn.hours = rtn.hours + rtn.days * 24 + rtn.days = nil + end + if not units.hours then + rtn.minutes = rtn.minutes + rtn.hours * 60 + rtn.hours = nil + end + if not units.minutes then + rtn.seconds = rtn.seconds + rtn.minutes * 60 + rtn.minutes = nil + end + if not units.seconds then + rtn.seconds = nil + end + + return rtn +end + --- Format a tick value into one of a selection of pre-defined formats (short, long, clock) --- @param ticks number|nil The number of ticks which will be represented, can be any duration or time value --- @param format Common.format_time_param_format format to display, must be one of: short, long, clock --- @param units Common.format_time_param_units A table selecting which units should be displayed, options are: days, hours, minutes, seconds --- @return string # The ticks formatted into a string of the desired format function ExpUtil.format_time(ticks, format, units) - --- @type string | number, string | number, string | number, string | number - local rtn_days, rtn_hours, rtn_minutes, rtn_seconds = "--", "--", "--", "--" - - if ticks ~= nil then - -- Calculate the values to be determine the display values - local max_days, max_hours, max_minutes, max_seconds = ticks / 5184000, ticks / 216000, ticks / 3600, ticks / 60 - local days, hours = max_days, max_hours - floor(max_days) * 24 - local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60 - - -- Calculate rhw units to be displayed - rtn_days, rtn_hours, rtn_minutes, rtn_seconds = floor(days), floor(hours), floor(minutes), floor(seconds) - if not units.days then rtn_hours = rtn_hours + rtn_days * 24 end - if not units.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end - if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end - end + local times = ticks and ExpUtil.extract_time_units(ticks, units) or {} local rtn = {} if format == "clock" then - if ticks then - -- When ticks is not nil, all rtn values are numbers - local f = "%02d" - rtn_days, rtn_hours = f:format(rtn_days), f:format(rtn_hours) - rtn_minutes, rtn_seconds = f:format(rtn_minutes), f:format(rtn_seconds) - end - -- Example 12:34:56 or --:--:-- - if units.days then rtn[#rtn + 1] = rtn_days end - if units.hours then rtn[#rtn + 1] = rtn_hours end - if units.minutes then rtn[#rtn + 1] = rtn_minutes end - if units.seconds then rtn[#rtn + 1] = rtn_seconds end + -- Example '12:34:56' or '--:--:--' + local f = "%02d" + if units.days then rtn[#rtn + 1] = ticks and f:format(times.days) or "--" end + if units.hours then rtn[#rtn + 1] = ticks and f:format(times.hours) or "--" end + if units.minutes then rtn[#rtn + 1] = ticks and f:format(times.minutes) or "--" end + if units.seconds then rtn[#rtn + 1] = ticks and f:format(times.seconds) or "--" end return concat(rtn, ":") elseif format == "short" then - -- Example 12d 34h 56m or --d --h --m - if units.days then rtn[#rtn + 1] = rtn_days .. "d" end - if units.hours then rtn[#rtn + 1] = rtn_hours .. "h" end - if units.minutes then rtn[#rtn + 1] = rtn_minutes .. "m" end - if units.seconds then rtn[#rtn + 1] = rtn_seconds .. "s" end + -- Example '12d 34h 56m' or '--d --h --m' + if units.days then rtn[#rtn + 1] = (times.days or "--") .. "d" end + if units.hours then rtn[#rtn + 1] = (times.hours or "--") .. "h" end + if units.minutes then rtn[#rtn + 1] = (times.minutes or "--") .. "m" end + if units.seconds then rtn[#rtn + 1] = (times.seconds or "--") .. "s" end return concat(rtn, " ") else - -- Example 12 days, 34 hours, and 56 minutes or -- days, -- hours, and -- minutes - if units.days then rtn[#rtn + 1] = rtn_days .. " days" end - if units.hours then rtn[#rtn + 1] = rtn_hours .. " hours" end - if units.minutes then rtn[#rtn + 1] = rtn_minutes .. " minutes" end - if units.seconds then rtn[#rtn + 1] = rtn_seconds .. " seconds" end + -- Example '12 days, 34 hours, and 56 minutes' or 'nan days, nan hours, and nan minutes' + local nan = 0 / 0 + if units.days then rtn[#rtn + 1] = (times.days or nan) .. " days" end + if units.hours then rtn[#rtn + 1] = (times.hours or nan) .. " hours" end + if units.minutes then rtn[#rtn + 1] = (times.minutes or nan) .. " minutes" end + if units.seconds then rtn[#rtn + 1] = (times.seconds or nan) .. " seconds" end if #rtn > 1 then rtn[#rtn] = "and " .. rtn[#rtn] end @@ -318,50 +339,32 @@ end --- @param units Common.format_time_param_units A table selecting which units should be displayed, options are: days, hours, minutes, seconds --- @return LocalisedString # The ticks formatted into a string of the desired format function ExpUtil.format_time_locale(ticks, format, units) - --- @type string | number, string | number, string | number, string | number - local rtn_days, rtn_hours, rtn_minutes, rtn_seconds = "--", "--", "--", "--" - - if ticks ~= nil then - -- Calculate the values to be determine the display values - local max_days, max_hours, max_minutes, max_seconds = ticks / 5184000, ticks / 216000, ticks / 3600, ticks / 60 - local days, hours = max_days, max_hours - floor(max_days) * 24 - local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60 - - -- Calculate rhw units to be displayed - rtn_days, rtn_hours, rtn_minutes, rtn_seconds = floor(days), floor(hours), floor(minutes), floor(seconds) - if not units.days then rtn_hours = rtn_hours + rtn_days * 24 end - if not units.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end - if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end - end + local times = ticks and ExpUtil.extract_time_units(ticks, units) or {} local rtn = {} local join = ", " --- @type LocalisedString if format == "clock" then - -- Example 12:34:56 or --:--:-- - if ticks then - -- When ticks is not nil, all rtn values are numbers - local f = "%02d" - rtn_days, rtn_hours = f:format(rtn_days), f:format(rtn_hours) - rtn_minutes, rtn_seconds = f:format(rtn_minutes), f:format(rtn_seconds) - end - if units.days then rtn[#rtn + 1] = rtn_days end - if units.hours then rtn[#rtn + 1] = rtn_hours end - if units.minutes then rtn[#rtn + 1] = rtn_minutes end - if units.seconds then rtn[#rtn + 1] = rtn_seconds end + -- Example '12:34:56' or '--:--:--' + local f = "%02d" + if units.days then rtn[#rtn + 1] = ticks and f:format(times.days) or "--" end + if units.hours then rtn[#rtn + 1] = ticks and f:format(times.hours) or "--" end + if units.minutes then rtn[#rtn + 1] = ticks and f:format(times.minutes) or "--" end + if units.seconds then rtn[#rtn + 1] = ticks and f:format(times.seconds) or "--" end join = { "colon" } elseif format == "short" then - -- Example 12d 34h 56m or --d --h --m - if units.days then rtn[#rtn + 1] = { "?", { "time-symbol-days-short", rtn_days }, rtn_days .. "d" } end - if units.hours then rtn[#rtn + 1] = { "time-symbol-hours-short", rtn_hours } end - if units.minutes then rtn[#rtn + 1] = { "time-symbol-minutes-short", rtn_minutes } end - if units.seconds then rtn[#rtn + 1] = { "time-symbol-seconds-short", rtn_seconds } end + -- Example '12d 34h 56m' or '--d --h --m' + if units.days then rtn[#rtn + 1] = { "?", { "time-symbol-days-short", times.days or "--" }, (times.days or "--") .. "d" } end + if units.hours then rtn[#rtn + 1] = { "time-symbol-hours-short", times.hours or "--" } end + if units.minutes then rtn[#rtn + 1] = { "time-symbol-minutes-short", times.minutes or "--" } end + if units.seconds then rtn[#rtn + 1] = { "time-symbol-seconds-short", times.seconds or "--" } end join = " " else - -- Example 12 days, 34 hours, and 56 minutes or -- days, -- hours, and -- minutes - if units.days then rtn[#rtn + 1] = { "days", rtn_days } end - if units.hours then rtn[#rtn + 1] = { "hours", rtn_hours } end - if units.minutes then rtn[#rtn + 1] = { "minutes", rtn_minutes } end - if units.seconds then rtn[#rtn + 1] = { "seconds", rtn_seconds } end + -- Example '12 days, 34 hours, and 56 minutes' or 'nan days, nan hours, and nan minutes' + local nan = 0 / 0 + if units.days then rtn[#rtn + 1] = { "days", times.days or nan } end + if units.hours then rtn[#rtn + 1] = { "hours", times.hours or nan } end + if units.minutes then rtn[#rtn + 1] = { "minutes", times.minutes or nan } end + if units.seconds then rtn[#rtn + 1] = { "seconds", times.seconds or nan } end if #rtn > 1 then rtn[#rtn] = { "", { "and" }, " ", rtn[#rtn] } end From 7369386725299dcb43fea91434dfac17f82fe13d Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Mon, 20 Jan 2025 08:48:27 +0900 Subject: [PATCH 3/5] Fix incorrect research names (#358) --- exp_legacy/module/config/research.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exp_legacy/module/config/research.lua b/exp_legacy/module/config/research.lua index 7ba2e223..07925afa 100644 --- a/exp_legacy/module/config/research.lua +++ b/exp_legacy/module/config/research.lua @@ -114,9 +114,9 @@ return { -- Robot Speed ["worker-robots-speed-7"] = 7, -- Laser Damage - ["energy-weapons-damage-7"] = 7, + ["laser-weapons-damage-7"] = 7, -- Electric Damage - ["electric-weapons-damage-3"] = 3, + ["electric-weapons-damage-4"] = 4, -- Explosive Damage ["stronger-explosives-7"] = 7, -- Bullet Damage From c1b24f664bd7d5e4d77f8d8dd79c3acbe6e10302 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Mon, 20 Jan 2025 08:49:50 +0900 Subject: [PATCH 4/5] Update waterfill locale (#360) * Update en.cfg * Update zh-CN.cfg * Update zh-TW.cfg --- exp_scenario/module/locale/en.cfg | 2 +- exp_scenario/module/locale/zh-CN.cfg | 4 ++-- exp_scenario/module/locale/zh-TW.cfg | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exp_scenario/module/locale/en.cfg b/exp_scenario/module/locale/en.cfg index 52edc056..2dd747e4 100644 --- a/exp_scenario/module/locale/en.cfg +++ b/exp_scenario/module/locale/en.cfg @@ -275,7 +275,7 @@ cleared-last=__1__ had their last warning cleared by __2__. description=Replace tiles with shallow water. requires-explosives=__ITEM__cliff-explosives__ are required to create water. enter=Entered waterfill selection mode, select the area to fill with water. -exit=Exited water fill seclection mode. +exit=Exited waterfill selection mode. nauvis-only=Can only waterfill on Nauvis, this may change in the future. area-too-large=Selected area is too large, must be less than __1__ tiles, selected __2__. too-few-explosives=Requires __1__ __ITEM__cliff-explosives__ you have __2__. diff --git a/exp_scenario/module/locale/zh-CN.cfg b/exp_scenario/module/locale/zh-CN.cfg index 109dd7ce..6abe8229 100644 --- a/exp_scenario/module/locale/zh-CN.cfg +++ b/exp_scenario/module/locale/zh-CN.cfg @@ -274,8 +274,8 @@ cleared-last=__1__ 的最後警告己被 __2__ 清除。 [exp-commands_waterfill] description=把地換為淺水。 requires-explosives=沒有足夠的 __ITEM__cliff-explosives__ 。 -enter=現在進入區域選擇 -exit=已進入區域選擇 +enter=現在進入挖水區域選擇 +exit=已進入挖水區域選擇 nauvis-only=只可在地星上填水,之後可能會再改變。 area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格。 too-few-explosives=需要 __1__ 個 __ITEM__cliff-explosives__,你現在有 __2__ 個。 diff --git a/exp_scenario/module/locale/zh-TW.cfg b/exp_scenario/module/locale/zh-TW.cfg index 109dd7ce..6abe8229 100644 --- a/exp_scenario/module/locale/zh-TW.cfg +++ b/exp_scenario/module/locale/zh-TW.cfg @@ -274,8 +274,8 @@ cleared-last=__1__ 的最後警告己被 __2__ 清除。 [exp-commands_waterfill] description=把地換為淺水。 requires-explosives=沒有足夠的 __ITEM__cliff-explosives__ 。 -enter=現在進入區域選擇 -exit=已進入區域選擇 +enter=現在進入挖水區域選擇 +exit=已進入挖水區域選擇 nauvis-only=只可在地星上填水,之後可能會再改變。 area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格。 too-few-explosives=需要 __1__ 個 __ITEM__cliff-explosives__,你現在有 __2__ 個。 From 99ca4c8b5225037248f08e57110fe67d3d3cbb53 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Mon, 20 Jan 2025 08:50:29 +0900 Subject: [PATCH 5/5] Fix vlayer selection locale (#361) * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update vlayer.lua --- exp_legacy/module/locale/en/gui.cfg | 2 ++ exp_legacy/module/locale/zh-CN/gui.cfg | 2 ++ exp_legacy/module/locale/zh-TW/gui.cfg | 2 ++ exp_legacy/module/modules/gui/vlayer.lua | 3 ++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/exp_legacy/module/locale/en/gui.cfg b/exp_legacy/module/locale/en/gui.cfg index 9f0957fd..729196f9 100644 --- a/exp_legacy/module/locale/en/gui.cfg +++ b/exp_legacy/module/locale/en/gui.cfg @@ -294,6 +294,8 @@ control-type-energy=Energy control-type-circuit=Circuit control-type-storage-input=Storage Input control-type-storage-output=Storage Output +enter=Entered vlayer selection mode. +exit=Exited vlayer selection mode. [module] main-tooltip=Module GUI diff --git a/exp_legacy/module/locale/zh-CN/gui.cfg b/exp_legacy/module/locale/zh-CN/gui.cfg index 1cabda1b..5f95bd6b 100644 --- a/exp_legacy/module/locale/zh-CN/gui.cfg +++ b/exp_legacy/module/locale/zh-CN/gui.cfg @@ -294,6 +294,8 @@ control-type-energy=電力 control-type-circuit=回路 control-type-storage-input=放入箱 control-type-storage-output=提取箱 +enter=現在進入 vlayer 區域選擇 +exit=已進入 vlayer 區域選擇 [module] main-tooltip=模組介面 diff --git a/exp_legacy/module/locale/zh-TW/gui.cfg b/exp_legacy/module/locale/zh-TW/gui.cfg index 65e60a84..398c779b 100644 --- a/exp_legacy/module/locale/zh-TW/gui.cfg +++ b/exp_legacy/module/locale/zh-TW/gui.cfg @@ -294,6 +294,8 @@ control-type-energy=電力 control-type-circuit=回路 control-type-storage-input=放入箱 control-type-storage-output=提取箱 +enter=現在進入 vlayer 區域選擇 +exit=已進入 vlayer 區域選擇 [module] main-tooltip=模組介面 diff --git a/exp_legacy/module/modules/gui/vlayer.lua b/exp_legacy/module/modules/gui/vlayer.lua index 44409c24..12595259 100644 --- a/exp_legacy/module/modules/gui/vlayer.lua +++ b/exp_legacy/module/modules/gui/vlayer.lua @@ -390,9 +390,10 @@ local vlayer_gui_control_build = }:on_click(function(player, _, _) if Selection.is_selecting(player, SelectionConvertArea) then Selection.stop(player) + player.print{ "vlayer.exit" } else Selection.start(player, SelectionConvertArea) - player.print{ "exp-commands_waterfill.entered-area-selection" } + player.print{ "vlayer.enter" } end vlayer_gui_list_refresh(player)