using Godot;

public partial class Mouth : XRCamera3D
{

    [Export]
    public float MaxEatWeight = 1.0f;

    [Export]
    public float EatGrowthFactor = 0.1f;

    [Export]
    public XRHand RightHand;
    [Export]
    public XRHand LeftHand;

    public override void _Ready()
    {
        UpdateWeights();
    }

    public void EnterMouth(Node node)
    {
        try
        {
            RigidBody3D body = (RigidBody3D)node;
            if (body.Mass > MaxEatWeight)
                return;

            UpdateWeights(body.Mass);
        }
        catch (System.InvalidCastException)
        {
            // dont give a shit
        }
    }

    void UpdateWeights(float mass = 0f)
    {
        GD.Print("Ate ", mass, "kg");
        MaxEatWeight += (mass / MaxEatWeight) * EatGrowthFactor;
        float WorldScale = MaxEatWeight;
        // ((XROrigin3D)GetParent()).WorldScale = WorldScale;
        ((Node3D)GetParent()).GlobalScale(new Vector3(WorldScale, WorldScale, WorldScale));
        RightHand.Strength = MaxEatWeight;
        LeftHand.Strength = MaxEatWeight;
        GD.Print("New MaxEatWeight: ", MaxEatWeight);
        GD.Print("New WorldScale: ", WorldScale);

        Near = 0.05f * MaxEatWeight;
        Far = 4000f * MaxEatWeight;

        GD.Print("New Near: ", Near);
        GD.Print("New Far: ", Far);
    }

}
