No more warnings

This commit is contained in:
Cooldude2606
2024-09-28 03:46:14 +01:00
parent 32a8ba8f3a
commit 3145f7e904
43 changed files with 215 additions and 177 deletions

View File

@@ -204,15 +204,15 @@ end
-- @param[opt] tableAsJson If table values should be returned as json
-- @param[opt] maxLineCount If table newline count exceeds provided then it will be inlined
-- @return The formated version of the value
function Common.format_any(value, tableAsJson, maxLineCount)
function Common.format_any(value, as_json, max_line_count)
local formatted, is_locale_string = Common.safe_value(value)
if type(formatted) == "table" and not is_locale_string then
if tableAsJson then
if as_json then
local success, rtn = pcall(game.table_to_json, value)
if success then return rtn end
end
local rtn = table.inspect(value, { depth = 5, indent = " ", newline = "\n", process = Common.safe_value })
if maxLineCount == nil or select(2, rtn:gsub("\n", "")) < maxLineCount then return rtn end
if max_line_count == nil or select(2, rtn:gsub("\n", "")) < max_line_count then return rtn end
return table.inspect(value, { depth = 5, indent = "", newline = "", process = Common.safe_value })
end
return formatted
@@ -234,10 +234,12 @@ function Common.format_time(ticks, format, units)
local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60
-- Calculate rhw units to be displayed
--- @diagnostic disable: cast-local-type
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
--- @diagnostic enable: cast-local-type
end
local rtn = {}
@@ -282,10 +284,12 @@ function Common.format_locale_time(ticks, format, units)
local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60
-- Calculate rhw units to be displayed
--- @diagnostic disable: cast-local-type
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
--- @diagnostic enable: cast-local-type
end
local rtn = {}
@@ -296,6 +300,7 @@ function Common.format_locale_time(ticks, format, units)
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
--- @diagnostic disable-next-line: cast-local-type
join = { "colon" }
elseif format == "short" then
-- Example 12d 34h 56m or --d --h --m
@@ -313,10 +318,10 @@ function Common.format_locale_time(ticks, format, units)
rtn[#rtn] = { "", { "and" }, " ", rtn[#rtn] }
end
local joined = { "" }
local joined = { "" } --[[@as any]]
for k, v in ipairs(rtn) do
joined[2 * k] = v
joined[2 * k + 1] = join
joined[2 * k + 1] = join --[[@as any]]
end
return joined

View File

@@ -5,20 +5,20 @@
@usage-- Show player chat message in world
local function on_console_chat(event)
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
FloatingText.print_as_player(player, event.message)
end
@usage-- Show player tags above their characters
local function on_player_respawned(event)
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
FloatingText.create_tag_as_player(player, player.tag)
end
@usage-- Show placed an entity in alt mode
local function on_built_entity(event)
local entity = event.created_entity
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
FloatingText.create_tag_above_entity(entity, player.name, player.color, true)
end

View File

@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
-- luacheck:ignore global table
local random = math.random
@@ -259,7 +260,7 @@ end
-- @param x one comparator operand
-- @param y the other comparator operand
-- @return true if x logically comes before y in a list, false otherwise
local function sortFunc(x, y) -- sorts tables with mixed index types.
local function sort_func(x, y) -- sorts tables with mixed index types.
local tx = type(x)
local ty = type(y)
if tx == ty then
@@ -296,7 +297,7 @@ function table.get_values(tbl, sorted, as_string)
end
end
if sorted then
table.sort(valueset, sortFunc)
table.sort(valueset, sort_func)
end
return valueset
end
@@ -322,7 +323,7 @@ function table.get_keys(tbl, sorted, as_string)
end
end
if sorted then
table.sort(keyset, sortFunc)
table.sort(keyset, sort_func)
end
return keyset
end