mirror of
https://github.com/factoriolib/flib.git
synced 2025-09-04 08:26:22 +00:00
Add flib_prototypes.get_base_type method
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.16.3
|
||||
Date: ????
|
||||
Features:
|
||||
- Added `flib_prototypes.get_base_type` method.
|
||||
Changes:
|
||||
- Improved error messaging of flib_prototypes functions.
|
||||
---------------------------------------------------------------------------------------------------
|
||||
|
@@ -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