Compare commits

...

5 Commits

Author SHA1 Message Date
compilatron
ad56284233 Move to version 0.16.4 2025-06-06 00:34:32 +02:00
compilatron
41544cd941 Prepare to release version 0.16.3 2025-06-06 00:34:28 +02:00
Caleb Heuer
6ae3ed1a84 Fix flib_locale.of using derived type for fallback string
Fixes #80
2025-06-06 00:33:27 +02:00
Caleb Heuer
046392cfa7 Add flib_prototypes.get_base_type method 2025-06-06 00:33:27 +02:00
PennyJim
605e071983 Actually use prototypes variable (#79) 2025-06-06 00:12:40 +02:00
4 changed files with 31 additions and 4 deletions

View File

@@ -1,8 +1,16 @@
---------------------------------------------------------------------------------------------------
Version: 0.16.3
Version: 0.16.4
Date: ????
Changes:
---------------------------------------------------------------------------------------------------
Version: 0.16.3
Date: 2025-06-05
Features:
- Added `flib_prototypes.get_base_type` method.
Changes:
- Improved error messaging of flib_prototypes functions.
Bugfixes:
- Fixed that `flib_locale.of` would give an incorrect result in some cases. (#80)
---------------------------------------------------------------------------------------------------
Version: 0.16.2
Date: 2025-01-24

View File

@@ -1,6 +1,6 @@
{
"name": "flib",
"version": "0.16.3",
"version": "0.16.4",
"title": "Factorio Library",
"author": "raiguard, Optera, justarandomgeek, Nexela",
"contact": "https://github.com/factoriolib/flib",

View File

@@ -18,7 +18,7 @@ function flib_locale.of(prototype, name)
elseif defines.prototypes.item[prototype.type] then
return flib_locale.of_item(prototype --[[@as data.ItemPrototype]])
else
return prototype.localised_name or { prototype.type .. "-name." .. prototype.name }
return prototype.localised_name or { flib_prototypes.get_base_type(prototype.type) .. "-name." .. prototype.name }
end
end

View File

@@ -181,7 +181,7 @@ function flib_prototypes.find(base_type, name)
for derived_type in pairs(defines.prototypes[base_type]) do
local prototypes = data.raw[derived_type]
if prototypes then
local prototype = data.raw[derived_type][name]
local prototype = prototypes[name]
if prototype then
return prototype
end
@@ -262,4 +262,23 @@ function flib_prototypes.get(base_type, name)
return result
end
--- @type table<string, string?>
local base_type_lookup = {}
for base_type, derived_types in pairs(defines.prototypes) do
for derived_type in pairs(derived_types) do
base_type_lookup[derived_type] = base_type
end
end
--- Returns the base type of the given prototype type.
--- @param derived_type string
--- @return string
function flib_prototypes.get_base_type(derived_type)
local base_type = base_type_lookup[derived_type]
if not base_type then
error("'" .. derived_type .. "' is not a valid prototype type.")
end
return base_type
end
return flib_prototypes