Skip to content

Commit f566be7

Browse files
committed
Added options for loading/saving on start/stop
Some times people may want to just save at an arbitrary time for debugging purposes etc.
1 parent 3f0f3fe commit f566be7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/EcsRx.Examples/ExampleApps/LoadingEntityDatabase/LoadingEntityDatabaseApplication.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class LoadingEntityDatabaseApplication : EcsRxPersistedApplication
1515

1616
// Tell it to look for the JSON file now rather than the binary one
1717
public override string EntityDatabaseFile => JsonEntityDatabaseModule.CustomEntityDatabaseFile;
18-
18+
1919
private bool _quit;
2020

2121
protected override void LoadModules()

src/EcsRx.Plugins.Persistence/EcsRxPersistedApplication.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public abstract class EcsRxPersistedApplication : EcsRxApplication
1414
public ILoadEntityDatabasePipeline LoadEntityDatabasePipeline;
1515

1616
public virtual string EntityDatabaseFile => PersistityModule.DefaultEntityDatabaseFile;
17+
public virtual bool LoadOnStart => true;
18+
public virtual bool SaveOnStop => true;
1719

1820
protected override void LoadPlugins()
1921
{
@@ -26,7 +28,9 @@ protected override void ResolveApplicationDependencies()
2628
SaveEntityDatabasePipeline = Container.Resolve<ISaveEntityDatabasePipeline>();
2729
LoadEntityDatabasePipeline = Container.Resolve<ILoadEntityDatabasePipeline>();
2830

29-
LoadEntityDatabase().Wait();
31+
if(LoadOnStart)
32+
{ LoadEntityDatabase().Wait(); }
33+
3034
base.ResolveApplicationDependencies();
3135
}
3236

@@ -45,5 +49,13 @@ protected virtual Task SaveEntityDatabase()
4549
// Update our database with any changes that have happened since it loaded
4650
return SaveEntityDatabasePipeline.Execute(EntityCollectionManager.EntityDatabase, null);
4751
}
52+
53+
public override void StopApplication()
54+
{
55+
if(SaveOnStop)
56+
{ SaveEntityDatabase().Wait(); }
57+
58+
base.StopApplication();
59+
}
4860
}
4961
}

0 commit comments

Comments
 (0)