Godot.FSharp.SourceGenerators
0.0.4
dotnet add package Godot.FSharp.SourceGenerators --version 0.0.4
NuGet\Install-Package Godot.FSharp.SourceGenerators -Version 0.0.4
<PackageReference Include="Godot.FSharp.SourceGenerators" Version="0.0.4" />
paket add Godot.FSharp.SourceGenerators --version 0.0.4
#r "nuget: Godot.FSharp.SourceGenerators, 0.0.4"
// Install Godot.FSharp.SourceGenerators as a Cake Addin #addin nuget:?package=Godot.FSharp.SourceGenerators&version=0.0.4 // Install Godot.FSharp.SourceGenerators as a Cake Tool #tool nuget:?package=Godot.FSharp.SourceGenerators&version=0.0.4
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 'Generated'
csOutputFolder = "./" #Folder, relative to f# 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 }
let CustomWithReturn (node: Node) (state: State) =
(state, 1)
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 | Versions 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. |
-
net6.0
- FSharp.Compiler.Service (>= 41.0.7)
- FSharp.Core (>= 6.0.7)
- Myriad.Sdk (>= 0.8.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.