local assets = 
{
	Asset("ANIM", "anim/er.zip"),
	 Asset("SOUNDPACKAGE", "sound/yy.fev"),
    Asset("SOUND", "sound/yy.fsb"),

   
	    Asset("IMAGE", "images/inventoryimages/er.tex"),
    Asset("ATLAS", "images/inventoryimages/er.xml"),
}

local prefabs = 
{
}

local function generic_perish(inst)
		inst:Remove()
		end

local function play(inst)
	
   	inst.SoundEmitter:PlaySound("yy/yy/yy", "yy/yy/yy")
   	inst:PushEvent("turnedon")


end

local function stop(inst)
	
    inst.SoundEmitter:KillSound("yy/yy/yy")


    inst:PushEvent("turnedoff")

end


local function OnEquip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_hat", "er", "swap_hat")
    owner.AnimState:Show("HAT")
	owner.AnimState:Hide("HAIR")

inst.components.fueled:StartConsuming()
 inst.Light:Enable(true)
		inst.SoundEmitter:PlaySound("yy/yy/yy", "yy/yy/yy")
   	

end

local function OnUnequip(inst, owner) 
    owner.AnimState:Hide("HAT")
    owner.AnimState:Show("HAIR")
inst.components.fueled:StopConsuming()
inst.Light:Enable(false)
 inst.SoundEmitter:KillSound("yy/yy/yy")
  

    
end

local function fn()
    local inst = CreateEntity()
    
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
	
   
if SaveGameIndex:IsModeShipwrecked() then
	MakeInventoryFloatable(inst, "anim", "anim")
end
    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("earmuffshat")
    inst.AnimState:SetBuild("er")
  inst.AnimState:PlayAnimation("anim")
  

    inst:AddTag("hat")


   
    inst:AddComponent("inspectable")

 

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "er"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/er.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
    inst.components.equippable:SetOnEquip(OnEquip)
    inst.components.equippable:SetOnUnequip(OnUnequip)
   inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL
inst:AddComponent("fueled")
		inst.components.fueled.fueltype = "USAGE"
		inst.components.fueled:InitializeFuelLevel(TUNING.TOPHAT_PERISHTIME)
		inst.components.fueled:SetDepletedFn(generic_perish)

inst.entity:AddLight()
		inst.Light:SetRadius(1)
		inst.Light:SetFalloff(1)
		inst.Light:SetIntensity(.5)
		inst.Light:SetColour(25/255,126/255,250/255)
   inst.Light:Enable(false)

    return inst
end

return Prefab("common/inventory/er", fn, assets, prefabs)
