fr.jeanf.questsystem 0.0.31 → 0.0.33

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.
@@ -4,6 +4,9 @@ using jeanf.EventSystem;
4
4
  using UnityEngine;
5
5
  using jeanf.propertyDrawer;
6
6
  using jeanf.validationTools;
7
+ using Unity.VisualScripting.YamlDotNet.Core.Tokens;
8
+ using UnityEngine.SceneManagement;
9
+ using UnityEditor;
7
10
 
8
11
 
9
12
  namespace jeanf.questsystem
@@ -24,6 +27,7 @@ namespace jeanf.questsystem
24
27
  private QuestSO questSO;
25
28
  private Dictionary<string, QuestStep> stepMap = new Dictionary<string, QuestStep>();
26
29
  private Dictionary<string, QuestStep> activeSteps = new Dictionary<string, QuestStep>();
30
+ private Dictionary<string, QuestStep> completedSteps = new Dictionary<string, QuestStep>();
27
31
 
28
32
 
29
33
  [ReadOnly] [Range(0, 1)] [SerializeField]
@@ -39,11 +43,12 @@ namespace jeanf.questsystem
39
43
  // if they do not exist simply right click in the hierarchy and find >InitializeQuestSystem<
40
44
  [Header("Listening on:")]
41
45
  [SerializeField] [Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
42
- [SerializeField] [Validation("A reference to the StartQuestEventChannel SO is required")] private StringEventChannelSO StartQuestEventChannel;
43
46
  [SerializeField] [Validation("A reference to the QuestInitialCheck SO is required")] private StringEventChannelSO QuestInitialCheck;
44
47
 
45
48
  [Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
46
49
  private StringEventChannelSO requirementCheck;
50
+ [SerializeField] StringEventChannelSO loadRequiredScenesEventChannel;
51
+ [SerializeField] IntEventChannelSO unlockDoorsEventChannel;
47
52
 
48
53
  #region Awake/Enable/Disable
49
54
  private void Awake()
@@ -65,6 +70,9 @@ namespace jeanf.questsystem
65
70
  InstantiateQuestStep(step.StepId);
66
71
  }
67
72
  }
73
+
74
+ LoadDependencies();
75
+
68
76
  }
69
77
 
70
78
  private void OnEnable()
@@ -78,37 +86,41 @@ namespace jeanf.questsystem
78
86
 
79
87
  private void Subscribe()
80
88
  {
81
- QuestInitialCheck.OnEventRaised += InitialCheckFromQuestManager;
82
- StartQuestEventChannel.OnEventRaised += RequestQuestStart;
89
+ QuestInitialCheck.OnEventRaised += Init;
83
90
  QuestProgress.OnEventRaised += UpdateProgress;
84
91
  GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
85
92
  GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
86
93
  QuestStep.sendNextStepId += InstantiateQuestStep;
87
94
  QuestStep.stepCompleted += DestroyQuestStep;
95
+ QuestStep.stepActive += UpdateStepStatus;
88
96
 
89
97
  }
90
98
 
91
99
  private void Unsubscribe()
92
100
  {
93
- QuestInitialCheck.OnEventRaised -= InitialCheckFromQuestManager;
94
- StartQuestEventChannel.OnEventRaised -= RequestQuestStart;
101
+ QuestInitialCheck.OnEventRaised -= Init;
95
102
  QuestProgress.OnEventRaised -= UpdateProgress;
96
103
  GameEventsManager.instance.questEvents.onQuestStateChange -= QuestStateChange;
97
104
  GameEventsManager.instance.inputEvents.onSubmitPressed -= UpdateState;
98
105
  QuestStep.sendNextStepId -= InstantiateQuestStep;
99
106
  QuestStep.stepCompleted -= DestroyQuestStep;
107
+ QuestStep.stepActive -= UpdateStepStatus;
100
108
 
101
109
  }
102
110
  #endregion
103
111
 
104
- #region Step Instantiation & Destroy
112
+ #region Instantiations & Loading
105
113
  public void InstantiateQuestStep(string id)
106
114
  {
107
- if (activeSteps.ContainsKey(id)) return;
115
+ if (activeSteps.ContainsKey(id))
116
+ {
117
+ Debug.Log($"Step with id:[{id}] is already in the list of active steps");
118
+ return;
119
+ }
108
120
 
109
121
  if (stepMap.ContainsKey(id))
110
122
  {
111
- activeSteps.Add(id, Instantiate(stepMap[id]));
123
+ activeSteps.Add(id,Instantiate(stepMap[id], this.transform, true));
112
124
  }
113
125
  }
114
126
 
@@ -120,26 +132,59 @@ namespace jeanf.questsystem
120
132
  activeSteps.Remove(id);
121
133
  }
122
134
  }
135
+
136
+ private void LoadDependencies()
137
+ {
138
+ foreach (string SceneToLoad in questSO.ScenesToLoad)
139
+ {
140
+ loadRequiredScenesEventChannel.RaiseEvent(SceneToLoad);
141
+ }
142
+
143
+ foreach (int roomToUnlock in questSO.roomsToUnlock)
144
+ {
145
+ unlockDoorsEventChannel.RaiseEvent(roomToUnlock);
146
+ }
147
+ }
123
148
  #endregion
124
149
 
150
+ public void UpdateStepStatus(string id, QuestStepStatus status)
151
+ {
152
+ switch (status)
153
+ {
154
+ case QuestStepStatus.Completed when activeSteps.ContainsKey(id):
155
+ // put step in completed list
156
+ activeSteps.Remove(id);
157
+ completedSteps.Add(id, stepMap[id]);
158
+ break;
159
+ case QuestStepStatus.Active when !activeSteps.ContainsKey(id):
160
+ // put step in active list
161
+ activeSteps.Add(id, stepMap[id]);
162
+ break;
163
+ case QuestStepStatus.Inactive:
164
+ // do nothing
165
+ default:
166
+ // do nothing
167
+ return;
168
+ }
169
+ }
125
170
 
126
171
  #region quest process
127
172
  private void Init(string id)
128
173
  {
174
+ activeSteps.Clear();
175
+ activeSteps.TrimExcess();
176
+ completedSteps.Clear();
177
+ completedSteps.TrimExcess();
129
178
 
130
179
  Debug.Log($"Quest [{id}]: _startQuestOnEnable value is: [{_startQuestOnEnable}]");
131
180
  if (!_startQuestOnEnable) return;
132
- RequestQuestStart(id);
133
- }
134
-
135
- private void InitialCheckFromQuestManager( string id)
136
- {
137
- Debug.Log($"Initial check for quest with id: [{id}], it is in the following state: [{currentQuestState}]");
138
- Init(id);
181
+ if (!_startQuestOnEnable || id != questId) return;
182
+ clearToStart = true;
183
+ currentQuestState = QuestState.CAN_START;
184
+ requirementCheck.RaiseEvent(questId);
185
+ UpdateState();
139
186
  }
140
187
 
141
-
142
-
143
188
  private void UpdateState()
144
189
  {
145
190
  if (isDebug) Debug.Log($"Updating State...");
@@ -192,34 +237,28 @@ namespace jeanf.questsystem
192
237
  UpdateState();
193
238
  }
194
239
  }
195
-
196
- public void AllClear(bool value)
197
- {
198
- Debug.Log($"All clear for quest [{questId}], sending an update to the QuestManager");
199
- clearToStart = value;
200
- currentQuestState = QuestState.CAN_START;
201
- requirementCheck.RaiseEvent(questId);
202
- UpdateState();
203
- }
204
-
205
- private void RequestQuestStart(string id)
206
- {
207
- if(id!= questId) return;
208
-
209
- Debug.Log($"Requesting start for quest [{id}]");
210
- AllClear(true);
211
- if(isDebug) Debug.Log($"Quest start was requested for quest {id}.", this);
212
- }
213
240
  #endregion
214
241
 
215
242
  #region validation tools
216
243
 
