require "prefabutil"

local assets =
{
	Asset("ANIM", "anim/venus_logcabin.zip"),
}

local function ontime(inst)
if GetClock():IsDay() then
inst.SoundEmitter:PlaySound("dontstarve/pig/pighut_lightoff")
inst.Light:Enable(false)
inst.AnimState:PushAnimation("idle")
elseif GetClock():IsDusk() then
inst.AnimState:PushAnimation("idle_night")
inst.SoundEmitter:PlaySound("dontstarve/pig/pighut_lighton")
inst.Light:Enable(true)
elseif GetClock():IsNight() then
inst.Light:Enable(true)
inst.AnimState:PushAnimation("idle_night")
end
end

local function fn(Sim)
	local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
	local anim = inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()
   
    
    MakeObstaclePhysics(inst, 1)    

    inst:AddTag("structure")
    anim:SetBank("venus_logcabin")
    anim:SetBuild("venus_logcabin")
    anim:PlayAnimation("idle", true)
    
	local minimap = inst.entity:AddMiniMapEntity()
	minimap:SetIcon( "venus_logcabin.tex" )
	
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("lootdropper")
	MakeSnowCovered(inst, .01)
    
	local light = inst.entity:AddLight()
	light:SetFalloff(0.5)
    light:SetIntensity(.75)
    light:SetRadius(2)
    light:Enable(false)
    light:SetColour(180/255, 195/255, 50/255)
    ontime(inst)
	inst:ListenForEvent("daytime",function() ontime(inst) end, GetWorld())
    inst:ListenForEvent("dusktime",function() ontime(inst) end, GetWorld())
    inst:ListenForEvent("nighttime",function() ontime(inst) end, GetWorld())
  
    return inst
end

return Prefab( "common/objects/venus_logcabin", fn, assets),
		MakePlacer( "common/venus_logcabin_placer", "venus_logcabin", "venus_logcabin", "idle" ) 
