mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-24 08:31:32 -04:00
996 lines
23 KiB
Plaintext
996 lines
23 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;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"HasSpecialStuff.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 HasSpecialStuff : SpacetimeDB.DatabaseTable<HasSpecialStuff, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "identity")]
|
|
public SpacetimeDB.Identity Identity;
|
|
[DataMember(Name = "address")]
|
|
public SpacetimeDB.Address Address;
|
|
|
|
public HasSpecialStuff(
|
|
SpacetimeDB.Identity Identity,
|
|
SpacetimeDB.Address Address
|
|
)
|
|
{
|
|
this.Identity = Identity;
|
|
this.Address = Address;
|
|
}
|
|
|
|
public HasSpecialStuff()
|
|
{
|
|
this.Identity = new();
|
|
this.Address = new();
|
|
}
|
|
|
|
public static IEnumerable<HasSpecialStuff> FilterByIdentity(SpacetimeDB.Identity value)
|
|
{
|
|
return Query(x => x.Identity == value);
|
|
}
|
|
|
|
public static IEnumerable<HasSpecialStuff> FilterByAddress(SpacetimeDB.Address value)
|
|
{
|
|
return Query(x => x.Address == value);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
'''
|
|
"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;
|
|
|
|
public PkMultiIdentity(
|
|
uint Id,
|
|
uint Other
|
|
)
|
|
{
|
|
this.Id = Id;
|
|
this.Other = Other;
|
|
}
|
|
|
|
public PkMultiIdentity()
|
|
{
|
|
}
|
|
|
|
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 Point(
|
|
long X,
|
|
long Y
|
|
)
|
|
{
|
|
this.X = X;
|
|
this.Y = Y;
|
|
}
|
|
|
|
public Point()
|
|
{
|
|
}
|
|
|
|
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 Private(
|
|
string Name
|
|
)
|
|
{
|
|
this.Name = Name;
|
|
}
|
|
|
|
public Private()
|
|
{
|
|
this.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;
|
|
}
|
|
}
|
|
|
|
}
|
|
'''
|
|
"RepeatingTestArg.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 RepeatingTestArg : SpacetimeDB.DatabaseTableWithPrimaryKey<RepeatingTestArg, SpacetimeDB.ReducerEvent>
|
|
{
|
|
[DataMember(Name = "prev_time")]
|
|
public ulong PrevTime;
|
|
[DataMember(Name = "scheduled_id")]
|
|
public ulong ScheduledId;
|
|
[DataMember(Name = "scheduled_at")]
|
|
public SpacetimeDB.ScheduleAt ScheduledAt;
|
|
|
|
public RepeatingTestArg(
|
|
ulong PrevTime,
|
|
ulong ScheduledId,
|
|
SpacetimeDB.ScheduleAt ScheduledAt
|
|
)
|
|
{
|
|
this.PrevTime = PrevTime;
|
|
this.ScheduledId = ScheduledId;
|
|
this.ScheduledAt = ScheduledAt;
|
|
}
|
|
|
|
public RepeatingTestArg()
|
|
{
|
|
this.ScheduledAt = null!;
|
|
}
|
|
|
|
private static Dictionary<ulong, RepeatingTestArg> ScheduledId_Index = new(16);
|
|
|
|
public override void InternalOnValueInserted()
|
|
{
|
|
ScheduledId_Index[ScheduledId] = this;
|
|
}
|
|
|
|
public override void InternalOnValueDeleted()
|
|
{
|
|
ScheduledId_Index.Remove(ScheduledId);
|
|
}
|
|
|
|
public static IEnumerable<RepeatingTestArg> FilterByPrevTime(ulong value)
|
|
{
|
|
return Query(x => x.PrevTime == value);
|
|
}
|
|
|
|
public static RepeatingTestArg? FindByScheduledId(ulong value)
|
|
{
|
|
ScheduledId_Index.TryGetValue(value, out var r);
|
|
return r;
|
|
}
|
|
|
|
public static IEnumerable<RepeatingTestArg> FilterByScheduledId(ulong value)
|
|
{
|
|
if (FindByScheduledId(value) is {} found)
|
|
{
|
|
yield return found;
|
|
}
|
|
}
|
|
|
|
public override object GetPrimaryKeyValue() => ScheduledId;
|
|
|
|
}
|
|
}
|
|
'''
|
|
"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 SpacetimeDB.RepeatingTestArg Arg = new();
|
|
}
|
|
|
|
public static partial class Reducer
|
|
{
|
|
public delegate void RepeatingTestHandler(ReducerEvent reducerEvent, SpacetimeDB.RepeatingTestArg arg);
|
|
public static event RepeatingTestHandler? OnRepeatingTestEvent;
|
|
|
|
public static void RepeatingTest(SpacetimeDB.RepeatingTestArg arg)
|
|
{
|
|
SpacetimeDBClient.instance.InternalCallReducer(new RepeatingTestArgsStruct { Arg = arg });
|
|
}
|
|
|
|
public static bool OnRepeatingTest(ReducerEvent reducerEvent, RepeatingTestArgsStruct args)
|
|
{
|
|
if (OnRepeatingTestEvent == null) return false;
|
|
OnRepeatingTestEvent(
|
|
reducerEvent,
|
|
args.Arg
|
|
);
|
|
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 TestA(
|
|
uint X,
|
|
uint Y,
|
|
string Z
|
|
)
|
|
{
|
|
this.X = X;
|
|
this.Y = Y;
|
|
this.Z = Z;
|
|
}
|
|
|
|
public TestA()
|
|
{
|
|
this.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;
|
|
|
|
public TestB(
|
|
string Foo
|
|
)
|
|
{
|
|
this.Foo = Foo;
|
|
}
|
|
|
|
public TestB()
|
|
{
|
|
this.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;
|
|
|
|
public TestD(
|
|
SpacetimeDB.Namespace.Types.TestC? TestC
|
|
)
|
|
{
|
|
this.TestC = TestC;
|
|
}
|
|
|
|
public TestD()
|
|
{
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
'''
|
|
"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;
|
|
|
|
public TestE(
|
|
ulong Id,
|
|
string Name
|
|
)
|
|
{
|
|
this.Id = Id;
|
|
this.Name = Name;
|
|
}
|
|
|
|
public TestE()
|
|
{
|
|
this.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;
|
|
using SpacetimeDB.ClientApi;
|
|
|
|
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(TransactionUpdate update, IReducerArgs? args) : base(update) => 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<HasSpecialStuff>();
|
|
clientDB.AddTable<PkMultiIdentity>();
|
|
clientDB.AddTable<Point>();
|
|
clientDB.AddTable<Private>();
|
|
clientDB.AddTable<RepeatingTestArg>();
|
|
clientDB.AddTable<TestA>();
|
|
clientDB.AddTable<TestD>();
|
|
clientDB.AddTable<TestE>();
|
|
}
|
|
|
|
public static readonly SpacetimeDBClient instance = new();
|
|
|
|
protected override ReducerEvent ReducerEventFromDbEvent(TransactionUpdate update)
|
|
{
|
|
var encodedArgs = update.ReducerCall.Args;
|
|
IReducerArgs? args = update.ReducerCall.ReducerName switch {
|
|
"add_player" => BSATNHelpers.Decode<AddPlayerArgsStruct>(encodedArgs),
|
|
"add_private" => BSATNHelpers.Decode<AddPrivateArgsStruct>(encodedArgs),
|
|
"delete_player" => BSATNHelpers.Decode<DeletePlayerArgsStruct>(encodedArgs),
|
|
"delete_players_by_name" => BSATNHelpers.Decode<DeletePlayersByNameArgsStruct>(encodedArgs),
|
|
"query_private" => BSATNHelpers.Decode<QueryPrivateArgsStruct>(encodedArgs),
|
|
"repeating_test" => BSATNHelpers.Decode<RepeatingTestArgsStruct>(encodedArgs),
|
|
"test" => BSATNHelpers.Decode<TestArgsStruct>(encodedArgs),
|
|
"<none>" => null,
|
|
"__identity_connected__" => null,
|
|
"__identity_disconnected__" => null,
|
|
"" => null,
|
|
var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
|
|
};
|
|
return new ReducerEvent(update, 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
|
|
}
|
|
'''
|