using Godot;
using Sfs3.Client;

/**
 * Parent class of the script attached to the main node in all scenes.
 */
public abstract partial class BaseController : Control
{
    private GlobalManager global;

    protected SmartFox sfs;

    public override void _Ready()
    {
        global = (GlobalManager)GetNode("/root/GlobalManager");
    }

    /**
	 * On ESC key press, hide modals.
	 */
    public override void _UnhandledInput(InputEvent @event)
    {
        if (@event.IsActionPressed("ui_cancel"))
            HideModals();
    }

    /**
	 * When a scene is destroyed, make sure all event listeners it added to the SmartFox class instance are removed.
	 */
    public override void _ExitTree()
    {
        RemoveSmartFoxListeners();
    }

    public GlobalManager Global => global;

    /**
	 * Abstract method to be implemented by controller classes, to remove all SmartFox-related event listeners.
	 */
    public abstract void RemoveSmartFoxListeners();

    /**
	 * Abstract method to be implemented by controller classes, to hide popup modals.
	 */
    protected abstract void HideModals();
}
