File tree 2 files changed +14
-2
lines changed
EcsRx.Examples/ExampleApps/LoadingEntityDatabase
EcsRx.Plugins.Persistence
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public class LoadingEntityDatabaseApplication : EcsRxPersistedApplication
15
15
16
16
// Tell it to look for the JSON file now rather than the binary one
17
17
public override string EntityDatabaseFile => JsonEntityDatabaseModule . CustomEntityDatabaseFile ;
18
-
18
+
19
19
private bool _quit ;
20
20
21
21
protected override void LoadModules ( )
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ public abstract class EcsRxPersistedApplication : EcsRxApplication
14
14
public ILoadEntityDatabasePipeline LoadEntityDatabasePipeline ;
15
15
16
16
public virtual string EntityDatabaseFile => PersistityModule . DefaultEntityDatabaseFile ;
17
+ public virtual bool LoadOnStart => true ;
18
+ public virtual bool SaveOnStop => true ;
17
19
18
20
protected override void LoadPlugins ( )
19
21
{
@@ -26,7 +28,9 @@ protected override void ResolveApplicationDependencies()
26
28
SaveEntityDatabasePipeline = Container . Resolve < ISaveEntityDatabasePipeline > ( ) ;
27
29
LoadEntityDatabasePipeline = Container . Resolve < ILoadEntityDatabasePipeline > ( ) ;
28
30
29
- LoadEntityDatabase ( ) . Wait ( ) ;
31
+ if ( LoadOnStart )
32
+ { LoadEntityDatabase ( ) . Wait ( ) ; }
33
+
30
34
base . ResolveApplicationDependencies ( ) ;
31
35
}
32
36
@@ -45,5 +49,13 @@ protected virtual Task SaveEntityDatabase()
45
49
// Update our database with any changes that have happened since it loaded
46
50
return SaveEntityDatabasePipeline . Execute ( EntityCollectionManager . EntityDatabase , null ) ;
47
51
}
52
+
53
+ public override void StopApplication ( )
54
+ {
55
+ if ( SaveOnStop )
56
+ { SaveEntityDatabase ( ) . Wait ( ) ; }
57
+
58
+ base . StopApplication ( ) ;
59
+ }
48
60
}
49
61
}
You can’t perform that action at this time.
0 commit comments