Godot.FSharp.SourceGenerators 0.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Godot.FSharp.SourceGenerators --version 0.0.3                
NuGet\Install-Package Godot.FSharp.SourceGenerators -Version 0.0.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="Godot.FSharp.SourceGenerators" Version="0.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Godot.FSharp.SourceGenerators --version 0.0.3                
#r "nuget: Godot.FSharp.SourceGenerators, 0.0.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.
// Install Godot.FSharp.SourceGenerators as a Cake Addin
#addin nuget:?package=Godot.FSharp.SourceGenerators&version=0.0.3

// Install Godot.FSharp.SourceGenerators as a Cake Tool
#tool nuget:?package=Godot.FSharp.SourceGenerators&version=0.0.3                

Godot.FSharp

Godot.FSharp contains Myriad based source generators for easier usage of Godot with F#

Basic setup

  • Create a Godot project with C# Solution and Project.
  • Add F# Project to solution in same folder as C# project (Different folder needs configuration)
  • Add reference to F# Project in C# project
  • Add the Godot.FSharp.SourceGenerators.CSharp package to the C# project with the version matching the Godot.NET.Sdk version
  • Add the following to the C# Project:
<Project>
    
  <Target Name="DisableDefaultGodotSourceGenerator" BeforeTargets="CoreCompile">
    <ItemGroup>
      <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'Godot.SourceGenerators'" />
    </ItemGroup>
  </Target>
  
</Project>

Configuration (Myriad.toml)

[godot]
namespace = "MyNamespace" #Namespace for generated nodes and resources. Default is 'UnknownNamespace'
csOutputFolder = "./" #Folder, relative to project, to put generated C# files

Examples

Node

MyNode.fs
namespace MyNodes
open Godot.FSharp.SourceGenerators.ObjectGenerator

[<NodeScript>] // Node to generate
module MyNode =
    [<Node>] // Godot class to inherit from
    type Node = Godot.Node2D
    
    [<State>] // Fields of the node
    type State =
        {
           [<Export>]ExportedVariable : int
           InternalVariable : float
        }
    
    // This is mandatory
    static member Default() = { ExportedVariable = 0; InternalVariable = 0.0 }
    
    // Methods signatures need to be like this Node -> ... additional parameters ... -> State -> State 
    // Node is a reference to the base node
    // State contains the current state
    // The return value should be the the new state
    
    let _Ready (node : Node) (state: State) =
        state
    
    let _Process (node : Node) (delta: double) (state: State) =
        state
        
    let Custom (node : Node) (value : int) (state: State) =        
        { state with ExportedVariable = value }        
Project file (f#)
<Compile Include="MyNode.fs" /> 
<Compile Include="MyNode.generated.fs">
    <MyriadFile>MyNode.fs</MyriadFile>
</Compile>

If you build the solution there should now be 2 Files that are generated:

  • MyNode.generated.fs
  • MyNodes/MyNode.cs

The script to be attached in godot is MyNode.cs

Union as Resource

MyUnion.fs
module MyResources
open Godot.FSharp.SourceGenerators.ResourceGenerator

[<Resource>]
type MyUnion =
    | A of Int: int
    | B of Int: int * Float: float
    | C of String: string
    | D of int
    | E of int * float
Project file (f#)
<Compile Include="MyUnion.fs" /> 
<Compile Include="MyUnion.generated.fs">
    <MyriadFile>MyUnion.fs</MyriadFile>
</Compile>

If you build the solution there should now be 2 Files that are generated:

  • MyUnion.generated.fs
  • MyResources/MyUnion.cs

If you attach MyUnion.cs to a Resource there should be at minimum a field "Type" with a dropdown that is set to "Unset" The dropdown should, besides Unset, contain items depending on the Union. The specific values can be set after changing the Type.

Record as resource

MyRecord.fs
namespace MyResources

open Godot.FSharp.SourceGenerators.ResourceGenerator

[<Resource>]
type MyRecord =
    { a : int
      b : float
      c : string }
    static member Default = { a = 0; b = 0.0; c = "" } // Mandatory
Project file (f#)
<Compile Include="MyRecord.fs" /> 
<Compile Include="MyRecord.generated.fs">
    <MyriadFile>MyRecord.fs</MyriadFile>
</Compile>

If you build the solution there should now be 2 Files that are generated:

  • MyRecord.generated.fs

  • MyResources/MyRecord.cs

  • If you attach MyRecord.cs to a Resource it should have all fields of the record.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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.0.4 188 7/11/2023
0.0.3 162 7/9/2023
0.0.2 163 7/5/2023