Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make constructor of StateChart.cs protected #119

Closed
BenocxX opened this issue May 15, 2024 · 1 comment
Closed

Make constructor of StateChart.cs protected #119

BenocxX opened this issue May 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@BenocxX
Copy link

BenocxX commented May 15, 2024

Hello!

Would it be possible to make the constructor of StateChart (C# class) protected? I would like to extend the class to add custom methods for the different state charts in my game (similar to the extensions methods in the C# example, but I don't want them to be accessible on every state chart).

Example of how I want to use it with the protected constructor :

// PlayerStateChart.cs
public class PlayerStateChart : StateChart // Inherits from StateChart that inherits from NodeWrapper
{
    protected PlayerStateChart(Node wrapped) : base(wrapped)
    {
    }
    
    public new static PlayerStateChart Of(Node stateChart)
    {
        StateChart.Of(stateChart); // Will throw an exception if the node is not a state chart.
        return new PlayerStateChart(stateChart);
    }
    
    public void SetIsMovementKeyPressed(bool value) => SetExpressionProperty("is_movement_key_pressed", value);
}

// Player.cs
public override void _Ready()
{
    var stateChart = PlayerStateChart.Of(GetNode("%StateChart"));
    stateChart.SetIsMovementKeyPressed(true);
}

// Enemy.cs
public override void _Ready()
{
    var stateChart = EnemyStateChart.Of(GetNode("%StateChart"));
    stateChart.SetIsMovementKeyPressed(true); // I want an error here, this method should only be accessible via the PlayerStateChart class
}

My current solution without the protected constructor is to either manually modify the StateChart file to make the constructor protected or to make a wrapper class called PlayerStateChart that exposes the needed methods. The downside of the custom wrapper is that I loose all the other methods of the StateChart & NodeWrapper classes since the are now inside PlayerStateChart. I could make the raw state chart property public, but it does not feel like a good enough solution to me.

Thanks for your time, this Godot extension is awesome!

@derkork
Copy link
Owner

derkork commented May 17, 2024

Makes sense, I'll add this to a future version. Thanks for reporting it!

@derkork derkork added the enhancement New feature or request label May 17, 2024
@derkork derkork closed this as completed in 3a07348 Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants