Class Saveable
- Namespace
- S1API.Internal.Abstraction
- Assembly
- S1API.dll
Generic wrapper for saveable classes.
public abstract class Saveable : Registerable
- Inheritance
-
Saveable
- Derived
- Inherited Members
- Extension Methods
Constructors
Saveable()
protected Saveable()
Properties
LoadOrder
Determines when this saveable should load relative to base game saveables.
public virtual SaveableLoadOrder LoadOrder { get; }
Property Value
- SaveableLoadOrder
Default is AfterBaseGame, which loads after base game entities are loaded. Override this property to return BeforeBaseGame if your mod data needs to be available before the base game's ISaveables are loaded.
Examples
public class EarlyConfigSaveable : Saveable
{
public override SaveableLoadOrder LoadOrder => SaveableLoadOrder.BeforeBaseGame;
[SaveableField("config")]
private ModConfig _config = new ModConfig();
protected override void OnLoaded()
{
// Base game entities are NOT loaded yet
ApplyGlobalSettings(_config);
}
}
Remarks
AfterBaseGame (default): Your OnLoaded() method is called after base game entities (NPCs, buildings, vehicles) have been loaded. This is the recommended setting for most mods.
BeforeBaseGame: Your OnLoaded() method is called before base game entities are loaded. Use this only if you need to set up hooks or state that the base game loading process depends on.
Note: All saveables are saved at the same time (after base game save), regardless of load order.
Methods
OnLoaded()
Called after all saveable fields have been loaded from their respective JSON files. This method can be overridden in derived classes to perform additional initialization or processing after the save data has been restored.
protected virtual void OnLoaded()
OnSaved()
Called after all saveable fields have been saved to their respective JSON files. This method can be overridden in derived classes to perform additional finalization or processing after the save data has been written to disk.
protected virtual void OnSaved()
RequestGameSave()
Requests the game to perform a save operation. If a game is not currently loaded, the request is ignored and the method returns false.
public static bool RequestGameSave()
Returns
- bool
True if a save was requested; false if the game is not in a savable state.
RequestGameSave(bool)
Requests the game to perform a save operation. If a game is not currently loaded, the request is ignored and the method returns false.
public static bool RequestGameSave(bool immediate)
Parameters
immediateboolThis parameter is ignored in v0.4.3+ (kept for backwards compatibility).
Returns
- bool
True if a save was requested; false if the game is not in a savable state.