function init()
    isActive = false
    toggleButton = FindShape("toggle-btn")
    SetTag(toggleButton, "interact", "loc@TURN_ON")

    waterPower = 0.0

    emitterLoc = FindLocation("emitter")
    emitterShape = FindShape("emitter-shape")

    local c = GetLocationTransform(emitterLoc)
    local p = GetShapeWorldTransform(emitterShape)
    emitterLocalT = TransformToLocalTransform(p, c)

    sWaterLoop = LoadLoop("tools/extinguisher-loop.ogg")
    sWaterStart = LoadSound("submerged.ogg")
end

function tick(dt)
    if InputPressed("interact") and GetPlayerInteractShape() == toggleButton then
        isActive = not isActive

        if isActive then
            SetTag(toggleButton, "interact", "loc@TURN_OFF")
            PlaySound(sWaterStart, GetShapeWorldTransform(toggleButton).pos, 0.7)
            SetValue("waterPower", 1.0, "easein", 1.5)
        else
            SetTag(toggleButton, "interact", "loc@TURN_ON")
            SetValue("waterPower", 0.0, "easeout", 1.5)
        end
    end

    if waterPower > 0.0 then
        ParticleReset()
        ParticleType("smoke")
        ParticleTile(1)
        ParticleRadius(0.2, 0.5)
        ParticleColor(0.88, 0.94, 1.0, 1,1,1)
        ParticleGravity(-9)
        ParticleAlpha(waterPower)

        local et = GetEmitterTransform()
        SpawnParticle(et.pos, QuatRotateVec(et.rot, Vec(0, 0, -8)), 2.0)
        PlayLoop(sWaterLoop, et.pos, waterPower * 0.7)

        local b = GetShapeBody(emitterShape)
        ApplyBodyImpulse(b, et.pos, QuatRotateVec(et.rot, Vec(0, 0, 1)))
    end
end

function GetEmitterTransform()
    return TransformToParentTransform(GetShapeWorldTransform(emitterShape), emitterLocalT)
end
