local assets=
{
	Asset("ANIM", "anim/backpack.zip"),
	Asset("ANIM", "anim/swap_xiaoyang_sack.zip"),
	Asset("IMAGE", "images/inventoryimages/venus_yangsack.tex"),
	Asset("ATLAS", "images/inventoryimages/venus_yangsack.xml"),

	
}

local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_body", "swap_xiaoyang_sack", "backpack")
    owner.AnimState:OverrideSymbol("swap_body", "swap_xiaoyang_sack", "swap_body")
    owner.components.inventory:SetOverflow(inst)
    inst.components.container:Open(owner)
end

local function onunequip(inst, owner) 
    owner.AnimState:ClearOverrideSymbol("swap_body")
    owner.AnimState:ClearOverrideSymbol("backpack")
    owner.components.inventory:SetOverflow(nil)
    inst.components.container:Close(owner)
end
local slotpos = {}

for y = 0, 6 do
	table.insert(slotpos, Vector3(-162, -y*75 + 240 ,0))
	table.insert(slotpos, Vector3(-162 +75, -y*75 + 240 ,0))
end
local function onopen(inst)
	inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_open", "open")
end

local function onclose(inst)
	inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_close", "open")
end



local function fn(Sim)
	local inst = CreateEntity()
    
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()
    MakeInventoryPhysics(inst)
    inst.AnimState:SetBank("swap_xiaoyang_sack")
    inst.AnimState:SetBuild("swap_xiaoyang_sack")
    inst.AnimState:PlayAnimation("idle")
    if SaveGameIndex:IsModeShipwrecked() then
    MakeInventoryFloatable(inst, "idle_water", "idle")
    end
    inst:AddTag("backpack")
    inst:AddTag("miaomiaosack")
	local minimap = inst.entity:AddMiniMapEntity()
	minimap:SetIcon("xiaoyang_sack.tex")

    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "venus_yangsack"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/venus_yangsack.xml"
    inst.components.inventoryitem.cangoincontainer = false
    
    
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.BACK or EQUIPSLOTS.BODY
    
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
    if IsDLCEnabled(CAPY_DLC) then
	inst.components.equippable.walkspeedmult = 0.1
	else
	inst.components.equippable.walkspeedmult = 1.1
	end
    
    inst:AddComponent("container")
    inst.components.container:SetNumSlots(#slotpos)
    inst.components.container.widgetslotpos = slotpos
    inst.components.container.widgetanimbank = "ui_krampusbag_2x8"
    inst.components.container.widgetanimbuild = "ui_krampusbag_2x8"
    inst.components.container.widgetpos = Vector3(-5,-120,0)
	inst.components.container.side_widget = true    
    inst.components.container.type = "pack"
	inst.components.container.onopenfn = onopen
    inst.components.container.onclosefn = onclose

	
    --inst:ListenForEvent("nighttime", function() CheckForFridge(inst) end, GetWorld())
    --inst:ListenForEvent("onclose", function() CheckForFridge(inst) end)
    return inst
end

return Prefab( "common/inventory/venus_yangsack", fn, assets) 
