local assets =
{
	Asset("ANIM", "anim/gears_hat_goggles.zip"),
--	Asset("IMAGE", "images/colour_cubes/goggles_on_cc.tex"),
--	Asset("IMAGE", "images/colour_cubes/goggles_off_cc.tex"),
}

local function generic_perish(inst)
	local fin = SpawnPrefab("ruins_battery")
	fin.Transform:SetPosition(inst.Transform:GetWorldPosition())	
    inst:Remove()
end

local function goggles_perish(inst)
	if inst.components.equippable ~= nil and inst.components.equippable:IsEquipped() then
		local owner = inst.components.inventoryitem ~= nil and inst.components.inventoryitem.owner or nil
		if owner ~= nil then
			goggles_turnoff(owner)
		end
	end
	inst:Remove()
end

local function fn()
	local function onequip(inst, owner)
		owner.AnimState:OverrideSymbol("swap_hat", "gears_hat_goggles", "swap_hat")
		owner.AnimState:Show("HAT")
		owner.AnimState:Show("HAT_HAIR")
	
		inst.components.fueled:StartConsuming()        
	end

	local function onunequip(inst, owner)
		owner.AnimState:Hide("HAT")
		owner.AnimState:Hide("HAT_HAIR")
	
		if owner:HasTag("player") then
			owner.AnimState:Show("HEAD")
			owner.AnimState:Hide("HEAD_HAIR")
		end
		
		inst.components.fueled:StopConsuming()      
	end
	
	local function goggles_onequip(inst, owner)
        onequip(inst, owner)
		owner.SoundEmitter:PlaySound("dontstarve_DLC001/common/moggles_on")
    end

    local function goggles_onunequip(inst, owner)
        onunequip(inst, owner)
		owner.SoundEmitter:PlaySound("dontstarve_DLC001/common/moggles_off")
    end
	
	local inst = CreateEntity()
	
	inst:AddTag("nightvision")
	
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddNetwork()
	
	MakeInventoryPhysics(inst) 

    inst.AnimState:SetBank("gears_hat_goggles")
    inst.AnimState:SetBuild("gears_hat_goggles")
    inst.AnimState:PlayAnimation("idle")    

	inst:AddTag("hat")
	
	inst.entity:SetPristine()
	
	if not TheWorld.ismastersim then
		return inst
	end
	
	inst:AddComponent("inspectable")
	
	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/gears_hat_goggles.xml"
	
	inst:AddComponent("tradable")
	
	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
	inst.components.equippable:SetOnEquip(goggles_onequip)
	inst.components.equippable:SetOnUnequip(goggles_onunequip)
	
	inst:AddComponent("fueled")
	inst.components.fueled.fueltype = "CAVE"
	inst.components.fueled:InitializeFuelLevel(TUNING.TOTAL_DAY_TIME*.75)
	inst.components.fueled:SetDepletedFn(goggles_perish)
	inst.components.fueled.accepting = true
	inst:AddTag("no_sewing")
	--[[
	inst:ListenForEvent("daytime", function(it)
	if GetWorld():IsCave() then return end
		if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() and not GetWorld():IsCave() then
			GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath("images/colour_cubes/goggles_off_cc.tex", 2))
		end
	end, GetWorld())
        inst:ListenForEvent("dusktime", function(it)
	if GetWorld():IsCave() then return end
		if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() then
			if GetWorld() and GetWorld().components.colourcubemanager then
                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath("images/colour_cubes/goggles_on_cc.tex", 2))
			end
		end
	end, GetWorld())
        inst:ListenForEvent("nighttime", function(it)
	if GetWorld():IsCave() then return end
		if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() then
			if GetWorld() and GetWorld().components.colourcubemanager then
                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath("images/colour_cubes/goggles_on_cc.tex", 2))
			end
		end
	end, GetWorld())
	]]
	
	MakeHauntableLaunch(inst)
	
    return inst
end

STRINGS.NAMES.GEARS_HAT_GOGGLES 							= "Gear Goggles"
STRINGS.RECIPE_DESC.GEARS_HAT_GOGGLES 						= "Renewable moggles."

STRINGS.CHARACTERS.GENERIC.DESCRIBE.GEARS_HAT_GOGGLES 		= "Fashion for the inventor."
STRINGS.CHARACTERS.WILLOW.DESCRIBE.GEARS_HAT_GOGGLES 		= "I prefer fire for lighting in the dark."
STRINGS.CHARACTERS.WOLFGANG.DESCRIBE.GEARS_HAT_GOGGLES 		= "Ha! Wolfgang no longer afraid of darkness!"
STRINGS.CHARACTERS.WENDY.DESCRIBE.GEARS_HAT_GOGGLES 		= "How boring. Why bother seeing through the darkness?"
STRINGS.CHARACTERS.WX78.DESCRIBE.GEARS_HAT_GOGGLES 			= "A TEMPORARY VISION UPGRADE"
STRINGS.CHARACTERS.WICKERBOTTOM.DESCRIBE.GEARS_HAT_GOGGLES 	= "These goggles appear to be lost technology."
STRINGS.CHARACTERS.WOODIE.DESCRIBE.GEARS_HAT_GOGGLES 		= "Fancy technological doodad."
STRINGS.CHARACTERS.WAXWELL.DESCRIBE.GEARS_HAT_GOGGLES 		= "I forgot about these."
STRINGS.CHARACTERS.WATHGRITHR.DESCRIBE.GEARS_HAT_GOGGLES 	= "The night no longer binds me."
STRINGS.CHARACTERS.WEBBER.DESCRIBE.GEARS_HAT_GOGGLES 		= "Awesome!"

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