Don't Starve Together

Don't Starve Together

Backpack Slot
同时显示背包/护甲
希望可以合并到大佬的Mod,虽然只对官方的背包做了兼容


local bag_symbol = {
backpack = "swap_backpack",
piggyback = "swap_piggyback",
icepack = "swap_icepack",
candybag = "candybag",
seedpouch = "seedpouch",
spicepack = "swap_chefpack",
krampus_sack = "swap_krampus_sack",
}

local function backpack_onequip(inst, owner)
if owner:HasTag("player") then
local skin_build = inst:GetSkinBuild()
if skin_build ~= nil then
owner:PushEvent("equipskinneditem", inst:GetSkinName())
owner.AnimState:OverrideItemSkinSymbol("backpack", skin_build, "backpack", inst.GUID, bag_symbol[inst.prefab])
owner.AnimState:OverrideItemSkinSymbol("swap_body_tall", skin_build, "swap_body", inst.GUID, bag_symbol[inst.prefab])
else
owner.AnimState:OverrideSymbol("backpack", bag_symbol[inst.prefab], "backpack")
owner.AnimState:OverrideSymbol("swap_body_tall", bag_symbol[inst.prefab], "swap_body")
end

if inst.components.container ~= nil then
inst.components.container:Open(owner)
end
else
inst.components.equippable.orig_onequipfn(inst, owner)
end
end

local function backpack_onunequip(inst, owner)
if owner:HasTag("player") then
local skin_build = inst:GetSkinBuild()
if skin_build ~= nil then
owner:PushEvent("unequipskinneditem", inst:GetSkinName())
end
owner.AnimState:ClearOverrideSymbol("swap_body_tall")
owner.AnimState:ClearOverrideSymbol("backpack")

if inst.components.container ~= nil then
inst.components.container:Close(owner)
end
else
inst.components.equippable.orig_onunequipfn(inst, owner)
end
end

local function backpack_postinit(inst)
if not TheWorld.ismastersim then
return
end
if inst.components.equippable then
inst.components.equippable.orig_onequipfn = inst.components.equippable.onequipfn
inst.components.equippable.orig_onunequipfn = inst.components.equippable.onunequipfn
inst.components.equippable:SetOnEquip(backpack_onequip)
inst.components.equippable:SetOnUnequip(backpack_onunequip)
end
end

local backpacks = {"backpack", "piggyback", "icepack", "candybag", "seedpouch", "spicepack", "krampus_sack"}
for _, backpack in pairs(backpacks) do
AddPrefabPostInit(backpack, backpack_postinit)
end