generated from IllusionMods/PluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
064577e
commit a80f45b
Showing
27 changed files
with
2,204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using ActionGame; | ||
using KK_PantyFairy.Events; | ||
using KK_PantyFairy.Functions; | ||
using KKAPI.MainGame; | ||
|
||
namespace KK_PantyFairy.Data | ||
{ | ||
public class PantyFairyGameController : GameCustomFunctionController | ||
{ | ||
protected override void OnGameLoad(GameSaveLoadEventArgs args) | ||
{ | ||
var data = GetExtendedData(); | ||
CustomEvents.SaveData = PantyFairySaveData.Deserialize(data); | ||
} | ||
|
||
protected override void OnGameSave(GameSaveLoadEventArgs args) | ||
{ | ||
var data = CustomEvents.SaveData.Serialize(); | ||
SetExtendedData(data); | ||
} | ||
|
||
protected override void OnDayChange(Cycle.Week day) | ||
{ | ||
PantyStealFeat.ClearDepantified(); | ||
} | ||
|
||
protected override void OnNewGame() | ||
{ | ||
CustomEvents.SaveData = new PantyFairySaveData() { Progress = StoryProgress.E1_Initial }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Reflection; | ||
using ExtensibleSaveFormat; | ||
|
||
namespace KK_PantyFairy.Data | ||
{ | ||
public sealed class PantyFairySaveData | ||
{ | ||
public StoryProgress Progress; | ||
public int EventProgress; | ||
public int PantiesStolenHeld; | ||
public int PantiesStolenTotal; | ||
public int UniformsStolenTotal; | ||
//public byte[] FairyHeroineData; | ||
|
||
#region SaveLoad | ||
|
||
private static readonly PantyFairySaveData _default = new PantyFairySaveData(); | ||
private static readonly FieldInfo[] _serializedFields = typeof(PantyFairySaveData).GetFields(BindingFlags.Public | BindingFlags.Instance); | ||
|
||
public static PantyFairySaveData Deserialize(PluginData data) | ||
{ | ||
var result = new PantyFairySaveData(); | ||
if (data != null) | ||
{ | ||
foreach (var fieldInfo in _serializedFields) | ||
{ | ||
if (data.data.TryGetValue(fieldInfo.Name, out var val)) | ||
{ | ||
try | ||
{ | ||
if (fieldInfo.FieldType.IsEnum) val = (int)val; | ||
fieldInfo.SetValue(result, val); | ||
} | ||
catch (Exception ex) | ||
{ | ||
PantyFairyPlugin.Logger.LogError($"Could not deserialize field {fieldInfo.Name} because of error: {ex.Message}"); | ||
} | ||
} | ||
} | ||
|
||
if (result.Progress == StoryProgress.Unknown || !Enum.IsDefined(typeof(StoryProgress), result.Progress)) | ||
{ | ||
result.Progress = StoryProgress.E1_Initial; | ||
PantyFairyPlugin.Logger.LogInfo("Resetting Story Progress to E1_Initial from " + result.Progress); | ||
} | ||
} | ||
else | ||
{ | ||
result.Progress = StoryProgress.E1_Initial; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public PluginData Serialize() | ||
{ | ||
var result = new PluginData { version = 1 }; | ||
foreach (var fieldInfo in _serializedFields) | ||
{ | ||
var value = fieldInfo.GetValue(this); | ||
// Check if any value is different than default, if not then don't save any data | ||
var defaultValue = fieldInfo.GetValue(_default); | ||
if (!Equals(defaultValue, value)) | ||
result.data.Add(fieldInfo.Name, value); | ||
} | ||
|
||
return result.data.Count > 0 ? result : null; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace KK_PantyFairy.Data | ||
{ | ||
/// <summary> | ||
/// Used to keep track what events to show and what skills to unlock | ||
/// </summary> | ||
public enum StoryProgress | ||
{ | ||
Unknown = 0, | ||
E1_Initial = 1, | ||
E2_Meeting = 2, | ||
E3_FirstRaid = 3, | ||
E4_SecondRaid = 4, | ||
E5_Steal = 5, | ||
E6_GustOfWind = 6, | ||
E7_Uniform = 7, | ||
Complete = 8 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using KK_PantyFairy.Data; | ||
|
||
namespace KK_PantyFairy.Events | ||
{ | ||
public class CustomEventData | ||
{ | ||
public bool Running { get; private set; } | ||
public bool Initialized { get; private set; } | ||
|
||
public readonly StoryProgress Index; | ||
private readonly Func<IDisposable> _initialize; | ||
private readonly Action<bool> _runningChanged; | ||
|
||
private IDisposable _cleanupCallback; | ||
|
||
public CustomEventData(StoryProgress index, | ||
Func<IDisposable> initialize, | ||
Action<bool> runningChanged = null) | ||
{ | ||
Index = index; | ||
_initialize = initialize; | ||
_runningChanged = runningChanged; | ||
} | ||
|
||
public void SetRunning(bool running) | ||
{ | ||
if (Running != running) | ||
{ | ||
if (running) | ||
{ | ||
if (!Initialized) | ||
{ | ||
_cleanupCallback = _initialize(); | ||
Initialized = true; | ||
} | ||
} | ||
else | ||
{ | ||
_cleanupCallback?.Dispose(); | ||
Initialized = false; | ||
} | ||
|
||
_runningChanged?.Invoke(running); | ||
|
||
Running = running; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.