Jump to content

Need some help with gift-type bundle inv images


Recommended Posts

So i've been trying to make bundles that work identically to gift bundles and while i got everything to work i can't figure out how to handle the inventory images.

20221006163020_1.thumb.jpg.04c7f961c74b49cff111ac1350d58004.jpg

(my inventory is full of bundles in this pic)

Anyway the bundle code is mostly copy pasted from the base game and klei seems to handle inventory images differently.

Code in question (the part that handles inv images)

local function MakeBundle(name, onesize, variations, loot, tossloot, setupdata, bank, build, inventoryimage)
       local assets =
    {
	Asset("ANIM", "anim/whiskybundle.zip"),
	
	Asset("ATLAS", "images/inventoryimages/whiskybundle_small.xml"),
    Asset("IMAGE", "images/inventoryimages/whiskybundle_small.tex"),
	
	Asset("ATLAS", "images/inventoryimages/whiskybundle_small1.xml"),
    Asset("IMAGE", "images/inventoryimages/whiskybundle_small1.tex"),
	
	Asset("ATLAS", "images/inventoryimages/whiskybundle_medium.xml"),
    Asset("IMAGE", "images/inventoryimages/whiskybundle_medium.tex"),
	
	Asset("ATLAS", "images/inventoryimages/whiskybundle_medium1.xml"),
    Asset("IMAGE", "images/inventoryimages/whiskybundle_medium1.tex"),
	
	Asset("ATLAS", "images/inventoryimages/whiskybundle_large.xml"),
    Asset("IMAGE", "images/inventoryimages/whiskybundle_large.tex"),
	
	Asset("ATLAS", "images/inventoryimages/whiskybundle_large1.xml"),
    Asset("IMAGE", "images/inventoryimages/whiskybundle_large1.tex")
	
    }


    local prefabs =
    {
        "ash",
        "whiskybundle_unwrap",
    }

        if variations ~= nil then
        for i = 1, variations do
            if onesize then
                table.insert(assets, Asset("INV_IMAGE", (inventoryimage or name)..tostring(i)))
            else
                table.insert(assets, Asset("INV_IMAGE", (inventoryimage or name).."_small"..tostring(i)))
                table.insert(assets, Asset("INV_IMAGE", (inventoryimage or name).."_medium"..tostring(i)))
                table.insert(assets, Asset("INV_IMAGE", (inventoryimage or name).."_large"..tostring(i)))
            end
        end
    elseif not onesize then
        table.insert(assets, Asset("INV_IMAGE", (inventoryimage or name).."_small"))
        table.insert(assets, Asset("INV_IMAGE", (inventoryimage or name).."_medium"))
        table.insert(assets, Asset("INV_IMAGE", (inventoryimage or name).."_large"))
    end

    local prefabs =
    {
        "ash",
        name.."_unwrap",
    }

    if loot ~= nil then
        for i, v in ipairs(loot) do
            table.insert(prefabs, v)
        end
    end

    local function UpdateInventoryImage(inst)
        local suffix = inst.suffix or "_small"
        if variations ~= nil then
            if inst.variation == nil then
                inst.variation = math.random(variations)
            end
            suffix = suffix..tostring(inst.variation)

            local skin_name = inst:GetSkinName()
            if skin_name ~= nil then
                inst.components.inventoryitem:ChangeImageName(skin_name..(onesize and tostring(inst.variation) or suffix))
            else
                inst.components.inventoryitem:ChangeImageName(name..(onesize and tostring(inst.variation) or suffix))
            end
        elseif not onesize then
            local skin_name = inst:GetSkinName()
            if skin_name ~= nil then
                inst.components.inventoryitem:ChangeImageName(skin_name..suffix)
            else
                inst.components.inventoryitem:ChangeImageName(name..suffix)
            end
        end
    end


    local function OnWrapped(inst, num, doer)
        local suffix =
            (onesize and "_onesize") or
            (num > 3 and "_large") or
            (num > 1 and "_medium") or
            "_small"

        inst.suffix = suffix

        UpdateInventoryImage(inst)

        if inst.variation then
            suffix = suffix.."1"
        end
        inst.AnimState:PlayAnimation("idle"..suffix)

        if doer ~= nil and doer.SoundEmitter ~= nil then
            doer.SoundEmitter:PlaySound(inst.skin_wrap_sound or "dontstarve/common/together/packaged")
        end
    end

I've looked at other similar items, i've butchered this code in like 3 different ways and i haven't made any progress on this for a week now so if anyone knows what's up please help.

Link to comment
Share on other sites

Did you forget to load assets either in modmain.lua or in prefab file?

Did you forget to call RegisterInventoryItemAtlas?

RegisterInventoryItemAtlas("images/" .. xmlfile .. ".xml", image .. ".tex")
RegisterInventoryItemAtlas("images/" .. xmlfile .. ".xml", hash(image .. ".tex"))

Did you forget to specify the inventoryitem.atlasname and inventoryitem.imagename?

inst.components.inventoryitem.atlasname = "images/"..atlasname..".xml" -- "images/bundle.xml"
inst.components.inventoryitem.imagename = imagename --"bundle"

 

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, Rickzzs said:

Did you forget to load assets either in modmain.lua or in prefab file?

Did you forget to call RegisterInventoryItemAtlas?

RegisterInventoryItemAtlas("images/" .. xmlfile .. ".xml", image .. ".tex")
RegisterInventoryItemAtlas("images/" .. xmlfile .. ".xml", hash(image .. ".tex"))

Did you forget to specify the inventoryitem.atlasname and inventoryitem.imagename?

inst.components.inventoryitem.atlasname = "images/"..atlasname..".xml" -- "images/bundle.xml"
inst.components.inventoryitem.imagename = imagename --"bundle"

 

Nope, i have all assets loaded in modmain. Specifying the inventory image didn't work either cause the UpdateInventoryImage function would replace them with assets it couldn't find. If u remember gift bundles change their inventory image and sprites depending on how much stuff is in them. I didn't find a solution and the bundle code is too confusing to me so yea i just gave up, got rid of UpdateInventoryImage and added a static inventory image.20221009153009_1.thumb.jpg.62b374b223afbe97640c6aaad3d3d41b.jpg

still thank u tho

Link to comment
Share on other sites

12 hours ago, Mentos said:

snip

So the problem is that the inventory cannot find your image file.

You may want to look at client_log or trace from inventory.lua to see where things goes unintended.

One more suggestion is that you can pack all inventory images into one xml because that is the convention. Things may go wrong if you have multiple xml for a single prefab because it is not design to be.

  • Like 1
Link to comment
Share on other sites

7 hours ago, Rickzzs said:

So the problem is that the inventory cannot find your image file.

You may want to look at client_log or trace from inventory.lua to see where things goes unintended.

One more suggestion is that you can pack all inventory images into one xml because that is the convention. Things may go wrong if you have multiple xml for a single prefab because it is not design to be.

ohh good idea thank you, i'll try again and see if i can get it to work

Link to comment
Share on other sites

On 10/10/2022 at 4:18 AM, Rickzzs said:

One more suggestion is that you can pack all inventory images into one xml because that is the convention. Things may go wrong if you have multiple xml for a single prefab because it is not design to be.

I tried doing this but the download link for the atlas packer on the forums is dead. Would u happen to have a copy?

Link to comment
Share on other sites

6 hours ago, Mentos said:

I tried doing this but the download link for the atlas packer on the forums is dead. Would u happen to have a copy?

I posted a tool collection in the tutorial and guide forum. You can find what you need there.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...