| | | 1 | | //======================================================================= |
| | | 2 | | // DefaultSaver.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | namespace Chronicler; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Provides a reusable save/apply lifecycle base for explicit state transfer helpers. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <remarks> |
| | | 14 | | /// Host integrations can use these hooks to transfer settings and configuration |
| | | 15 | | /// between a library and an editor or game engine. The host owns when each phase |
| | | 16 | | /// runs; this base class has no engine dependency. |
| | | 17 | | /// </remarks> |
| | | 18 | | public abstract class DefaultSaver |
| | | 19 | | { |
| | | 20 | | /// <summary>Capture the state to transfer.</summary> |
| | | 21 | | /// <remarks>Calls <see cref="OnSave"/> synchronously. The host decides when to run the phase.</remarks> |
| | | 22 | | public void Save() |
| | | 23 | | { |
| | 2 | 24 | | OnSave(); |
| | 2 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary>Capture the state to transfer.</summary> |
| | | 28 | | /// <remarks>Override to implement <see cref="Save"/> for the host. The default hook has no effect.</remarks> |
| | 1 | 29 | | protected virtual void OnSave() { } |
| | | 30 | | |
| | | 31 | | /// <summary>Prepare the destination for applying state.</summary> |
| | | 32 | | /// <remarks>Calls <see cref="OnEarlyApply"/> synchronously. The host decides when to run the phase.</remarks> |
| | | 33 | | public void EarlyApply() |
| | | 34 | | { |
| | 2 | 35 | | OnEarlyApply(); |
| | 2 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary>Prepare the destination for applying state.</summary> |
| | | 39 | | /// <remarks>Override to implement <see cref="EarlyApply"/> for the host. The default hook has no effect.</remarks> |
| | 1 | 40 | | protected virtual void OnEarlyApply() { } |
| | | 41 | | |
| | | 42 | | /// <summary>Apply the transferred state.</summary> |
| | | 43 | | /// <remarks>Calls <see cref="OnApply"/> synchronously. The host decides when to run the phase.</remarks> |
| | | 44 | | public void Apply() |
| | | 45 | | { |
| | 2 | 46 | | OnApply(); |
| | 2 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary>Apply the transferred state.</summary> |
| | | 50 | | /// <remarks>Override to implement <see cref="Apply"/> for the host. The default hook has no effect.</remarks> |
| | 1 | 51 | | protected virtual void OnApply() { } |
| | | 52 | | |
| | | 53 | | /// <summary>Finish applying state and reconnect dependent host state.</summary> |
| | | 54 | | /// <remarks>Calls <see cref="OnLateApply"/> synchronously. The host decides when to run the phase.</remarks> |
| | | 55 | | public void LateApply() |
| | | 56 | | { |
| | 2 | 57 | | OnLateApply(); |
| | 2 | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary>Finish applying state and reconnect dependent host state.</summary> |
| | | 61 | | /// <remarks>Override to implement <see cref="LateApply"/> for the host. The default hook has no effect.</remarks> |
| | 1 | 62 | | protected virtual void OnLateApply() { } |
| | | 63 | | } |