Skip to content

Instantly share code, notes, and snippets.

@elken
Last active July 19, 2025 08:56
Show Gist options
  • Save elken/75502acd5672896610789d5aec7c9d3a to your computer and use it in GitHub Desktop.
Save elken/75502acd5672896610789d5aec7c9d3a to your computer and use it in GitHub Desktop.
#!/bin/bash
PROJECT_NAME=${1:-fs}
SLN_FILE=$(ls *.sln | head -1)
CSPROJ_FILE=$(ls *.csproj | head -1)
# Create F# project
dotnet new classlib -o "$PROJECT_NAME" -n "$PROJECT_NAME" -lang "F#" -f net8.0 --force
pushd "$PROJECT_NAME"
dotnet add package GodotSharp
cat > "Library.fs" << EOF
namespace $PROJECT_NAME
open Godot
type GameLogic() =
let mutable isInitialized = false
member this.Initialize() =
if not isInitialized then
GD.Print("F# GameLogic initialized!")
isInitialized <- true
member this.Update(delta: float32) =
// Your game logic here
()
member this.HandleInput(event: InputEvent) =
match event with
| :? InputEventKey as keyEvent when keyEvent.Pressed ->
GD.Print(\$"F# Key pressed: {keyEvent.Keycode}")
| _ -> ()
member this.Cleanup() =
GD.Print("F# GameLogic cleanup")
isInitialized <- false
EOF
popd
cat > "${PROJECT_NAME}Node.cs" << EOF
using Godot;
using $PROJECT_NAME;
public partial class ${PROJECT_NAME}Node : Node
{
private GameLogic gameLogic;
public override void _Ready()
{
gameLogic = new GameLogic();
gameLogic.Initialize();
}
public override void _Process(double delta)
{
gameLogic.Update((float)delta);
}
public override void _Input(InputEvent @event)
{
gameLogic.HandleInput(@event);
}
public override void _ExitTree()
{
gameLogic?.Cleanup();
}
}
EOF
# Add F# project to solution and reference
dotnet sln "$SLN_FILE" add "$PROJECT_NAME/$PROJECT_NAME.fsproj"
dotnet add "$CSPROJ_FILE" reference "$PROJECT_NAME/$PROJECT_NAME.fsproj"
dotnet build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment