-
Notifications
You must be signed in to change notification settings - Fork 54
AutoSync
Garrett Luskey edited this page Sep 22, 2024
·
5 revisions
The Autosync framework through immense pain magic (aka Reflection.Emit) will sync data automatically between the server and all clients.
Currently the Autosync framework only provides server controlled functionality.
- If a auto synced value is changed on the server it will update for all clients
- If a auto synced value is changed on the client it will not set the value and log an error
- Lifetime sync is setup for your declaring class and the type of the field (if it is a class/struct, native types work by default)
- Declaring class - The class that contains the field
- Sync - State is updated to match the controlling entity (the server in our case)
class FiefSync : IAutoSync
{
public FiefSync(IAutoSyncBuilder autoSyncBuilder)
{
// Sync a field in declaring class
autoSyncBuilder.AddField(AccessTools.Field(typeof(Fief), nameof(Fief.GarrisonPartyComponent)));
// Sync a field called by an external class/external function call (aka not in this class)
autoSyncBuilder.AddFieldChangeMethod(AccessTools.Method(typeof(TBD), nameof(Example.ExampleExternalMethod)));
// Sync a property
autoSyncBuilder.AddProperty(AccessTools.Property(typeof(Fief), nameof(Fief.FoodStocks)));
}
}
WARNING: Setting the field directly in the test will not trigger a field changed event. To do so get the field set intercept from the environment from the example below