ov-sa/Assetify.library

Allow nil values for `createDummy()` assetClump and clumpMaps variables

thejdmego opened this issue · 4 comments

If you don't want to set any clumps to asset dummy you should set this variables as false, but if you use nil instead then asset will not be applied for dummy element.

If you don't want to set any clumps to asset dummy you should set this variables as false, but if you use nil instead then asset will not be applied for dummy element.

You mean this isn't working r8?

local element: cDummy = assetify.createDummy(
  string: assetType,
  string: assetName,
  string: nil,
  table: nil,
  table: dummyData
)

Maybe because unpack bug, table.unpack can fix

Maybe because unpack bug, table.unpack can fix

I've made an extension to fix this artifact.

-----------------
--[[ Imports ]]--
-----------------

local imports = {
    type = type,
    pairs = pairs,
    select = select,
    unpack = unpack
}
unpack = nil


----------------------
--[[ Class: Table ]]--
----------------------

--This function packs while keeping nil values into consideration
table.pack = function(...)
    return {__n = imports.select("#", ...), ...}
end

--This function unpacks either normal table or custom packed table via above function ^
--Note: Normally default unpack() bugs asf especially when unpacking table with nil values. This has been fixed on newer Lua version; However MTA is bound to an older version for compatibility reasons.
table.unpack = function(baseTable)
    if not baseTable or (imports.type(baseTable) ~= "table") then return false end
    return imports.unpack(baseTable, 1, baseTable.__n or #baseTable)
end

--Clones an existing table
table.clone = function(baseTable, isRecursive)
    if not baseTable or (imports.type(baseTable) ~= "table") then return false end
    local clonedTable = {}
    for i, j in imports.pairs(baseTable) do
        if (imports.type(j) == "table") and isRecursive then
            clonedTable[i] = table.clone(j, true)
        else
            clonedTable[i] = j
        end
    end
    return clonedTable
end

Usage:
━━━━

local testTable = table.pack(nil, "Tron", nil, "Rookie", nil, nil, "Fantastic", nil, "Kid")
print(table.unpack(testTable)) --INFO: nil    Tron    nil    Rookie    nil    nil    Fantastic    nil    Kid
iprint(table.clone(testTable))

If you don't want to set any clumps to asset dummy you should set this variables as false, but if you use nil instead then asset will not be applied for dummy element.

Fixed in this release: https://github.com/ov-sa/Assetify-Library/releases/tag/v.4.2.4