mirror of
https://github.com/factoriolib/flib.git
synced 2025-09-06 12:15:02 +00:00
Compare commits
5 Commits
4eb1b795a6
...
ad56284233
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ad56284233 | ||
![]() |
41544cd941 | ||
![]() |
6ae3ed1a84 | ||
![]() |
046392cfa7 | ||
![]() |
605e071983 |
@@ -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
|
||||
|
@@ -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",
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user