217
- #if UNITY_EDITOR
244
+ #if UNITY_EDITOR
218
245
  public void OnValidate()
219
246
  {
220
247
  ValidityCheck();
221
248
  }
222
- #endif
249
+ #endif
250
+
251
+
252
+ #if UNITY_EDITOR
253
+ public void LogActiveSteps()
254
+ {
255
+ Debug.Log($"There is {activeSteps.Count} active steps at the moment.");
256
+ foreach (var step in activeSteps.Keys)
257
+ {
258
+ Debug.Log($"active step: {step}");
259
+ }
260
+ }
261
+ #endif
223
262
 
224
263
  private void ValidityCheck()
225
264
  {
@@ -260,19 +299,6 @@ namespace jeanf.questsystem
260
299
 
261
300
  }
262
301
 
263
- if (StartQuestEventChannel == null)
264
- {
265
- if (isDebug) Debug.Log($"{searching} {_}/StartQuestEventChannel in {searchLocation}", this);
266
- StartQuestEventChannel = Resources.Load<StringEventChannelSO>($"{_}/StartQuestEventChannel");
267
- if (StartQuestEventChannel == null)
268
- {
269
- errorMessages.Add($"{_}/StartQuestEventChannel is not {searchLocation} {readInstructions}");
270
- validityCheck = false;
271
- invalidObjects.Add(StartQuestEventChannel);
272
- }
273
- }
274
-
275
-
276
302
  if (requirementCheck == null)
277
303
  {
278
304
  if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
@@ -297,4 +323,20 @@ namespace jeanf.questsystem
297
323
  }
298
324
  #endregion
299
325
  }
326
+
327
+
328
+ #if UNITY_EDITOR
329
+ [CustomEditor(typeof(QuestItem))]
330
+ public class BoolEventOnClickEditor : Editor {
331
+ override public void OnInspectorGUI () {
332
+ DrawDefaultInspector();
333
+ GUILayout.Space(10);
334
+ var eventToSend = (QuestItem) target;
335
+ if(GUILayout.Button("Log active steps", GUILayout.Height(30))) {
336
+ eventToSend.LogActiveSteps(); // how do i call this?
337
+ }
338
+ GUILayout.Space(10);
339
+ }
340
+ }
341
+ #endif
300
342
  }
@@ -238,22 +238,22 @@ namespace jeanf.questsystem
238
238
  }
239
239
  }
240
240
 
241
- private Quest LoadQuest(QuestSO questInfo)
241
+ private Quest LoadQuest(QuestSO questSO)
242
242
  {
243
243
  Quest quest = null;
244
244
  try
245
245
  {
246
246
  // load quest from saved data
247
- if (PlayerPrefs.HasKey(questInfo.id) && loadSavedQuestState)
247
+ if (PlayerPrefs.HasKey(questSO.id) && loadSavedQuestState)
248
248
  {
249
- string serializedData = PlayerPrefs.GetString(questInfo.id);
249
+ string serializedData = PlayerPrefs.GetString(questSO.id);
250
250
  QuestData questData = JsonUtility.FromJson<QuestData>(serializedData);
251
- quest = new Quest(questInfo, questData.state, questData.questStepIndex, questData.questStepStates);
251
+ quest = new Quest(questSO, questData.state, questData.questStepIndex, questData.questStepStates);
252
252
  }
253
253
  // otherwise, initialize a new quest
254
254
  else
255
255
  {
256
- quest = new Quest(questInfo);
256
+ quest = new Quest(questSO);
257
257
  }
258
258
  }
259
259
  catch (System.Exception e)
@@ -5,6 +5,7 @@ using UnityEngine;
5
5
  using jeanf.propertyDrawer;
6
6
  using jeanf.validationTools;
7
7
  using System.Collections.Generic;
8
+ using UnityEngine.SceneManagement;
8
9
 
9
10
  namespace jeanf.questsystem
10
11
  {
@@ -17,8 +18,6 @@ namespace jeanf.questsystem
17
18
  public bool IsValid { get; private set; }
18
19
 
19
20
  [Header("General")] public string displayName;
20
- [SerializeField][Validation("A reference to a BaseGraph is required.")] public BaseGraph QuestTree;
21
- [SerializeField] public QuestStep startingStep;
22
21
 
23
22
  [Header("Custom messages init/finish")]
24
23
  [SerializeField] public StringEventChannelSO messageChannel; //change to delegate?
@@ -29,6 +28,8 @@ namespace jeanf.questsystem
29
28
 
30
29
  [Header("Requirements")] public int levelRequirement;
31
30
  public QuestSO[] questPrerequisites;
31
+ public List<string> ScenesToLoad = new List<string>();
32
+ public List<int> roomsToUnlock = new List<int>();
32
33
 
33
34
  [Header("Steps")] public QuestStep[] questSteps;
34
35
 
@@ -42,12 +43,6 @@ namespace jeanf.questsystem
42
43
  var invalidObjects = new List<object>();
43
44
  var errorMessages = new List<string>();
44
45
 
45
- if (QuestTree == null)
46
- {
47
- validityCheck = false;
48
- invalidObjects.Add(QuestTree);
49
- }
50
-
51
46
  IsValid = validityCheck;
52
47
  if (!IsValid) return;
53
48
 
@@ -72,4 +67,4 @@ namespace jeanf.questsystem
72
67
  }
73
68
  #endif
74
69
  }
75
- }
70
+ }
@@ -23,8 +23,6 @@ namespace jeanf.questsystem
23
23
  public string QuestId { get { return questId; } }
24
24
 
25
25
 
26
- private float questStepProgress = 0;
27
-
28
26
  [field: ReadOnly] [SerializeField] public QuestStepStatus stepStatus;
29
27
 
30
28
  [Tooltip("This boolean has to be enabled if the quest step has an intro timeline.")]
@@ -42,6 +40,10 @@ namespace jeanf.questsystem
42
40
  public bool isRootStep;
43
41
  public delegate void StepCompleted(string id);
44
42
  public static StepCompleted stepCompleted;
43
+ public delegate void StepActive(string id, QuestStepStatus stepStatus);
44
+ public static StepActive stepActive;
45
+
46
+
45
47
  [Header("Quest Tooltip")]
46
48
  [SerializeField] private QuestTooltipSO questTooltipSO;
47
49
 
@@ -64,6 +66,7 @@ namespace jeanf.questsystem
64
66
  Debug.Log($"Initializing quest with questId: {questId}");
65
67
 
66
68
  stepStatus = QuestStepStatus.Active;
69
+ stepActive?.Invoke(stepId, stepStatus);
67
70
 
68
71
 
69
72
  if (sendQuestStepTooltip != null)
@@ -98,6 +101,7 @@ namespace jeanf.questsystem
98
101
  sendNextStepId?.Invoke(questStep.stepId);
99
102
  }
100
103
 
104
+ stepActive?.Invoke(stepId, stepStatus);
101
105
  stepCompleted?.Invoke(stepId);
102
106
 
103
107
  if (!isUsingIntroTimeline || !timeline) return;
@@ -39,17 +39,5 @@ namespace jeanf.questsystem
39
39
  onQuestStateChange(quest);
40
40
  }
41
41
  }
42
-
43
- //public event Action<string, int, QuestStepState> onQuestStepStateChange;
44
-
45
- //public void QuestStepStateChange(string id, int stepIndex, QuestStepState questStepState)
46
- //{
47
- // if (onQuestStepStateChange != null)
48
- // {
49
- // Debug.Log($"quest step state change: {id} -- stepstate: {questStepState}");
50
- // onQuestStepStateChange(id, stepIndex, questStepState);
51
- // }
52
- //}
53
-
54
42
  }
55
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name":"fr.jeanf.questsystem",
3
- "version":"0.0.31",
3
+ "version":"0.0.33",
4
4
  "displayName":"Quest system",
5
5
  "description":"This package uses Scriptable Objects to define quests.",
6
6
  "unity": "2021.3",