Coplt.Systems 0.13.0

dotnet add package Coplt.Systems --version 0.13.0                
NuGet\Install-Package Coplt.Systems -Version 0.13.0                
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="Coplt.Systems" Version="0.13.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Coplt.Systems --version 0.13.0                
#r "nuget: Coplt.Systems, 0.13.0"                
#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 Coplt.Systems as a Cake Addin
#addin nuget:?package=Coplt.Systems&version=0.13.0

// Install Coplt.Systems as a Cake Tool
#tool nuget:?package=Coplt.Systems&version=0.13.0                

Coplt.Systems

Automatic system (the S in ECS) scheduling and dependency injection

Examples

[System]
public partial class SysGroup1 : ISystemGroup;
    
public struct Data
{
    public int inc;
}

[System]
public readonly partial struct Sys1<T>(ref float a, int b) // di on constructor parameters
{
    // di on partial properties
    public partial ref Data Data { get; }
    public partial ref readonly Data Data2 { get; }
    
    private readonly float some = a + b;
    
    public void Update(ref int a) // di on parameters
    {
        Data.inc++;
    }
}

// use

// Build systems
var sys = new Systems();
sys.SetResource(new Data()); // Resources will be automatically dependency injected
sys.Add<Sys1<int>>();
sys.Add<SysGroup1>();

// Call update every frame
sys.Update();

// Resources can be modified and retrieved at any time (thread-safe)
var inc = sys.GetResource<Data>().inc;
Console.WriteLine(inc);
Assert.That(inc, Is.EqualTo(1));

Setting groups and order via attributes

[System(Group = typeof(SysGroup1))]
public readonly partial struct Sys4
{
    private void Update(ref Data data) => data.inc *= 2;
}

[System(Group = typeof(SysGroup1), Before = [typeof(Sys4)])]
public readonly partial struct Sys5
{
    private void Update(ref Data data) => data.inc *= 3;
}

[System(After = [typeof(SysGroup1)])]
public readonly partial struct Sys6
{
    private void Update(ref Data data) => data.inc += 3;
}

var sys = new Systems();
sys.SetResource(new Data { inc = 6 });
sys.Add<SysGroup1>();
sys.Add<Sys4>();
sys.Add<Sys5>();
sys.Add<Sys6>();

sys.Update();

var inc = sys.GetResource<Data>().inc;
Console.WriteLine(inc);
Assert.That(inc, Is.EqualTo(39));

Custom resource providers

public class NullResourceProvider : ResourceProvider<NullAttribute>
{
    public override ResRef<T> GetRef<T>(NullAttribute data, ResReq req = default)
    {
        Console.WriteLine(data.Msg);
        return default;
    }
}

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
public sealed class NullAttribute(string Msg = "") : ResourceProviderAttribute<NullResourceProvider, NullAttribute>
{
    public string Msg { get; } = Msg;

    public override NullAttribute GetData() => this;
}

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
public sealed class NullAttribute(string Msg = "") : ResourceProviderAttribute<NullResourceProvider>
{
    public string Msg { get; } = Msg;
}

[System]
public partial class NullResourceProviderSystem([Null] object? a) : ISystem
{
    [Null("Some")]
    public partial object? Some { get; set; }
    public partial object? Foo { get; set; }

    public void Update([Null] object? b) { }
}

var sys = new Systems();
sys.SetResourceProvider(new NullResourceProvider());
sys.Add<NullResourceProviderSystem>();
sys.Update();

// print: Some
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

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.13.0 77 12/23/2024
0.11.1 72 12/20/2024
0.9.1 80 12/20/2024
0.8.2 82 12/20/2024
0.7.1 95 11/21/2024
0.6.0 88 11/20/2024
0.5.0 90 11/20/2024