mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-24 16:41:20 -04:00
773 lines
20 KiB
Plaintext
773 lines
20 KiB
Plaintext
---
|
|
source: crates/cli/tests/codegen.rs
|
|
expression: outfiles
|
|
---
|
|
"AddPlayerReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial class AddPlayerArgsStruct : IReducerArgs
|
|
{
|
|
ReducerType IReducerArgs.ReducerType => ReducerType.AddPlayer;
|
|
string IReducerArgsBase.ReducerName => "add_player";
|
|
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnAddPlayer(reducerEvent, this);
|
|
|
|
public string Name = "";
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void AddPlayerHandler(ReducerEvent reducerEvent, string name);
|
|
public static event AddPlayerHandler? OnAddPlayerEvent;
|
|
|
|
public static void AddPlayer(string name)
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new AddPlayerArgsStruct { Name = name });
|
|
}
|
|
|
|
public static bool OnAddPlayer(ReducerEvent reducerEvent, AddPlayerArgsStruct args)
|
|
{
|
|
if (OnAddPlayerEvent == null) return false;
|
|
OnAddPlayerEvent(
|
|
reducerEvent,
|
|
args.Name
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"AddPrivateReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial class AddPrivateArgsStruct : IReducerArgs
|
|
{
|
|
ReducerType IReducerArgs.ReducerType => ReducerType.AddPrivate;
|
|
string IReducerArgsBase.ReducerName => "add_private";
|
|
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnAddPrivate(reducerEvent, this);
|
|
|
|
public string Name = "";
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void AddPrivateHandler(ReducerEvent reducerEvent, string name);
|
|
public static event AddPrivateHandler? OnAddPrivateEvent;
|
|
|
|
public static void AddPrivate(string name)
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new AddPrivateArgsStruct { Name = name });
|
|
}
|
|
|
|
public static bool OnAddPrivate(ReducerEvent reducerEvent, AddPrivateArgsStruct args)
|
|
{
|
|
if (OnAddPrivateEvent == null) return false;
|
|
OnAddPrivateEvent(
|
|
reducerEvent,
|
|
args.Name
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"DeletePlayerReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial class DeletePlayerArgsStruct : IReducerArgs
|
|
{
|
|
ReducerType IReducerArgs.ReducerType => ReducerType.DeletePlayer;
|
|
string IReducerArgsBase.ReducerName => "delete_player";
|
|
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnDeletePlayer(reducerEvent, this);
|
|
|
|
public ulong Id;
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void DeletePlayerHandler(ReducerEvent reducerEvent, ulong id);
|
|
public static event DeletePlayerHandler? OnDeletePlayerEvent;
|
|
|
|
public static void DeletePlayer(ulong id)
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new DeletePlayerArgsStruct { Id = id });
|
|
}
|
|
|
|
public static bool OnDeletePlayer(ReducerEvent reducerEvent, DeletePlayerArgsStruct args)
|
|
{
|
|
if (OnDeletePlayerEvent == null) return false;
|
|
OnDeletePlayerEvent(
|
|
reducerEvent,
|
|
args.Id
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"DeletePlayersByNameReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial class DeletePlayersByNameArgsStruct : IReducerArgs
|
|
{
|
|
ReducerType IReducerArgs.ReducerType => ReducerType.DeletePlayersByName;
|
|
string IReducerArgsBase.ReducerName => "delete_players_by_name";
|
|
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnDeletePlayersByName(reducerEvent, this);
|
|
|
|
public string Name = "";
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void DeletePlayersByNameHandler(ReducerEvent reducerEvent, string name);
|
|
public static event DeletePlayersByNameHandler? OnDeletePlayersByNameEvent;
|
|
|
|
public static void DeletePlayersByName(string name)
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new DeletePlayersByNameArgsStruct { Name = name });
|
|
}
|
|
|
|
public static bool OnDeletePlayersByName(ReducerEvent reducerEvent, DeletePlayersByNameArgsStruct args)
|
|
{
|
|
if (OnDeletePlayersByNameEvent == null) return false;
|
|
OnDeletePlayersByNameEvent(
|
|
reducerEvent,
|
|
args.Name
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"NamespaceTestC.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public partial class Namespace
|
|
{
|
|
public partial class Types
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public enum TestC
|
|
{
|
|
Foo,
|
|
Bar,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"NamespaceTestF.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public partial class Namespace
|
|
{
|
|
public partial class Types
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial record TestF : SpacetimeDB.TaggedEnum<(
|
|
SpacetimeDB.Unit Foo,
|
|
SpacetimeDB.Unit Bar,
|
|
string Baz
|
|
)>;
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"PkMultiIdentity.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
[DataContract]
|
|
public partial class PkMultiIdentity : SpacetimeDB.DatabaseTableWithPrimaryKey<PkMultiIdentity, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "id")]
|
|
public uint Id;
|
|
[DataMember(Name = "other")]
|
|
public uint Other;
|
|
|
|
private static Dictionary<uint, PkMultiIdentity> Id_Index = new(16);
|
|
private static Dictionary<uint, PkMultiIdentity> Other_Index = new(16);
|
|
|
|
public override void InternalOnValueInserted()
|
|
{
|
|
Id_Index[Id] = this;
|
|
Other_Index[Other] = this;
|
|
}
|
|
|
|
public override void InternalOnValueDeleted()
|
|
{
|
|
Id_Index.Remove(Id);
|
|
Other_Index.Remove(Other);
|
|
}
|
|
|
|
public static PkMultiIdentity? FindById(uint value)
|
|
{
|
|
Id_Index.TryGetValue(value, out var r);
|
|
return r;
|
|
}
|
|
|
|
public static IEnumerable<PkMultiIdentity> FilterById(uint value)
|
|
{
|
|
if (FindById(value) is {} found)
|
|
{
|
|
yield return found;
|
|
}
|
|
}
|
|
|
|
public static PkMultiIdentity? FindByOther(uint value)
|
|
{
|
|
Other_Index.TryGetValue(value, out var r);
|
|
return r;
|
|
}
|
|
|
|
public static IEnumerable<PkMultiIdentity> FilterByOther(uint value)
|
|
{
|
|
if (FindByOther(value) is {} found)
|
|
{
|
|
yield return found;
|
|
}
|
|
}
|
|
|
|
public override object GetPrimaryKeyValue() => Id;
|
|
|
|
}
|
|
}
|
|
'''
|
|
"Point.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
[DataContract]
|
|
public partial class Point : SpacetimeDB.DatabaseTable<Point, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "x")]
|
|
public long X;
|
|
[DataMember(Name = "y")]
|
|
public long Y;
|
|
|
|
public static IEnumerable<Point> FilterByX(long value)
|
|
{
|
|
return Query(x => x.X == value);
|
|
}
|
|
|
|
public static IEnumerable<Point> FilterByY(long value)
|
|
{
|
|
return Query(x => x.Y == value);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
'''
|
|
"Private.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
[DataContract]
|
|
public partial class Private : SpacetimeDB.DatabaseTable<Private, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "name")]
|
|
public string Name = "";
|
|
|
|
public static IEnumerable<Private> FilterByName(string value)
|
|
{
|
|
return Query(x => x.Name == value);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
'''
|
|
"QueryPrivateReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial class QueryPrivateArgsStruct : IReducerArgs
|
|
{
|
|
ReducerType IReducerArgs.ReducerType => ReducerType.QueryPrivate;
|
|
string IReducerArgsBase.ReducerName => "query_private";
|
|
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnQueryPrivate(reducerEvent, this);
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void QueryPrivateHandler(ReducerEvent reducerEvent);
|
|
public static event QueryPrivateHandler? OnQueryPrivateEvent;
|
|
|
|
public static void QueryPrivate()
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new QueryPrivateArgsStruct { });
|
|
}
|
|
|
|
public static bool OnQueryPrivate(ReducerEvent reducerEvent, QueryPrivateArgsStruct args)
|
|
{
|
|
if (OnQueryPrivateEvent == null) return false;
|
|
OnQueryPrivateEvent(
|
|
reducerEvent
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"RepeatingTestReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial class RepeatingTestArgsStruct : IReducerArgs
|
|
{
|
|
ReducerType IReducerArgs.ReducerType => ReducerType.RepeatingTest;
|
|
string IReducerArgsBase.ReducerName => "repeating_test";
|
|
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnRepeatingTest(reducerEvent, this);
|
|
|
|
public ulong PrevTime;
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void RepeatingTestHandler(ReducerEvent reducerEvent, ulong prevTime);
|
|
public static event RepeatingTestHandler? OnRepeatingTestEvent;
|
|
|
|
public static void RepeatingTest(ulong prevTime)
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new RepeatingTestArgsStruct { PrevTime = prevTime });
|
|
}
|
|
|
|
public static bool OnRepeatingTest(ReducerEvent reducerEvent, RepeatingTestArgsStruct args)
|
|
{
|
|
if (OnRepeatingTestEvent == null) return false;
|
|
OnRepeatingTestEvent(
|
|
reducerEvent,
|
|
args.PrevTime
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"TestA.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
[DataContract]
|
|
public partial class TestA : SpacetimeDB.DatabaseTable<TestA, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "x")]
|
|
public uint X;
|
|
[DataMember(Name = "y")]
|
|
public uint Y;
|
|
[DataMember(Name = "z")]
|
|
public string Z = "";
|
|
|
|
public static IEnumerable<TestA> FilterByX(uint value)
|
|
{
|
|
return Query(x => x.X == value);
|
|
}
|
|
|
|
public static IEnumerable<TestA> FilterByY(uint value)
|
|
{
|
|
return Query(x => x.Y == value);
|
|
}
|
|
|
|
public static IEnumerable<TestA> FilterByZ(string value)
|
|
{
|
|
return Query(x => x.Z == value);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
'''
|
|
"TestB.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
[DataContract]
|
|
public partial class TestB
|
|
{
|
|
[DataMember(Name = "foo")]
|
|
public string Foo = "";
|
|
|
|
}
|
|
}
|
|
'''
|
|
"TestD.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
[DataContract]
|
|
public partial class TestD : SpacetimeDB.DatabaseTable<TestD, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "test_c")]
|
|
public SpacetimeDB.Namespace.Types.TestC? TestC;
|
|
|
|
|
|
}
|
|
}
|
|
'''
|
|
"TestE.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
[DataContract]
|
|
public partial class TestE : SpacetimeDB.DatabaseTableWithPrimaryKey<TestE, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "id")]
|
|
public ulong Id;
|
|
[DataMember(Name = "name")]
|
|
public string Name = "";
|
|
|
|
private static Dictionary<ulong, TestE> Id_Index = new(16);
|
|
|
|
public override void InternalOnValueInserted()
|
|
{
|
|
Id_Index[Id] = this;
|
|
}
|
|
|
|
public override void InternalOnValueDeleted()
|
|
{
|
|
Id_Index.Remove(Id);
|
|
}
|
|
|
|
public static TestE? FindById(ulong value)
|
|
{
|
|
Id_Index.TryGetValue(value, out var r);
|
|
return r;
|
|
}
|
|
|
|
public static IEnumerable<TestE> FilterById(ulong value)
|
|
{
|
|
if (FindById(value) is {} found)
|
|
{
|
|
yield return found;
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<TestE> FilterByName(string value)
|
|
{
|
|
return Query(x => x.Name == value);
|
|
}
|
|
|
|
public override object GetPrimaryKeyValue() => Id;
|
|
|
|
}
|
|
}
|
|
'''
|
|
"TestReducer.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
[SpacetimeDB.Type]
|
|
public partial class TestArgsStruct : IReducerArgs
|
|
{
|
|
ReducerType IReducerArgs.ReducerType => ReducerType.Test;
|
|
string IReducerArgsBase.ReducerName => "test";
|
|
bool IReducerArgs.InvokeHandler(ReducerEvent reducerEvent) => Reducer.OnTest(reducerEvent, this);
|
|
|
|
public SpacetimeDB.TestA Arg = new();
|
|
public SpacetimeDB.TestB Arg2 = new();
|
|
public SpacetimeDB.Namespace.Types.TestC Arg3;
|
|
public SpacetimeDB.Namespace.TestF Arg4 = null!;
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void TestHandler(ReducerEvent reducerEvent, SpacetimeDB.TestA arg, SpacetimeDB.TestB arg2, SpacetimeDB.Namespace.Types.TestC arg3, SpacetimeDB.Namespace.TestF arg4);
|
|
public static event TestHandler? OnTestEvent;
|
|
|
|
public static void Test(SpacetimeDB.TestA arg, SpacetimeDB.TestB arg2, SpacetimeDB.Namespace.Types.TestC arg3, SpacetimeDB.Namespace.TestF arg4)
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new TestArgsStruct { Arg = arg, Arg2 = arg2, Arg3 = arg3, Arg4 = arg4 });
|
|
}
|
|
|
|
public static bool OnTest(ReducerEvent reducerEvent, TestArgsStruct args)
|
|
{
|
|
if (OnTestEvent == null) return false;
|
|
OnTestEvent(
|
|
reducerEvent,
|
|
args.Arg,
|
|
args.Arg2,
|
|
args.Arg3,
|
|
args.Arg4
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"_Globals/SpacetimeDBClient.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
public enum ReducerType
|
|
{
|
|
None,
|
|
AddPlayer,
|
|
AddPrivate,
|
|
DeletePlayer,
|
|
DeletePlayersByName,
|
|
QueryPrivate,
|
|
RepeatingTest,
|
|
Test,
|
|
}
|
|
|
|
public interface IReducerArgs : IReducerArgsBase
|
|
{
|
|
ReducerType ReducerType { get; }
|
|
bool InvokeHandler(ReducerEvent reducerEvent);
|
|
}
|
|
|
|
public partial class ReducerEvent : ReducerEventBase
|
|
{
|
|
public IReducerArgs? Args { get; }
|
|
|
|
public string ReducerName => Args?.ReducerName ?? "<none>";
|
|
|
|
[Obsolete("ReducerType is deprecated, please match directly on type of .Args instead.")]
|
|
public ReducerType Reducer => Args?.ReducerType ?? ReducerType.None;
|
|
|
|
public ReducerEvent(IReducerArgs? args) : base() => Args = args;
|
|
public ReducerEvent(ClientApi.Event dbEvent, IReducerArgs? args) : base(dbEvent) => Args = args;
|
|
|
|
[Obsolete("Accessors that implicitly cast `Args` are deprecated, please match `Args` against the desired type explicitly instead.")]
|
|
public AddPlayerArgsStruct AddPlayerArgs => (AddPlayerArgsStruct)Args!;
|
|
[Obsolete("Accessors that implicitly cast `Args` are deprecated, please match `Args` against the desired type explicitly instead.")]
|
|
public AddPrivateArgsStruct AddPrivateArgs => (AddPrivateArgsStruct)Args!;
|
|
[Obsolete("Accessors that implicitly cast `Args` are deprecated, please match `Args` against the desired type explicitly instead.")]
|
|
public DeletePlayerArgsStruct DeletePlayerArgs => (DeletePlayerArgsStruct)Args!;
|
|
[Obsolete("Accessors that implicitly cast `Args` are deprecated, please match `Args` against the desired type explicitly instead.")]
|
|
public DeletePlayersByNameArgsStruct DeletePlayersByNameArgs => (DeletePlayersByNameArgsStruct)Args!;
|
|
[Obsolete("Accessors that implicitly cast `Args` are deprecated, please match `Args` against the desired type explicitly instead.")]
|
|
public QueryPrivateArgsStruct QueryPrivateArgs => (QueryPrivateArgsStruct)Args!;
|
|
[Obsolete("Accessors that implicitly cast `Args` are deprecated, please match `Args` against the desired type explicitly instead.")]
|
|
public RepeatingTestArgsStruct RepeatingTestArgs => (RepeatingTestArgsStruct)Args!;
|
|
[Obsolete("Accessors that implicitly cast `Args` are deprecated, please match `Args` against the desired type explicitly instead.")]
|
|
public TestArgsStruct TestArgs => (TestArgsStruct)Args!;
|
|
|
|
public override bool InvokeHandler() => Args?.InvokeHandler(this) ?? false;
|
|
}
|
|
|
|
public class SpacetimeDBClient : SpacetimeDBClientBase<ReducerEvent>
|
|
{
|
|
protected SpacetimeDBClient()
|
|
{
|
|
clientDB.AddTable<PkMultiIdentity>();
|
|
clientDB.AddTable<Point>();
|
|
clientDB.AddTable<Private>();
|
|
clientDB.AddTable<TestA>();
|
|
clientDB.AddTable<TestD>();
|
|
clientDB.AddTable<TestE>();
|
|
}
|
|
|
|
public static readonly SpacetimeDBClient instance = new();
|
|
|
|
protected override ReducerEvent ReducerEventFromDbEvent(ClientApi.Event dbEvent)
|
|
{
|
|
var argBytes = dbEvent.FunctionCall.ArgBytes;
|
|
IReducerArgs? args = dbEvent.FunctionCall.Reducer switch {
|
|
"add_player" => BSATNHelpers.FromProtoBytes<AddPlayerArgsStruct>(argBytes),
|
|
"add_private" => BSATNHelpers.FromProtoBytes<AddPrivateArgsStruct>(argBytes),
|
|
"delete_player" => BSATNHelpers.FromProtoBytes<DeletePlayerArgsStruct>(argBytes),
|
|
"delete_players_by_name" => BSATNHelpers.FromProtoBytes<DeletePlayersByNameArgsStruct>(argBytes),
|
|
"query_private" => BSATNHelpers.FromProtoBytes<QueryPrivateArgsStruct>(argBytes),
|
|
"repeating_test" => BSATNHelpers.FromProtoBytes<RepeatingTestArgsStruct>(argBytes),
|
|
"test" => BSATNHelpers.FromProtoBytes<TestArgsStruct>(argBytes),
|
|
"<none>" => null,
|
|
"__identity_connected__" => null,
|
|
"__identity_disconnected__" => null,
|
|
"" => null,
|
|
var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
|
|
};
|
|
return new ReducerEvent(dbEvent, args);
|
|
}
|
|
}
|
|
}
|
|
'''
|
|
"_Globals/UnityNetworkManager.cs" = '''
|
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
|
|
// <auto-generated />
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
|
|
namespace SpacetimeDB
|
|
{
|
|
// This class is only used in Unity projects.
|
|
// Attach this to a gameobject in your scene to use SpacetimeDB.
|
|
#if UNITY_5_3_OR_NEWER
|
|
public class UnityNetworkManager : UnityEngine.MonoBehaviour
|
|
{
|
|
private void OnDestroy() => SpacetimeDBClient.instance.Close();
|
|
private void Update() => SpacetimeDBClient.instance.Update();
|
|
}
|
|
#endif
|
|
}
|
|
'''
|