local assets =
{
	Asset("ANIM", "anim/swap_wool_sack.zip"),
	Asset("ATLAS", "images/inventoryimages/wool_sack.xml"),
}

--local params = {}
--local containers = require "containers"
--local prev_widgetsetup=containers.widgetsetup

--[[local function mywidgetsetup(container, prefab, data)
    local t = data or params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
    end
end]]

--------------------------------------------------------------------------
--[[ wool_sack ]]
--------------------------------------------------------------------------

--[[params.wool_sack =
{
    widget =
    {
        slotpos = {},
        animbank = "ui_piggyback_2x6",
        animbuild = "ui_piggyback_2x6",
        pos = Vector3(-5, -50, 0),
    },
    issidewidget = true,
    type = "pack",
}

for y = 0, 5 do
    table.insert(params.wool_sack.widget.slotpos, Vector3(-162, -75 * y + 170, 0))
    table.insert(params.wool_sack.widget.slotpos, Vector3(-162 + 75, -75 * y + 170, 0))
end]]

--------------------------------------------------------------------------

--------------------------------------------------------------------------

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

local function onunequip(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")
    owner.AnimState:ClearOverrideSymbol("backpack")
    inst.components.container:Close(owner)
end

local function onburnt(inst)
    if inst.components.container then
        inst.components.container:DropEverything()
        inst.components.container:Close()
        inst:RemoveComponent("container")
    end

    local ash = SpawnPrefab("ash")
    ash.Transform:SetPosition(inst.Transform:GetWorldPosition())

    inst:Remove()
end

local function fn()
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("wool_sack")
    inst.AnimState:SetBuild("swap_wool_sack")
    inst.AnimState:PlayAnimation("anim")

	inst.MiniMapEntity:SetIcon("minimap_wool_sack.tex")

	inst:AddTag("backpack")
    inst:AddTag("waterproofer")

	inst.foleysound = "dontstarve/movement/foley/backpack"

	inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/wool_sack.xml"
    inst.components.inventoryitem.cangoincontainer = false

	inst:AddComponent("equippable")
	if EQUIPSLOTS["BACK"] then
		inst.components.equippable.equipslot = EQUIPSLOTS.BACK
	elseif EQUIPSLOTS["PACK"] then
		inst.components.equippable.equipslot = EQUIPSLOTS.PACK
	else
		inst.components.equippable.equipslot = EQUIPSLOTS.BODY
	end

	inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)

    inst:AddComponent("waterproofer")
    inst.components.waterproofer:SetEffectiveness(0)

	inst:AddComponent("container")
	--containers.widgetsetup = mywidgetsetup
	inst.components.container:WidgetSetup("wool_sack")
	--containers.widgetsetup = prev_widgetsetup

	MakeSmallBurnable(inst)
    MakeSmallPropagator(inst)
    inst.components.burnable:SetOnBurntFn(onburnt)

    MakeHauntableLaunchAndDropFirstItem(inst)

    return inst
end

STRINGS.NAMES.WOOL_SACK 								= "Wool Sack"
STRINGS.RECIPE_DESC.WOOL_SACK 							= "Carries a lot and does not slow you down."

STRINGS.CHARACTERS.GENERIC.DESCRIBE.WOOL_SACK  			= "Feels like a steel scrubber on my back"
STRINGS.CHARACTERS.WILLOW.DESCRIBE.WOOL_SACK  			= "It's like a big, metal fuzz ball."
STRINGS.CHARACTERS.WOLFGANG.DESCRIBE.WOOL_SACK 			= "Is like my chest hair."
STRINGS.CHARACTERS.WENDY.DESCRIBE.WOOL_SACK 			= "Not as fuzzy as it appears to be."
STRINGS.CHARACTERS.WX78.DESCRIBE.WOOL_SACK 				= "METALLIC SACK MADE FROM ORGANIC MATTER."
STRINGS.CHARACTERS.WICKERBOTTOM.DESCRIBE.WOOL_SACK 		= "It seems to make its contents feel lighter."
STRINGS.CHARACTERS.WOODIE.DESCRIBE.WOOL_SACK 			= "A back scratcher."
STRINGS.CHARACTERS.WAXWELL.DESCRIBE.WOOL_SACK 			= "Scratches any back itches away."
STRINGS.CHARACTERS.WATHGRITHR.DESCRIBE.WOOL_SACK 		= "This sack is evidence of my triumphant battle!"
STRINGS.CHARACTERS.WEBBER.DESCRIBE.WOOL_SACK			= "It's like a massive scrubber!"

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