-
Notifications
You must be signed in to change notification settings - Fork 43
/
CharaCustomFunctionController.cs
584 lines (532 loc) · 30.3 KB
/
CharaCustomFunctionController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
using KKAPI.Maker;
using KKAPI.Utilities;
using System;
using System.Collections;
#if KK || KKS
using KKAPI.MainGame;
using UniRx;
#elif AI || HS2
using AIChara;
#endif
using ExtensibleSaveFormat;
using UnityEngine;
#pragma warning disable 618
namespace KKAPI.Chara
{
/// <summary>
/// Base type for custom character extensions.
/// It provides many useful methods that abstract away the nasty hooks needed to figure out when
/// a character is changed or how to save and load your custom data to the character card.
///
/// This controller is a MonoBehaviour that is added to root gameObjects of ALL characters spawned into the game.
/// It's recommended to not use constructors, Awake or Start in controllers. Use <see cref="OnReload(GameMode,bool)"/> instead.
/// </summary>
public abstract class CharaCustomFunctionController : MonoBehaviour
{
private bool _wasLoaded;
/// <summary>
/// ChaControl of the character this controller is attached to. It's on the same gameObject as this controller.
/// </summary>
public ChaControl ChaControl { get; private set; }
/// <summary>
/// ChaFile of the character this controller is attached to.
/// </summary>
public ChaFileControl ChaFileControl => ChaControl.chaFile;
/// <summary>
/// ID used for extended data by this controller. It's set when registering the controller
/// with <see cref="CharacterApi.RegisterExtraBehaviour{T}(string)"/>
/// </summary>
public string ExtendedDataId => ControllerRegistration.ExtendedDataId;
/// <summary>
/// Definition of this kind of function controllers.
/// </summary>
public CharacterApi.ControllerRegistration ControllerRegistration { get; internal set; }
/// <summary>
/// True if this controller has been initialized
/// </summary>
public bool Started { get; private set; }
#region Ext data
/// <summary>
/// Get extended data based on supplied ExtendedDataId. When in chara maker loads data from character that's being loaded.
/// This should be used inside the <see cref="OnReload(KKAPI.GameMode,bool)"/> event.
/// Consider using one of the other "Get___ExtData" and "Set___ExtData" methods instead since they are more reliable and handle copying and transferring outfits and they conform to built in maker load toggles.
/// </summary>
public PluginData GetExtendedData()
{
return GetExtendedData(true);
}
/// <summary>
/// Get extended data of the current character by using the ID you specified when registering this controller.
/// This should be used inside the <see cref="OnReload(KKAPI.GameMode,bool)"/> event.
/// Consider using one of the other "Get___ExtData" and "Set___ExtData" methods instead since they are more reliable and handle copying and transferring outfits and they conform to built in maker load toggles.
/// </summary>
/// <param name="getFromLoadedChara">If true, when in chara maker load data from character that's being loaded.
/// When outside maker or false, always grab current character's data.</param>
public PluginData GetExtendedData(bool getFromLoadedChara)
{
if (ExtendedDataId == null) throw new ArgumentException(nameof(ExtendedDataId));
var chaFile = getFromLoadedChara ? MakerAPI.LastLoadedChaFile ?? ChaFileControl : ChaFileControl;
return ExtendedSave.GetExtendedDataById(chaFile, ExtendedDataId);
}
/// <summary>
/// Save your custom data to the character card under the ID you specified when registering this controller.
/// This should be used inside the <see cref="OnCardBeingSaved"/> event.
/// Consider using one of the other "Get___ExtData" and "Set___ExtData" methods instead since they are more reliable and handle copying and transferring outfits and they conform to built in maker load toggles.
/// </summary>
/// <param name="data">Your custom data to be written to the character card. Can be null to remove the data.</param>
public void SetExtendedData(PluginData data)
{
if (ExtendedDataId == null) throw new ArgumentException(nameof(ExtendedDataId));
ExtendedSave.SetExtendedDataById(ChaFileControl, ExtendedDataId, data);
#if KK || KKS
if (KoikatuAPI.GetCurrentGameMode() == GameMode.MainGame)
{
// In main game store ext data for the character inside of the main chaFile object (the one that gets saved to game saves).
// This allows saving ext data inside talk scenes and H scenes without losing it after exiting to main map.
var heroine = ChaControl.GetHeroine();
if (heroine != null)
{
ExtendedSave.SetExtendedDataById(heroine.charFile, ExtendedDataId, data);
if (ChaControl != heroine.chaCtrl)
{
ExtendedSave.SetExtendedDataById(heroine.chaCtrl.chaFile, ExtendedDataId, data);
// Update other instance to reflect the new ext data
CharacterApi.Hooks.SetDirty(heroine, true);
}
var npc = heroine.GetNPC();
if (npc != null && npc.chaCtrl != null && npc.chaCtrl != ChaControl && npc.chaCtrl != heroine.chaCtrl)
{
ExtendedSave.SetExtendedDataById(npc.chaCtrl.chaFile, ExtendedDataId, data);
// Update other instance to reflect the new ext data
CharacterApi.Hooks.SetDirty(heroine, true);
}
}
else
{
var player = ChaControl.GetPlayer();
if (player != null)
{
ExtendedSave.SetExtendedDataById(player.charFile, ExtendedDataId, data);
if (ChaControl != player.chaCtrl)
{
ExtendedSave.SetExtendedDataById(player.chaCtrl.chaFile, ExtendedDataId, data);
// Update other instance to reflect the new ext data
CharacterApi.Hooks.SetDirty(player, true);
}
}
}
}
#endif
}
/// <summary>
/// Get extended data of the specified coordinate by using the ID you specified when registering this controller.
/// This should be used inside the <see cref="OnCoordinateBeingLoaded(ChaFileCoordinate,bool)"/> event.
/// Consider using one of the other "Get___ExtData" and "Set___ExtData" methods instead since they are more reliable and handle copying and transferring outfits and they conform to built in maker load toggles.
/// </summary>
/// <param name="coordinate">Coordinate you want to get the data from</param>
public PluginData GetCoordinateExtendedData(ChaFileCoordinate coordinate)
{
if (coordinate == null) throw new ArgumentNullException(nameof(coordinate));
if (ExtendedDataId == null) throw new ArgumentException(nameof(ExtendedDataId));
return ExtendedSave.GetExtendedDataById(coordinate, ExtendedDataId);
}
/// <summary>
/// Set extended data to the specified coordinate by using the ID you specified when registering this controller.
/// This should be used inside the <see cref="OnCoordinateBeingSaved"/> event.
/// Consider using one of the other "Get___ExtData" and "Set___ExtData" methods instead since they are more reliable and handle copying and transferring outfits and they conform to built in maker load toggles.
/// </summary>
/// <param name="coordinate">Coordinate you want to set the data to</param>
/// <param name="data">Your custom data to be saved to the coordinate card</param>
public void SetCoordinateExtendedData(ChaFileCoordinate coordinate, PluginData data)
{
if (coordinate == null) throw new ArgumentNullException(nameof(coordinate));
if (ExtendedDataId == null) throw new ArgumentException(nameof(ExtendedDataId));
ExtendedSave.SetExtendedDataById(coordinate, ExtendedDataId, data);
}
#endregion
#region Events
/// <summary>
/// Fired when the character information is being saved.
/// It handles all types of saving (to character card, to a scene etc.)
/// Write any of your extended data in this method by using <see cref="SetExtendedData"/>.
/// Avoid reusing old PluginData since we might no longer be pointed to the same character.
/// </summary>
protected abstract void OnCardBeingSaved(GameMode currentGameMode);
internal void OnCardBeingSavedInternal() => OnCardBeingSavedInternal(KoikatuAPI.GetCurrentGameMode());
internal void OnCardBeingSavedInternal(GameMode gamemode)
{
if (!_wasLoaded)
{
KoikatuAPI.Logger.LogWarning("Tried to save card before it was loaded - " + ChaFileControl.GetFancyCharacterName());
return;
}
try
{
OnCardBeingSaved(gamemode);
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}
/// <summary>
/// OnReload is fired whenever the character's state needs to be updated.
/// This might be beacuse the character was just loaded into the game,
/// was replaced with a different character, etc.
/// Use this method instead of Awake and Start. It will always get called
/// before other methods, but after the character is in a usable state.
/// WARNING: Make sure to completely reset your state in this method!
/// Assume that all of your variables are no longer valid!
/// </summary>
/// <param name="currentGameMode">Game mode we are currently in</param>
/// <param name="maintainState">If true, the current state should be preserved.
/// Do not load new extended data, instead reuse what you currently have or do nothing.</param>
protected virtual void OnReload(GameMode currentGameMode, bool maintainState) { }
/// <summary>
/// OnReload is fired whenever the character's state needs to be updated.
/// This might be beacuse the character was just loaded into the game,
/// was replaced with a different character, etc.
/// Use this method instead of Awake and Start. It will always get called
/// before other methods, but after the character is in a usable state.
/// WARNING: Make sure to completely reset your state in this method!
/// Assume that all of your variables are no longer valid!
/// WARNING: Will not get fired if disabled in <see cref="CharacterApi.RegisteredHandlers"/>,
/// use overloads with maintainState parameter in that case.
/// </summary>
/// <param name="currentGameMode">Game mode we are currently in</param>
protected virtual void OnReload(GameMode currentGameMode) { }
internal void OnReloadInternal() => OnReloadInternal(KoikatuAPI.GetCurrentGameMode());
internal void OnReloadInternal(GameMode currentGameMode)
{
#if KK || KKS
if (currentGameMode == GameMode.MainGame)
CharacterApi.Hooks.SetDirty(ChaControl.GetHeroine(), false);
#endif
try
{
if (!ControllerRegistration.MaintainState)
OnReload(currentGameMode);
OnReload(currentGameMode, ControllerRegistration.MaintainState);
_wasLoaded = true;
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}
// issue with stopallcoroutines
// todo hook startcoroutine and check if active, if not then show stack trace
///// <summary>
///// Hides base StartCoroutine and runs it on the plugin instance
///// </summary>
//public new Coroutine StartCoroutine(IEnumerator routine)
//{
// return KKAPI.KoikatuAPI.Instance.StartCoroutine(routine);
//}
/// <summary>
/// Fired just before current coordinate is saved to a coordinate card. Use <see cref="SetCoordinateExtendedData"/> to save data to it.
/// You might need to wait for the next frame with <see cref="MonoBehaviour.StartCoroutine(IEnumerator)"/> before handling this.
/// </summary>
protected virtual void OnCoordinateBeingSaved(ChaFileCoordinate coordinate) { }
internal void OnCoordinateBeingSavedInternal(ChaFileCoordinate coordinate)
{
if (!_wasLoaded)
{
KoikatuAPI.Logger.LogWarning("Tried to save coordinate before the character was loaded - " + ChaFileControl.charaFileName);
}
try
{
OnCoordinateBeingSaved(coordinate);
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}
/// <summary>
/// Fired just after loading a coordinate card into the current coordinate slot.
/// Use <see cref="GetCoordinateExtendedData"/> to get save data of the loaded coordinate.
/// </summary>
/// <param name="coordinate">Coordinate being currently loaded.</param>
/// <param name="maintainState">If true, the current state should be preserved.
/// Do not load new extended data, instead reuse what you currently have or do nothing.</param>
protected virtual void OnCoordinateBeingLoaded(ChaFileCoordinate coordinate, bool maintainState) { }
/// <summary>
/// Fired just after loading a coordinate card into the current coordinate slot.
/// Use <see cref="GetCoordinateExtendedData"/> to get save data of the loaded coordinate.
/// Will not get fired if disabled in <see cref="CharacterApi.RegisteredHandlers"/>,
/// use overloads with maintainState parameter in that case.
/// </summary>
/// <param name="coordinate">Coordinate being currently loaded.</param>
protected virtual void OnCoordinateBeingLoaded(ChaFileCoordinate coordinate) { }
internal void OnCoordinateBeingLoadedInternal(ChaFileCoordinate coordinate)
{
// If the controller didn't load yet then delay the coordinate load event until after onreload to avoid losing data from coordinate
if (!_wasLoaded)
{
StartCoroutine(new WaitUntil(() => _wasLoaded).AppendCo(() => OnCoordinateBeingLoadedInternal(coordinate)));
return;
}
try
{
if (!ControllerRegistration.MaintainCoordinateState)
OnCoordinateBeingLoaded(coordinate);
OnCoordinateBeingLoaded(coordinate, ControllerRegistration.MaintainCoordinateState);
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}
#if KK || KKS
/// <summary>
/// Currently selected clothes on this character. Can subscribe to listen for changes.
/// </summary>
public BehaviorSubject<ChaFileDefine.CoordinateType> CurrentCoordinate { get; private set; }
#endif
#endregion
/// <summary>
/// Warning: When overriding make sure to call the base method at the end of your logic!
/// </summary>
protected virtual void Update()
{
// Can't remove for bacwards compatibility
}
/// <summary>
/// Warning: When overriding make sure to call the base method at the end of your logic!
/// </summary>
protected virtual void OnDestroy()
{
#if KK || KKS
CurrentCoordinate.Dispose();
#endif
}
/// <summary>
/// Warning: When overriding make sure to call the base method at the end of your logic!
/// </summary>
protected virtual void OnEnable()
{
// Order is Awake - OnEnable - Start, so need to check if we started yet
if (Started)
OnReloadInternal(KoikatuAPI.GetCurrentGameMode());
}
/// <summary>
/// Warning: When overriding make sure to call the base method at the end of your logic!
/// </summary>
protected virtual void Awake()
{
ChaControl = GetComponent<ChaControl>();
#if KK || KKS
CurrentCoordinate = new BehaviorSubject<ChaFileDefine.CoordinateType>((ChaFileDefine.CoordinateType)ChaControl.fileStatus.coordinateType);
#endif
}
/// <summary>
/// Warning: When overriding make sure to call the base method at the end of your logic!
/// </summary>
protected virtual void Start()
{
Started = true;
OnReloadInternal(KoikatuAPI.GetCurrentGameMode());
}
#region New ExtData
private ChaFileCoordinate GetCoordinate(int coordinateId)
{
// Get coord from the current ChaControl since it can be temporarily changed and would mess up ext data of clothes inside heroine.chaCtrl if we saved there
KoikatuAPI.Assert(ChaControl.nowCoordinate != null, "ChaControl.nowCoordinate != null");
#if KK || KKS
return (coordinateId < 0 ? ChaControl.nowCoordinate : ChaFileControl.coordinate[coordinateId]);
#elif EC || AI || HS2
if (coordinateId > 0) KoikatuAPI.Logger.LogWarning("This game doesn't support multiple coordinates, nowCoordinate will be used!\n" + new System.Diagnostics.StackTrace());
return ChaControl.nowCoordinate;
#endif
}
private ChaFile GetExtDataTargetChaFile(bool setDirty)
{
#if KK || KKS
// In main game store ext data for the character inside of the main chaFile object (the one that gets saved to game saves) instead of its copies.
// This allows saving ext data inside talk scenes and H scenes without losing it after exiting to main map.
if (KoikatuAPI.GetCurrentGameMode() == GameMode.MainGame)
{
var heroine = ChaControl.GetHeroine();
if (heroine != null)
{
if (setDirty)
CharacterApi.Hooks.SetDirty(heroine, true);
return heroine.charFile;
}
var player = ChaControl.GetPlayer();
if (player != null)
{
if (setDirty)
CharacterApi.Hooks.SetDirty(player, true);
return player.charFile;
}
}
#endif
return ChaFileControl;
}
/// <summary>
/// Get extended data for specific clothes.
/// Do not store this data because it might change without notice, for example when clothing is copied. Always call Get at the point where you need the data, not earlier.
/// If you change any of the data, remember to call the corresponding Set method or the change might not be saved.
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// If no extended data of this plugin was set yet, this method will return null.
/// In maker, you can update controls that use this data in the <see cref="MakerAPI.ReloadCustomInterface"/> event.
/// </summary>
/// <param name="coordinateId">The coordinate number to open extened data for if the game supports multiple coords (0-indexed). -1 will use the current coordinate.</param>
public PluginData GetClothesExtData(int coordinateId = -1)
{
var coord = GetCoordinate(coordinateId);
KoikatuAPI.Assert(coord != null, nameof(coord) + " != null");
KoikatuAPI.Assert(coord.clothes != null, "coord.clothes != null");
var clothes = coord.clothes;
clothes.TryGetExtendedDataById(ExtendedDataId, out var data);
return data;
}
/// <summary>
/// Get extended data for a specific accessory.
/// Do not store this data because it might change without notice, for example when clothing is copied. Always call Get at the point where you need the data, not earlier.
/// If you change any of the data, remember to call the corresponding Set method or the change might not be saved.
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// If no extended data of this plugin was set yet, this method will return null.
/// In maker, you can update controls that use this data in the <see cref="MakerAPI.ReloadCustomInterface"/> event.
/// </summary>
/// <param name="accessoryPartId">The accessory part number to open extened data for (0-indexed).</param>
/// <param name="coordinateId">The coordinate number to open extened data for if the game supports multiple coords (0-indexed). -1 will use the current coordinate.</param>
public PluginData GetAccessoryExtData(int accessoryPartId, int coordinateId = -1)
{
var coord = GetCoordinate(coordinateId);
KoikatuAPI.Assert(coord != null, nameof(coord) + " != null");
KoikatuAPI.Assert(coord.accessory != null, "coord.accessory != null");
var accessoryPart = coord.accessory.parts[accessoryPartId];
accessoryPart.TryGetExtendedDataById(ExtendedDataId, out var data);
return data;
}
/// <summary>
/// Get extended data for character's body (body sliders, tattoos).
/// Do not store this data because it might change without notice, for example when clothing is copied. Always call Get at the point where you need the data, not earlier.
/// If you change any of the data, remember to call the corresponding Set method or the change might not be saved.
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// If no extended data of this plugin was set yet, this method will return null.
/// In maker, you can update controls that use this data in the <see cref="MakerAPI.ReloadCustomInterface"/> event.
/// </summary>
public PluginData GetBodyExtData()
{
var chafile = GetExtDataTargetChaFile(false);
KoikatuAPI.Assert(chafile.custom != null, "chafile.custom != null");
KoikatuAPI.Assert(chafile.custom.body != null, "chafile.custom.body != null");
chafile.custom.body.TryGetExtendedDataById(ExtendedDataId, out var data);
return data;
}
/// <summary>
/// Get extended data for character's face (face sliders, eye settings).
/// Do not store this data because it might change without notice, for example when clothing is copied. Always call Get at the point where you need the data, not earlier.
/// If you change any of the data, remember to call the corresponding Set method or the change might not be saved.
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// If no extended data of this plugin was set yet, this method will return null.
/// In maker, you can update controls that use this data in the <see cref="MakerAPI.ReloadCustomInterface"/> event.
/// </summary>
public PluginData GetFaceExtData()
{
var chafile = GetExtDataTargetChaFile(false);
KoikatuAPI.Assert(chafile.custom != null, "chafile.custom != null");
KoikatuAPI.Assert(chafile.custom.face != null, "chafile.custom.face != null");
chafile.custom.face.TryGetExtendedDataById(ExtendedDataId, out var data);
return data;
}
/// <summary>
/// Get extended data for character's parameters (personality, preferences, traits).
/// Do not store this data because it might change without notice, for example when clothing is copied. Always call Get at the point where you need the data, not earlier.
/// If you change any of the data, remember to call the corresponding Set method or the change might not be saved.
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// If no extended data of this plugin was set yet, this method will return null.
/// In maker, you can update controls that use this data in the <see cref="MakerAPI.ReloadCustomInterface"/> event.
/// </summary>
public PluginData GetParameterExtData()
{
var chafile = GetExtDataTargetChaFile(false);
KoikatuAPI.Assert(chafile.parameter != null, "chafile.parameter != null");
chafile.parameter.TryGetExtendedDataById(ExtendedDataId, out var data);
return data;
}
/// <summary>
/// Set extended data for specific clothes.
/// Always call Set right after changing any of the data, or the change might not be saved if the data is changed for whatever reason (clothing change, reload, etc.)
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// </summary>
/// <param name="data">Extended data to save.</param>
/// <param name="coordinateId">The coordinate number to open extened data for if the game supports multiple coords (0-indexed). -1 will use the current coordinate.</param>
public void SetClothesExtData(PluginData data, int coordinateId = -1)
{
var coord = GetCoordinate(coordinateId);
KoikatuAPI.Assert(coord != null, nameof(coord) + " != null");
KoikatuAPI.Assert(coord.clothes != null, "coord.clothes != null");
var clothes = coord.clothes;
clothes.SetExtendedDataById(ExtendedDataId, data);
}
/// <summary>
/// Set extended data for a specific accessory.
/// Always call Set right after changing any of the data, or the change might not be saved if the data is changed for whatever reason (clothing change, reload, etc.)
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// </summary>
/// <param name="data">Extended data to save.</param>
/// <param name="accessoryPartId">The accessory part number to open extened data for (0-indexed).</param>
/// <param name="coordinateId">The coordinate number to open extened data for if the game supports multiple coords (0-indexed). -1 will use the current coordinate.</param>
public void SetAccessoryExtData(PluginData data, int accessoryPartId, int coordinateId = -1)
{
var coord = GetCoordinate(coordinateId);
KoikatuAPI.Assert(coord != null, nameof(coord) + " != null");
KoikatuAPI.Assert(coord.accessory != null, "coord.accessory != null");
var accessoryPart = coord.accessory.parts[accessoryPartId];
accessoryPart.SetExtendedDataById(ExtendedDataId, data);
}
/// <summary>
/// Set extended data for character's body (body sliders, tattoos).
/// Always call Set right after changing any of the data, or the change might not be saved if the data is changed for whatever reason (clothing change, reload, etc.)
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// </summary>
/// <param name="data">Extended data to save.</param>
public void SetBodyExtData(PluginData data)
{
var chafile = GetExtDataTargetChaFile(true);
KoikatuAPI.Assert(chafile.custom != null, "chafile.custom != null");
KoikatuAPI.Assert(chafile.custom.body != null, "chafile.custom.body != null");
chafile.custom.body.SetExtendedDataById(ExtendedDataId, data);
// Save both to the main chafile and to the current instance in case it gets saved by something
if (chafile != ChaFileControl)
ChaFileControl.custom.body.SetExtendedDataById(ExtendedDataId, data);
}
/// <summary>
/// Set extended data for character's face (face sliders, eye settings).
/// Always call Set right after changing any of the data, or the change might not be saved if the data is changed for whatever reason (clothing change, reload, etc.)
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// </summary>
/// <param name="data">Extended data to save.</param>
public void SetFaceExtData(PluginData data)
{
var chafile = GetExtDataTargetChaFile(true);
KoikatuAPI.Assert(chafile.custom != null, "chafile.custom != null");
KoikatuAPI.Assert(chafile.custom.face != null, "chafile.custom.face != null");
chafile.custom.face.SetExtendedDataById(ExtendedDataId, data);
// Save both to the main chafile and to the current instance in case it gets saved by something
if (chafile != ChaFileControl)
ChaFileControl.custom.face.SetExtendedDataById(ExtendedDataId, data);
}
/// <summary>
/// Set extended data for character's parameters (personality, preferences, traits).
/// Always call Set right after changing any of the data, or the change might not be saved if the data is changed for whatever reason (clothing change, reload, etc.)
/// This data is saved alongside game data, which means it is automatically copied and moved as necessary.
/// </summary>
/// <param name="data">Extended data to save.</param>
public void SetParameterExtData(PluginData data)
{
var chafile = GetExtDataTargetChaFile(true);
KoikatuAPI.Assert(chafile.parameter != null, "chafile.parameter != null");
chafile.parameter.SetExtendedDataById(ExtendedDataId, data);
// Save both to the main chafile and to the current instance in case it gets saved by something
if (chafile != ChaFileControl)
ChaFileControl.parameter.SetExtendedDataById(ExtendedDataId, data);
}
#endregion
}
}