GodotInputMapper.SourceGenerator 0.1.3

dotnet add package GodotInputMapper.SourceGenerator --version 0.1.3
                    
NuGet\Install-Package GodotInputMapper.SourceGenerator -Version 0.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GodotInputMapper.SourceGenerator" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GodotInputMapper.SourceGenerator" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="GodotInputMapper.SourceGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GodotInputMapper.SourceGenerator --version 0.1.3
                    
#r "nuget: GodotInputMapper.SourceGenerator, 0.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GodotInputMapper.SourceGenerator@0.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GodotInputMapper.SourceGenerator&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=GodotInputMapper.SourceGenerator&version=0.1.3
                    
Install as a Cake Tool

Godot Input Mapper

A source generator based package designed to make nicer C# API for Godot's Input system.

Goals:

  • Ergonimc API with sensible defaults
  • Easy support for multiple Players across multiple devices
  • Elimiation/Minimisation of string references and runtime errors

⚠️ Work in progress

Examples

//Example Decoration on an Analog Stick
[MapToInput("Look", MapToInputAttribute.InputLevel.Getter)]
public Vector2 LookDirection => _lookDirection;

//Generates:
private Vector2 _lookDirection => Input.GetVector( "Look_-X", "Look_+X",  "Look_-Y",  "Look_+Y");
//Example Decoration on an Trigger
[InputMapPlayerIndex(nameof(PlayerIndex))]
public partial class PlayerController : Node {

    [Export]
    public int PlayerIndex = 0;

    [MapToInput("Shoot", MapToInputAttribute.InputLevel.Getter)]
    public float Shooting => _shooting;

}
//Generates:
public partial class PlayerController : Node {
    private float _shooting  => Input.GetActionStrength("Shoot_" + PlayerIndex);
}
//Example Decoration on Delegate to fire event.
[Signal]
[MapToInput("Aim", MapToInputAttribute.InputLevel._UnhandledInput, true)]
public delegate void AimEventHandler(bool isPressed);

public override partial void _UnhandledInput(InputEvent evt);


//Generates
public override partial void _UnhandledInput(InputEvent evt)
{
    if(evt.IsActionPressed("Aim_" + PlayerIndex)) 
    {
        EmitSignal(SignalName.Aim,true);
        GetViewport().SetInputAsHandled();
    }
    else if(evt.IsActionReleased("Aim_" + PlayerIndex)) 
    {
        EmitSignal(SignalName.Aim,false);
        GetViewport().SetInputAsHandled();
    }
}

Usage

The Attribute [MapToInput] can be used to decorate Properties and Delegates on any class that inherits from Node.

  • The first parameter, ActionName, is required, it's the first stub of the Action Name defined in the InputMap/Project settings. It can be modified based on the property type such as Vector2 or use of [InputMapPlayerIndex].
  • The second parameter, Level, is also required, it's an enum with the options:
    • MapToInputAttribute.InputLevel.Getter : Places the check in a Get method. Useful for checking input in a _Process. Uses InputMap.
    • MapToInputAttribute.InputLevel._UnhandledInput : Places the check in a an _UnhandledInput callback. Useful for delegates. Requires partial method specification
    • MapToInputAttribute.InputLevel._Input: Places the check in a an _Input callback useful for GUI checks. Requires partial method specification
  • The third parameter, HandleInput, defaults to false, and decides whether to call Viewport.SetInputAsHandled();
  • The fourth parameter, FireOnRelease, defaults to true, relates only to delegates and expects the delegate to have a single bool property True when IsActionPressed and False when IsActionReleased

Acceptable Property types are:

  • Vector2
  • float
  • bool

Acceptable Delegate return types are void and with either no parameters or a single bool depending on if FireOnRelease is true.

TODO

  • Ensure InputMap is setup properly, setting it up if needed.
  • Enable Remapping or check compatibility with InputHelper
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.3 324 10/15/2023
0.1.2 142 10/15/2023
0.1.1 162 10/15/2023
0.1.0 146 10/15/2023