Update to make catagories
This commit is contained in:
@@ -20,6 +20,59 @@ local function getAmmoMakerFiredCasing(ammoType)
|
||||
return nil
|
||||
end
|
||||
|
||||
local function getAmmoTypeData()
|
||||
if type(ammoMakerAmmoTypes) ~= "table" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local data = ammoMakerAmmoTypes[ammoType]
|
||||
if type(data) ~= "table" or type(data.ammoTypes) ~= "table" or #data.ammoTypes == 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
local function getActiveAmmoData(typeData)
|
||||
if type(typeData) ~= "table" or type(typeData.ammoTypes) ~= "table" or type(ammoMakerAmmoData) ~= "table" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local activeIndex = 1
|
||||
if type(typeData.modIds) == "table" and type(ammoMakerCompatibleMods) == "table" then
|
||||
for i = 1, #typeData.modIds do
|
||||
local modId = typeData.modIds[i]
|
||||
if ammoMakerCompatibleMods[modId] == true then
|
||||
activeIndex = i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if activeIndex < 1 or activeIndex > #typeData.ammoTypes then
|
||||
activeIndex = 1
|
||||
end
|
||||
|
||||
local activeAmmoKey = typeData.ammoTypes[activeIndex]
|
||||
if type(activeAmmoKey) == "string" then
|
||||
local activeAmmoData = ammoMakerAmmoData[activeAmmoKey]
|
||||
if type(activeAmmoData) == "table" then
|
||||
return activeAmmoData
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #typeData.ammoTypes do
|
||||
local ammoKey = typeData.ammoTypes[i]
|
||||
if type(ammoKey) == "string" then
|
||||
local ammoData = ammoMakerAmmoData[ammoKey]
|
||||
if type(ammoData) == "table" then
|
||||
return ammoData
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
local function partDataToFiredType(partData)
|
||||
if type(partData) ~= "table" then
|
||||
return nil
|
||||
@@ -37,30 +90,16 @@ local function getAmmoMakerFiredCasing(ammoType)
|
||||
return nil
|
||||
end
|
||||
|
||||
if type(ammoMakerGetCasingType) == "function" then
|
||||
local ok, casingType = pcall(ammoMakerGetCasingType, ammoType)
|
||||
if ok and type(casingType) == "string" then
|
||||
local firedType = partDataToFiredType(ammoMakerAmmoParts[casingType])
|
||||
if firedType then
|
||||
return firedType
|
||||
end
|
||||
end
|
||||
local ammoTypeData = getAmmoTypeData()
|
||||
if not ammoTypeData then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Fallback path that doesn't depend on Ammo Maker active-mod resolution.
|
||||
if type(ammoMakerAmmoTypes) == "table" and type(ammoMakerAmmoData) == "table" then
|
||||
local ammoDef = ammoMakerAmmoTypes[ammoType]
|
||||
if type(ammoDef) == "table" and type(ammoDef.ammoTypes) == "table" then
|
||||
for i = 1, #ammoDef.ammoTypes do
|
||||
local ammoKey = ammoDef.ammoTypes[i]
|
||||
local ammoData = ammoMakerAmmoData[ammoKey]
|
||||
if type(ammoData) == "table" and type(ammoData.casingType) == "string" then
|
||||
local firedType = partDataToFiredType(ammoMakerAmmoParts[ammoData.casingType])
|
||||
if firedType then
|
||||
return firedType
|
||||
end
|
||||
end
|
||||
end
|
||||
local ammoData = getActiveAmmoData(ammoTypeData)
|
||||
if type(ammoData) == "table" and type(ammoData.casingType) == "string" then
|
||||
local firedType = partDataToFiredType(ammoMakerAmmoParts[ammoData.casingType])
|
||||
if firedType then
|
||||
return firedType
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user