net.dreditor.progressing.handling 0.0.0-stage → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChapterTitleDisplayer.cs +42 -0
- package/ChapterTitleDisplayer.cs.meta +11 -0
- package/DREditor.Progressing.Handling.asmdef +17 -0
- package/DREditor.Progressing.Handling.asmdef.meta +7 -0
- package/FlagTriggerExtensions.cs +79 -0
- package/FlagTriggerExtensions.cs.meta +11 -0
- package/FlagTriggerHandler.cs +237 -0
- package/FlagTriggerHandler.cs.meta +11 -0
- package/FlagTriggerHandlerBase.cs +66 -0
- package/FlagTriggerHandlerBase.cs.meta +11 -0
- package/HistoricalManagerBase.cs +159 -0
- package/HistoricalManagerBase.cs.meta +2 -0
- package/IHistory.cs +101 -0
- package/IHistory.cs.meta +2 -0
- package/ProgressionData.cs +181 -0
- package/ProgressionData.cs.meta +11 -0
- package/ProgressionDebugger.cs +186 -0
- package/ProgressionDebugger.cs.meta +11 -0
- package/ProgressionFlagHandler.cs +167 -0
- package/ProgressionFlagHandler.cs.meta +11 -0
- package/ProgressionHistoryManager.cs +34 -0
- package/ProgressionHistoryManager.cs.meta +11 -0
- package/ProgressionInfo.cs +54 -0
- package/ProgressionInfo.cs.meta +11 -0
- package/ProgressionLoader.cs +129 -0
- package/ProgressionLoader.cs.meta +11 -0
- package/ProgressionManager.cs +286 -0
- package/ProgressionManager.cs.meta +11 -0
- package/ProgressionManagerBase.cs +132 -0
- package/ProgressionManagerBase.cs.meta +11 -0
- package/ProgressionSaver.cs +49 -0
- package/ProgressionSaver.cs.meta +11 -0
- package/Samples/CurrentChapterIndex.asset +21 -0
- package/Samples/CurrentChapterIndex.asset.meta +8 -0
- package/Samples/CurrentObjectiveIndex.asset +19 -0
- package/Samples/CurrentObjectiveIndex.asset.meta +8 -0
- package/Samples/CurrentObjectiveName.asset +19 -0
- package/Samples/CurrentObjectiveName.asset.meta +8 -0
- package/Samples/FlagTriggered.asset +19 -0
- package/Samples/FlagTriggered.asset.meta +8 -0
- package/Samples/Flag_Trigger_Handler.prefab +194 -0
- package/Samples/Flag_Trigger_Handler.prefab.meta +7 -0
- package/Samples/LoadProgressionData.asset +14 -0
- package/Samples/LoadProgressionData.asset.meta +8 -0
- package/Samples/MoveToNextNaturalObjective.asset +14 -0
- package/Samples/MoveToNextNaturalObjective.asset.meta +8 -0
- package/Samples/MoveToObjective.asset +19 -0
- package/Samples/MoveToObjective.asset.meta +8 -0
- package/Samples/ObjectiveKeepsInstanceData.asset +19 -0
- package/Samples/ObjectiveKeepsInstanceData.asset.meta +8 -0
- package/Samples/OnGeneratePastData.asset +14 -0
- package/Samples/OnGeneratePastData.asset.meta +8 -0
- package/Samples/OnLastObjective.asset +19 -0
- package/Samples/OnLastObjective.asset.meta +8 -0
- package/Samples/Progression_Debugger.prefab +73 -0
- package/Samples/Progression_Debugger.prefab.meta +7 -0
- package/Samples/Progression_Flag_Handler.prefab +47 -0
- package/Samples/Progression_Flag_Handler.prefab.meta +7 -0
- package/Samples/Progression_History_Manager.prefab +107 -0
- package/Samples/Progression_History_Manager.prefab.meta +7 -0
- package/Samples/Progression_Loader.prefab +76 -0
- package/Samples/Progression_Loader.prefab.meta +7 -0
- package/Samples/Progression_Manager_ETemplate.prefab +603 -0
- package/Samples/Progression_Manager_ETemplate.prefab.meta +7 -0
- package/Samples/Progression_Saver.prefab +51 -0
- package/Samples/Progression_Saver.prefab.meta +7 -0
- package/Samples/RequiredFlagsTriggered.asset +19 -0
- package/Samples/RequiredFlagsTriggered.asset.meta +8 -0
- package/Samples/TriggerAllRequiredFlags.asset +14 -0
- package/Samples/TriggerAllRequiredFlags.asset.meta +8 -0
- package/Samples.meta +8 -0
- package/package.json +35 -6
- package/package.json.meta +7 -0
- package/README.md +0 -3
package/IHistory.cs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.Saving;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using UnityEngine.Scripting.APIUpdating;
|
|
5
|
+
|
|
6
|
+
namespace DREditor.Progressing.Handling
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
///
|
|
10
|
+
/// </summary>
|
|
11
|
+
[MovedFrom(true, "DREditor.Progression.Handling", "DREditor.Progression.Handling")]
|
|
12
|
+
public interface IHistory : IPersistentData, IClearableOnNewGameSelected
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
///
|
|
16
|
+
/// </summary>
|
|
17
|
+
/// <param name="chapterIndex"></param>
|
|
18
|
+
/// <param name="objective"></param>
|
|
19
|
+
void Add(int chapterIndex, Objective objective);
|
|
20
|
+
|
|
21
|
+
/// <summary>
|
|
22
|
+
///
|
|
23
|
+
/// </summary>
|
|
24
|
+
/// <param name="objectiveName"></param>
|
|
25
|
+
/// <returns></returns>
|
|
26
|
+
bool ContainsObjective(string objectiveName);
|
|
27
|
+
|
|
28
|
+
/// <summary>
|
|
29
|
+
///
|
|
30
|
+
/// </summary>
|
|
31
|
+
/// <returns></returns>
|
|
32
|
+
int GetAmountOfFinishedObjectives();
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
///
|
|
36
|
+
/// </summary>
|
|
37
|
+
/// <returns></returns>
|
|
38
|
+
List<List<Objective>> GetChapterHistory();
|
|
39
|
+
|
|
40
|
+
/// <summary>
|
|
41
|
+
///
|
|
42
|
+
/// </summary>
|
|
43
|
+
/// <param name="flagName"></param>
|
|
44
|
+
/// <returns></returns>
|
|
45
|
+
ProgressionFlag GetFlagFromHistory(string flagName);
|
|
46
|
+
|
|
47
|
+
/// <summary>
|
|
48
|
+
///
|
|
49
|
+
/// </summary>
|
|
50
|
+
/// <param name="chapter"></param>
|
|
51
|
+
/// <param name="objective"></param>
|
|
52
|
+
/// <param name="flag"></param>
|
|
53
|
+
/// <returns></returns>
|
|
54
|
+
ProgressionFlag GetFlagFromIndexes(int chapter, int objective, int flag);
|
|
55
|
+
|
|
56
|
+
/// <summary>
|
|
57
|
+
///
|
|
58
|
+
/// </summary>
|
|
59
|
+
/// <param name="chapter"></param>
|
|
60
|
+
/// <param name="objective"></param>
|
|
61
|
+
/// <returns></returns>
|
|
62
|
+
Objective GetHistoryObjective(int chapter, int objective);
|
|
63
|
+
|
|
64
|
+
/// <summary>
|
|
65
|
+
///
|
|
66
|
+
/// </summary>
|
|
67
|
+
/// <returns></returns>
|
|
68
|
+
Objective GetLastObjective();
|
|
69
|
+
|
|
70
|
+
/// <summary>
|
|
71
|
+
///
|
|
72
|
+
/// </summary>
|
|
73
|
+
/// <param name="chapterHistory"></param>
|
|
74
|
+
void SetChapterHistory(List<List<Objective>> chapterHistory);
|
|
75
|
+
|
|
76
|
+
/// <summary>
|
|
77
|
+
///
|
|
78
|
+
/// </summary>
|
|
79
|
+
/// <param name="chapter"></param>
|
|
80
|
+
void SetChapterIndex(int chapter);
|
|
81
|
+
|
|
82
|
+
/// <summary>
|
|
83
|
+
///
|
|
84
|
+
/// </summary>
|
|
85
|
+
/// <param name="objective"></param>
|
|
86
|
+
void SetPreviousObjective(Objective objective);
|
|
87
|
+
|
|
88
|
+
/// <summary>
|
|
89
|
+
///
|
|
90
|
+
/// </summary>
|
|
91
|
+
/// <param name="selectedChapter"></param>
|
|
92
|
+
/// <returns></returns>
|
|
93
|
+
int GetObjectiveCountFromHistory(int selectedChapter);
|
|
94
|
+
|
|
95
|
+
/// <summary>
|
|
96
|
+
///
|
|
97
|
+
/// </summary>
|
|
98
|
+
/// <returns></returns>
|
|
99
|
+
int LatestChapterIndex();
|
|
100
|
+
}
|
|
101
|
+
}
|
package/IHistory.cs.meta
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.Linq;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.Scripting.APIUpdating;
|
|
7
|
+
using UnityEngine.Serialization;
|
|
8
|
+
|
|
9
|
+
namespace DREditor.Progressing.Handling
|
|
10
|
+
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
///
|
|
13
|
+
/// </summary>
|
|
14
|
+
[Serializable]
|
|
15
|
+
[MovedFrom(true, "DREditor.Progression.Handling", "DREditor.Progression.Handling")]
|
|
16
|
+
public class ProgressionData : IHistory
|
|
17
|
+
{
|
|
18
|
+
/// <summary>
|
|
19
|
+
///
|
|
20
|
+
/// </summary>
|
|
21
|
+
[Tooltip("")]
|
|
22
|
+
public int chapter;
|
|
23
|
+
|
|
24
|
+
/// <summary>
|
|
25
|
+
///
|
|
26
|
+
/// </summary>
|
|
27
|
+
[Tooltip("")]
|
|
28
|
+
public Objective previousObjective;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/// <remarks></remarks>
|
|
32
|
+
/// <summary>
|
|
33
|
+
///
|
|
34
|
+
/// </summary>
|
|
35
|
+
[Tooltip("")]
|
|
36
|
+
[FormerlySerializedAs("Info")]
|
|
37
|
+
public List<ProgressionInfo> Infos = new();
|
|
38
|
+
|
|
39
|
+
public ProgressionData() { }
|
|
40
|
+
|
|
41
|
+
/// <inheritdoc/>
|
|
42
|
+
public virtual void CarryOver(IPersistentData persistentData)
|
|
43
|
+
{
|
|
44
|
+
if (persistentData is ProgressionData oldData)
|
|
45
|
+
Infos = oldData.Infos;
|
|
46
|
+
else
|
|
47
|
+
UnityEngine.Debug.LogWarning("ALERT: TRIED TO SET PROGRESSION DATA OF A DIFFERENT TYPE!");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// <inheritdoc/>
|
|
51
|
+
public virtual void SetChapterIndex(int chapter) => this.chapter = chapter;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/// <inheritdoc/>
|
|
55
|
+
public virtual void SetPreviousObjective(Objective objective) => previousObjective = objective;
|
|
56
|
+
|
|
57
|
+
/// <inheritdoc/>
|
|
58
|
+
public virtual void Add(int chapterIndex, Objective objective)
|
|
59
|
+
{
|
|
60
|
+
RecursiveAdd(chapterIndex);
|
|
61
|
+
|
|
62
|
+
Infos[chapterIndex].Add(objective);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected virtual void RecursiveAdd(int chapterIndex)
|
|
66
|
+
{
|
|
67
|
+
if (chapterIndex >= Infos.Count)
|
|
68
|
+
{
|
|
69
|
+
Infos.Add(new ProgressionInfo());
|
|
70
|
+
|
|
71
|
+
RecursiveAdd(chapterIndex);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// <inheritdoc/>
|
|
76
|
+
public virtual void Clear() => Infos.Clear();
|
|
77
|
+
|
|
78
|
+
/// <inheritdoc/>
|
|
79
|
+
public virtual Objective GetLastObjective()
|
|
80
|
+
{
|
|
81
|
+
if (previousObjective != null)
|
|
82
|
+
return previousObjective;
|
|
83
|
+
|
|
84
|
+
if (Infos.Count == 0)
|
|
85
|
+
return null;
|
|
86
|
+
|
|
87
|
+
return Infos.Last().objectives.Last();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// <inheritdoc/>
|
|
91
|
+
public virtual bool ContainsObjective(string objectiveName)
|
|
92
|
+
{
|
|
93
|
+
for (int i = 0; i < Infos.Count; i++)
|
|
94
|
+
if (Infos[i].ContainsObjective(objectiveName))
|
|
95
|
+
return true;
|
|
96
|
+
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// <inheritdoc/>
|
|
101
|
+
public virtual ProgressionFlag GetFlagFromHistory(string flagName)
|
|
102
|
+
{
|
|
103
|
+
IEnumerable<ProgressionInfo> chaptersContainingFlag =
|
|
104
|
+
Infos.Where(chapter => chapter.objectives.Where(objective => objective.GetFlagNames()
|
|
105
|
+
.Contains(flagName)).Count() > 0);
|
|
106
|
+
|
|
107
|
+
if (chaptersContainingFlag.Count() > 0)
|
|
108
|
+
{
|
|
109
|
+
var firstObjectiveContainingFlag =
|
|
110
|
+
chaptersContainingFlag.ElementAt(0).objectives.Where(n => n.GetFlagNames().Contains(flagName)).ElementAt(0);
|
|
111
|
+
|
|
112
|
+
var matchingFlags = firstObjectiveContainingFlag.Flags.Where(n => n.name == flagName);
|
|
113
|
+
|
|
114
|
+
if (matchingFlags.Count() > 0 && matchingFlags.ElementAt(0) != null)
|
|
115
|
+
return matchingFlags.ElementAt(0);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
UnityEngine.Debug.LogWarning("After Checking this save files previously completed Objectives, " +
|
|
119
|
+
"that flag couldn't be found. \n" +
|
|
120
|
+
"Which means one has occured: There's been user error building progression, " +
|
|
121
|
+
"The Searched progression flag string used was misspelt, OR the save file never completed or had the objective " +
|
|
122
|
+
"that contained the searched flag. \n" +
|
|
123
|
+
"If you still encounter this error after making sure Debug Viewing " +
|
|
124
|
+
"Progression data contains the flag, and the searched flag " +
|
|
125
|
+
"was not misspelt, you should contact Sweden in order to debug and find the problem.");
|
|
126
|
+
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// <inheritdoc/>
|
|
131
|
+
public virtual List<List<Objective>> GetChapterHistory()
|
|
132
|
+
{
|
|
133
|
+
List<List<Objective>> chapterHistory = new();
|
|
134
|
+
|
|
135
|
+
foreach (var chapter in Infos)
|
|
136
|
+
chapterHistory.Add(chapter.objectives);
|
|
137
|
+
|
|
138
|
+
return chapterHistory;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// <inheritdoc/>
|
|
142
|
+
public virtual void SetChapterHistory(List<List<Objective>> chapterHistory)
|
|
143
|
+
{
|
|
144
|
+
foreach (var chapter in Infos)
|
|
145
|
+
chapter.SetObjectiveHistory(chapterHistory[Infos.IndexOf(chapter)]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// <inheritdoc/>
|
|
149
|
+
public virtual Objective GetHistoryObjective(int chapter, int objective) => Infos[chapter].objectives[objective];
|
|
150
|
+
|
|
151
|
+
/// <inheritdoc/>
|
|
152
|
+
public virtual int GetAmountOfFinishedObjectives()
|
|
153
|
+
=> Infos.Count > chapter ? Infos[chapter].objectives.Count : 0;
|
|
154
|
+
|
|
155
|
+
/// <inheritdoc/>
|
|
156
|
+
public virtual int GetObjectiveCountFromHistory(int selectedChapter)
|
|
157
|
+
{
|
|
158
|
+
if (selectedChapter < Infos.Count && selectedChapter >= 0)
|
|
159
|
+
return Infos[selectedChapter].objectives.Count;
|
|
160
|
+
|
|
161
|
+
UnityEngine.Debug.LogWarning($"REPORT: The selected chapter index: {selectedChapter} " +
|
|
162
|
+
$"does not have progression history! Is there Progression data missing?");
|
|
163
|
+
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// <inheritdoc/>
|
|
168
|
+
public virtual int LatestChapterIndex()
|
|
169
|
+
{
|
|
170
|
+
int history = Infos.Count;
|
|
171
|
+
|
|
172
|
+
--history;
|
|
173
|
+
|
|
174
|
+
return Math.Max(chapter, history);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/// <inheritdoc/>
|
|
178
|
+
public virtual ProgressionFlag GetFlagFromIndexes(int chapter, int objective, int flag)
|
|
179
|
+
=> GetHistoryObjective(chapter, objective).Flags[flag];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.EventObjects;
|
|
3
|
+
using DREditor.Services;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.Scripting.APIUpdating;
|
|
7
|
+
using UnityEngine.Serialization;
|
|
8
|
+
|
|
9
|
+
namespace DREditor.Progressing.Handling
|
|
10
|
+
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
///
|
|
13
|
+
/// </summary>
|
|
14
|
+
[DefaultExecutionOrder(1)]
|
|
15
|
+
[ClassHeader("")]
|
|
16
|
+
[MovedFrom(true, "DREditor.Progression.Handling", "DREditor.Progression.Handling")]
|
|
17
|
+
public class ProgressionDebugger : MonoBehaviour
|
|
18
|
+
{
|
|
19
|
+
/// <summary>
|
|
20
|
+
///
|
|
21
|
+
/// </summary>
|
|
22
|
+
[Tooltip("")]
|
|
23
|
+
[FormerlySerializedAs("database")]
|
|
24
|
+
[SerializeField] protected ProgressionDatabase progressionDatabase = null;
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
///
|
|
28
|
+
/// </summary>
|
|
29
|
+
[Tooltip("")]
|
|
30
|
+
[SerializeField] protected IntWithEvent currentChapterIndex = null;
|
|
31
|
+
|
|
32
|
+
/// <summary>
|
|
33
|
+
///
|
|
34
|
+
/// </summary>
|
|
35
|
+
[Tooltip("")]
|
|
36
|
+
[SerializeField] protected SceneEventListener onGeneratePastData = null;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/// <summary>
|
|
40
|
+
///
|
|
41
|
+
/// </summary>
|
|
42
|
+
[Header("")]
|
|
43
|
+
[Divider]
|
|
44
|
+
[Tooltip("")]
|
|
45
|
+
[SerializeField] protected bool testLatestObjective = false;
|
|
46
|
+
|
|
47
|
+
/// <summary>
|
|
48
|
+
///
|
|
49
|
+
/// </summary>
|
|
50
|
+
[Tooltip("")]
|
|
51
|
+
[SerializeField] protected int startObjective = 0;
|
|
52
|
+
|
|
53
|
+
/// <summary>
|
|
54
|
+
///
|
|
55
|
+
/// </summary>
|
|
56
|
+
[Tooltip("")]
|
|
57
|
+
[SerializeField] protected int clearedFlags = 0;
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
///
|
|
61
|
+
/// </summary>
|
|
62
|
+
[Tooltip("")]
|
|
63
|
+
[SerializeField] protected bool generatePastData = false;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/// <summary>
|
|
67
|
+
///
|
|
68
|
+
/// </summary>
|
|
69
|
+
protected ProgressionManagerBase manager = null;
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/// <summary>
|
|
73
|
+
///
|
|
74
|
+
/// </summary>
|
|
75
|
+
protected virtual void OnEnable() => onGeneratePastData.Response.AddListener(GeneratePast);
|
|
76
|
+
|
|
77
|
+
/// <summary>
|
|
78
|
+
///
|
|
79
|
+
/// </summary>
|
|
80
|
+
protected virtual void OnDisable() => onGeneratePastData.Response.RemoveListener(GeneratePast);
|
|
81
|
+
|
|
82
|
+
/// <summary>
|
|
83
|
+
///
|
|
84
|
+
/// </summary>
|
|
85
|
+
protected virtual void Start() => Initialize();
|
|
86
|
+
|
|
87
|
+
/// <summary>
|
|
88
|
+
///
|
|
89
|
+
/// </summary>
|
|
90
|
+
protected virtual void Initialize()
|
|
91
|
+
{
|
|
92
|
+
manager = ServiceLocator.GetService<ProgressionManagerBase>();
|
|
93
|
+
|
|
94
|
+
InitializeStartObjective();
|
|
95
|
+
|
|
96
|
+
TriggerFlagsInCurrentObjective();
|
|
97
|
+
|
|
98
|
+
InitializePastData();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// <summary>
|
|
102
|
+
///
|
|
103
|
+
/// </summary>
|
|
104
|
+
protected virtual void InitializeStartObjective()
|
|
105
|
+
{
|
|
106
|
+
if (manager == null)
|
|
107
|
+
manager = ServiceLocator.GetService<ProgressionManagerBase>();
|
|
108
|
+
|
|
109
|
+
if (manager.GetCurrentChapter() == null)
|
|
110
|
+
return;
|
|
111
|
+
|
|
112
|
+
startObjective = testLatestObjective ? manager.GetCurrentChapter().Objectives.Count - 1 : startObjective;
|
|
113
|
+
|
|
114
|
+
if (manager.GetCurrentChapter().Objectives.Count > 0)
|
|
115
|
+
manager.SetCurrentObjective((Objective)manager.GetCurrentChapter().Objectives[startObjective].Clone());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// <summary>
|
|
119
|
+
///
|
|
120
|
+
/// </summary>
|
|
121
|
+
protected virtual void TriggerFlagsInCurrentObjective()
|
|
122
|
+
{
|
|
123
|
+
if (manager.currentObjective != null && clearedFlags > 0 && clearedFlags <= manager.currentObjective.Flags.Count)
|
|
124
|
+
for (int i = 0; i < clearedFlags; i++)
|
|
125
|
+
manager.currentObjective.Flags[i].SetTriggered(true);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// <summary>
|
|
129
|
+
///
|
|
130
|
+
/// </summary>
|
|
131
|
+
protected virtual void InitializePastData()
|
|
132
|
+
{
|
|
133
|
+
if (generatePastData)
|
|
134
|
+
GeneratePast();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// <summary>
|
|
138
|
+
///
|
|
139
|
+
/// </summary>
|
|
140
|
+
protected virtual void GeneratePast()
|
|
141
|
+
{
|
|
142
|
+
for (int chapterIndex = 0; chapterIndex <= currentChapterIndex.Value; chapterIndex++)
|
|
143
|
+
GenerateChapterObjectives(chapterIndex);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// <summary>
|
|
147
|
+
///
|
|
148
|
+
/// </summary>
|
|
149
|
+
/// <param name="chapterIndex"></param>
|
|
150
|
+
protected void GenerateChapterObjectives(int chapterIndex)
|
|
151
|
+
{
|
|
152
|
+
foreach (Objective objective in progressionDatabase.Chapters[chapterIndex].Objectives)
|
|
153
|
+
{
|
|
154
|
+
if (objective.Description == manager.currentObjective.Description)
|
|
155
|
+
break;
|
|
156
|
+
|
|
157
|
+
GenerateCompletedObjectiveToHistory(chapterIndex, objective);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// <summary>
|
|
162
|
+
///
|
|
163
|
+
/// </summary>
|
|
164
|
+
/// <param name="chapterIndex"></param>
|
|
165
|
+
/// <param name="objective"></param>
|
|
166
|
+
protected void GenerateCompletedObjectiveToHistory(int chapterIndex, Objective objective)
|
|
167
|
+
{
|
|
168
|
+
Objective clonedObjective = (Objective)objective.Clone();
|
|
169
|
+
|
|
170
|
+
TriggerAllRequiredFlags(clonedObjective.Flags);
|
|
171
|
+
|
|
172
|
+
ServiceLocator.GetService<IHistory>().Add(chapterIndex, clonedObjective);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// <summary>
|
|
176
|
+
///
|
|
177
|
+
/// </summary>
|
|
178
|
+
/// <param name="flags"></param>
|
|
179
|
+
protected void TriggerAllRequiredFlags(List<ProgressionFlag> flags)
|
|
180
|
+
{
|
|
181
|
+
foreach (ProgressionFlag flag in flags)
|
|
182
|
+
if (!flag.optional)
|
|
183
|
+
flag.SetTriggered(true);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.Services;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
using UnityEngine.Scripting.APIUpdating;
|
|
6
|
+
using UnityEngine.Serialization;
|
|
7
|
+
|
|
8
|
+
namespace DREditor.Progressing.Handling
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
///
|
|
12
|
+
/// </summary>
|
|
13
|
+
[ClassHeader("")]
|
|
14
|
+
[MovedFrom(true, "DREditor.Progression.Handling", "DREditor.Progression.Handling")]
|
|
15
|
+
public class ProgressionFlagHandler : MonoBehaviour
|
|
16
|
+
{
|
|
17
|
+
/// <summary>
|
|
18
|
+
///
|
|
19
|
+
/// </summary>
|
|
20
|
+
[Tooltip("")]
|
|
21
|
+
[FormerlySerializedAs("database")]
|
|
22
|
+
[SerializeField] protected ProgressionDatabase progressionDatabase = null;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/// <summary>
|
|
26
|
+
///
|
|
27
|
+
/// </summary>
|
|
28
|
+
/// <param name="flagName"></param>
|
|
29
|
+
/// <param name="targetObjective"></param>
|
|
30
|
+
/// <returns></returns>
|
|
31
|
+
public virtual ProgressionFlag GetFlag(string flagName, Objective targetObjective)
|
|
32
|
+
{
|
|
33
|
+
if (SearchCurrentObjective(flagName, targetObjective) is ProgressionFlag flagOne && flagOne != null)
|
|
34
|
+
return flagOne;
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
RepairProgressionHistory(ServiceLocator.GetService<IHistory>().GetChapterHistory());
|
|
38
|
+
|
|
39
|
+
if (ServiceLocator.GetService<IHistory>().GetFlagFromHistory(flagName) is ProgressionFlag flagTwo && flagTwo != null)
|
|
40
|
+
return flagTwo;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
RepairObjective(ref targetObjective);
|
|
44
|
+
|
|
45
|
+
if (SearchCurrentObjective(flagName, targetObjective) is ProgressionFlag flagThree && flagThree != null)
|
|
46
|
+
return flagThree;
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
return OnFlagNotRevived(flagName);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// <summary>
|
|
53
|
+
///
|
|
54
|
+
/// </summary>
|
|
55
|
+
/// <param name="chapterHistory"></param>
|
|
56
|
+
protected virtual void RepairProgressionHistory(List<List<Objective>> chapterHistory)
|
|
57
|
+
{
|
|
58
|
+
UnityEngine.Debug.Log($"REPORT: {ToString()}: Repairing progression history.");
|
|
59
|
+
|
|
60
|
+
foreach (List<Objective> chapterObjectives in chapterHistory)
|
|
61
|
+
RepairObjectivesOnFlagMismatch(chapterObjectives);
|
|
62
|
+
|
|
63
|
+
ServiceLocator.GetService<IHistory>().SetChapterHistory(chapterHistory);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// <summary>
|
|
67
|
+
///
|
|
68
|
+
/// </summary>
|
|
69
|
+
/// <param name="objectives"></param>
|
|
70
|
+
protected virtual void RepairObjectivesOnFlagMismatch(List<Objective> objectives)
|
|
71
|
+
{
|
|
72
|
+
for (int i = 0; i < objectives.Count; i++)
|
|
73
|
+
RepairObjectiveOnFlagMismatch(objectives[i]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// <summary>
|
|
77
|
+
///
|
|
78
|
+
/// </summary>
|
|
79
|
+
/// <param name="objective"></param>
|
|
80
|
+
protected virtual void RepairObjectiveOnFlagMismatch(Objective objective)
|
|
81
|
+
{
|
|
82
|
+
if (ObjectiveFlagsDontMatchBase(objective))
|
|
83
|
+
RepairObjective(ref objective);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/// <summary>
|
|
87
|
+
///
|
|
88
|
+
/// </summary>
|
|
89
|
+
/// <param name="objective"></param>
|
|
90
|
+
/// <returns></returns>
|
|
91
|
+
protected virtual bool ObjectiveFlagsDontMatchBase(Objective objective)
|
|
92
|
+
=> objective.Flags.Count != progressionDatabase.GetObjective(objective.Description).Flags.Count;
|
|
93
|
+
|
|
94
|
+
/// <summary>
|
|
95
|
+
///
|
|
96
|
+
/// </summary>
|
|
97
|
+
/// <param name="flagName"></param>
|
|
98
|
+
/// <returns></returns>
|
|
99
|
+
protected virtual ProgressionFlag OnFlagNotRevived(string flagName)
|
|
100
|
+
{
|
|
101
|
+
UnityEngine.Debug.LogWarning("ALERT: After repairing the current save file objective, the current " +
|
|
102
|
+
"flag couldn't be found. Best to contact Sweden for support.");
|
|
103
|
+
|
|
104
|
+
UnityEngine.Debug.LogWarning("ALERT: Since the flag couldn't be found for Flag: " + flagName +
|
|
105
|
+
" the game will just return a triggered flag and use that as the default.");
|
|
106
|
+
|
|
107
|
+
return new ProgressionFlag(true);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// <summary>
|
|
111
|
+
///
|
|
112
|
+
/// </summary>
|
|
113
|
+
/// <param name="objective"></param>
|
|
114
|
+
public virtual void RepairObjective(ref Objective objective)
|
|
115
|
+
{
|
|
116
|
+
UnityEngine.Debug.LogWarning("REPORT: The system noticed an issue with the current objective and will now repair it." +
|
|
117
|
+
"\nThis is common in scenarios where objective data from a save file is outdated or manipulated through debugging.");
|
|
118
|
+
|
|
119
|
+
Objective currentObjectiveCopy = (Objective)objective.Clone();
|
|
120
|
+
|
|
121
|
+
objective = (Objective)progressionDatabase.GetObjective(objective.Description).Clone();
|
|
122
|
+
|
|
123
|
+
CopyFlagsToObjective(currentObjectiveCopy, ref objective);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/// <summary>
|
|
127
|
+
///
|
|
128
|
+
/// </summary>
|
|
129
|
+
/// <param name="currentObjectiveCopy"></param>
|
|
130
|
+
/// <param name="targetObjective"></param>
|
|
131
|
+
protected virtual void CopyFlagsToObjective(Objective currentObjectiveCopy, ref Objective targetObjective)
|
|
132
|
+
{
|
|
133
|
+
for (int i = 0; i < currentObjectiveCopy.Flags.Count; i++)
|
|
134
|
+
ApplyFlagStateToObjectivesFlag(currentObjectiveCopy.Flags[i], ref targetObjective);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// <summary>
|
|
138
|
+
///
|
|
139
|
+
/// </summary>
|
|
140
|
+
/// <param name="originalFlag"></param>
|
|
141
|
+
/// <param name="targetObjective"></param>
|
|
142
|
+
protected virtual void ApplyFlagStateToObjectivesFlag(ProgressionFlag originalFlag, ref Objective targetObjective)
|
|
143
|
+
{
|
|
144
|
+
foreach (ProgressionFlag currentObjectiveFlag in targetObjective.Flags)
|
|
145
|
+
if (currentObjectiveFlag.name == originalFlag.name && originalFlag.triggered)
|
|
146
|
+
currentObjectiveFlag.SetTriggered(true);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// <summary>
|
|
150
|
+
///
|
|
151
|
+
/// </summary>
|
|
152
|
+
/// <param name="flagName"></param>
|
|
153
|
+
/// <param name="currentObjective"></param>
|
|
154
|
+
/// <returns></returns>
|
|
155
|
+
protected virtual ProgressionFlag SearchCurrentObjective(string flagName, Objective currentObjective)
|
|
156
|
+
{
|
|
157
|
+
foreach (ProgressionFlag flag in currentObjective.Flags)
|
|
158
|
+
if (flag.name == flagName)
|
|
159
|
+
return flag;
|
|
160
|
+
|
|
161
|
+
UnityEngine.Debug.LogWarning("ALERT: Flag: " + flagName + " could not be found on Objective: " +
|
|
162
|
+
currentObjective.Description + " Make sure you spell the flag name correctly!");
|
|
163
|
+
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|