Skip to content

Commit 5978b2c

Browse files
committed
Update Save/Load
Update the saveables page to show proper usage
1 parent cb762c5 commit 5978b2c

File tree

1 file changed

+23
-57
lines changed

1 file changed

+23
-57
lines changed

.vitepress/docs/api/save-system/index.md

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -64,75 +64,41 @@ public abstract class Saveable : Registerable, ISaveable
6464

6565
## Usage Examples
6666

67-
### Basic Save/Load Implementation
67+
### Using SaveableField in Quests and NPCs
68+
69+
The SaveableField attribute works with Quest and NPC classes, automatically handling the saving and loading of marked fields:
6870

6971
```csharp
70-
// Create a class that extends Saveable
71-
public class MyModData : Saveable
72+
// Define a custom data class for your save data
73+
public class OrderData
7274
{
73-
// Mark fields to be saved with the SaveableField attribute
74-
[SaveableField("playerStats")]
75-
private PlayerStats _playerStats = new PlayerStats();
76-
77-
[SaveableField("unlockedItems")]
78-
private List<string> _unlockedItems = new List<string>();
79-
80-
// Optional: Override callbacks
81-
public override void OnSaved()
82-
{
83-
Console.WriteLine("Data has been saved!");
84-
}
85-
86-
public override void OnLoaded()
87-
{
88-
Console.WriteLine($"Loaded {_unlockedItems.Count} unlocked items");
89-
RefreshUI();
90-
}
75+
public ProductDefinition? Product;
76+
public int Amount;
77+
public int Price;
9178
}
92-
```
9379

94-
### Handling Complex Objects
95-
96-
```csharp
97-
public class ModConfig : Saveable
80+
// Use it in your Quest class
81+
public class MyFancyQuest : Quest
9882
{
99-
[SaveableField("settings")]
100-
private Dictionary<string, object> _settings = new Dictionary<string, object>();
101-
102-
[SaveableField("playerProgress")]
103-
private PlayerProgress _playerProgress = new PlayerProgress();
104-
105-
// Provide helper methods to work with your data
106-
public T GetSetting<T>(string key, T defaultValue = default)
83+
// Mark the field to be automatically saved with the SaveableField attribute
84+
[SaveableField("Order")]
85+
private OrderData _orderData = new OrderData();
86+
87+
public void SetOrderAmount(int amount)
10788
{
108-
if (_settings.TryGetValue(key, out var value) && value is T typedValue)
109-
return typedValue;
110-
return defaultValue;
89+
_orderData.Amount = amount;
11190
}
11291

113-
public void SetSetting<T>(string key, T value)
92+
public void SetOrderProduct(ProductDefinition product)
11493
{
115-
_settings[key] = value;
94+
_orderData.Product = product;
11695
}
117-
}
118-
```
119-
120-
### Cross-compatibility Support
121-
122-
The save system is designed to work consistently across both Mono and Il2Cpp builds:
123-
124-
```csharp
125-
// This code works the same way in both Mono and Il2Cpp builds
126-
public class MyQuestData : Saveable
127-
{
128-
[SaveableField("questProgress")]
129-
private Dictionary<string, int> _questProgress = new Dictionary<string, int>();
13096

131-
// Method to update quest progress
132-
public void UpdateQuestProgress(string questId, int progress)
97+
public void SetOrderPrice(int price)
13398
{
134-
_questProgress[questId] = progress;
135-
// Data will be automatically saved through the Saveable system
99+
_orderData.Price = price;
136100
}
137101
}
138-
```
102+
```
103+
104+
The SaveableField attribute is recognized during the save/load process for NPC and Quest objects, and the data is automatically persisted within the current save file.

0 commit comments

Comments
 (0)