fr.jeanf.questsystem 0.0.9 → 0.0.12

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.
@@ -18,6 +18,8 @@ namespace jeanf.questsystem
18
18
  var channelFolderPath = $"{questFolderPath}/{channelFolder}";
19
19
 
20
20
  // files needed
21
+ var questStatusUpdate = "QuestStatusUpdate.asset";
22
+ var questRequirementCheck = "QuestRequirementCheck.asset";
21
23
  var questProgressChannel = $"QuestsProgressChannel.asset";
22
24
  var startQuestEventChannel = $"StartQuestEventChannel.asset";
23
25
 
@@ -30,22 +32,24 @@ namespace jeanf.questsystem
30
32
  AssetDatabase.CreateFolder(questFolderPath, channelFolder);
31
33
  }
32
34
 
33
- CreateQuestStartEventChannelFile(channelFolderPath, startQuestEventChannel);
34
- CreateQuestProgressChannelFile(channelFolderPath, questProgressChannel);
35
+ CreateStringEventFile(channelFolderPath, questStatusUpdate);
36
+ CreateStringEventFile(channelFolderPath, questRequirementCheck);
37
+ CreateStringEventFile(channelFolderPath, startQuestEventChannel);
38
+ CreateStringFloatEventFile(channelFolderPath, questProgressChannel);
35
39
  }
36
40
 
37
- public static void CreateQuestStartEventChannelFile(string path, string startEventChannel)
41
+ public static void CreateStringEventFile(string path, string fileName)
38
42
  {
39
- if (File.Exists($"{path}/{startEventChannel}"))
43
+ if (File.Exists($"{path}/{fileName}"))
40
44
  {
41
- Debug.Log($"file: [{path}/{startEventChannel}] was found.");
45
+ Debug.Log($"file: [{path}/{fileName}] was found.");
42
46
  return;
43
47
  }
44
48
 
45
- Debug.Log($"file: [{path}/{startEventChannel}] not found. Creating it for you.");
49
+ Debug.Log($"file: [{path}/{fileName}] not found. Creating it for you.");
46
50
  StringEventChannelSO asset = ScriptableObject.CreateInstance<StringEventChannelSO>();
47
51
 
48
- AssetDatabase.CreateAsset(asset, $"{path}/{startEventChannel}");
52
+ AssetDatabase.CreateAsset(asset, $"{path}/{fileName}");
49
53
  AssetDatabase.SaveAssets();
50
54
 
51
55
  EditorUtility.FocusProjectWindow();
@@ -53,24 +57,25 @@ namespace jeanf.questsystem
53
57
  Selection.activeObject = asset;
54
58
  }
55
59
 
56
- public static void CreateQuestProgressChannelFile(string path, string questProgressChannel)
60
+ public static void CreateStringFloatEventFile(string path, string fileName)
57
61
  {
58
- if (File.Exists($"{path}/{questProgressChannel}"))
62
+ if (File.Exists($"{path}/{fileName}"))
59
63
  {
60
- Debug.Log($"file: [{path}/{questProgressChannel}] was found.");
64
+ Debug.Log($"file: [{path}/{fileName}] was found.");
61
65
  return;
62
66
  }
63
67
 
64
- Debug.Log($"file: [{path}/{questProgressChannel}] not found. Creating it for you.");
68
+ Debug.Log($"file: [{path}/{fileName}] not found. Creating it for you.");
65
69
  StringFloatEventChannelSO asset = ScriptableObject.CreateInstance<StringFloatEventChannelSO>();
66
70
 
67
- AssetDatabase.CreateAsset(asset, $"{path}/{questProgressChannel}");
71
+ AssetDatabase.CreateAsset(asset, $"{path}/{fileName}");
68
72
  AssetDatabase.SaveAssets();
69
73
 
70
74
  EditorUtility.FocusProjectWindow();
71
75
 
72
76
  Selection.activeObject = asset;
73
77
  }
78
+
74
79
  }
75
80
  #endif
76
81
  }
@@ -166,6 +166,8 @@ MonoBehaviour:
166
166
  m_Name:
167
167
  m_EditorClassIdentifier:
168
168
  _isDebug: 1
169
+ _startQuestOnEnable: 0
169
170
  questInfoForPoint: {fileID: 11400000, guid: b7b6381ae7b9c2244862b31a1ce5b2f5, type: 2}
170
171
  progress: 0
171
172
  clearToStart: 0
173
+ requirementCheck: {fileID: 0}
@@ -1,18 +1,21 @@
1
1
  using System;
2
+ using System.Collections.Generic;
2
3
  using jeanf.EventSystem;
3
4
  using UnityEngine;
4
5
  using UnityEngine.Serialization;
5
6
  using jeanf.propertyDrawer;
7
+ using jeanf.validationTools;
6
8
 
7
9
  namespace jeanf.questsystem
8
10
  {
9
- public class QuestItem : MonoBehaviour, IDebugBehaviour
11
+ public class QuestItem : MonoBehaviour, IDebugBehaviour, IValidatable
10
12
  {
11
13
  public bool isDebug
12
14
  {
13
15
  get => _isDebug;
14
16
  set => _isDebug = value;
15
17
  }
18
+ public bool IsValid { get; private set; }
16
19
 
17
20
  [SerializeField] private bool _isDebug = false;
18
21
  [SerializeField] private bool _startQuestOnEnable = false;
@@ -31,36 +34,80 @@ namespace jeanf.questsystem
31
34
 
32
35
  // these events are Located in Assets/Resources/Quests/Channels - it is searched for at Awake time.
33
36
  // if they do not exist simply right click in the hierarchy and find >InitializeQuestSystem<
34
- private StringFloatEventChannelSO QuestProgress;
35
- private StringEventChannelSO StartQuestEventChannel;
37
+ [Header("Listening on:")]
38
+ [SerializeField] [Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
39
+ [SerializeField] [Validation("A reference to the StartQuestEventChannel SO is required")] private StringEventChannelSO StartQuestEventChannel;
36
40
 
37
- [Header("Broadcasting on:")] [SerializeField]
41
+ [Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
38
42
  private StringEventChannelSO requirementCheck;
39
43
 
40
44
  public void OnValidate()
45
+ {
46
+ #if UNITY_EDITOR
47
+ ValididtyCheck();
48
+ #endif
49
+
50
+ questId = questInfoForPoint.id;
51
+ }
52
+
53
+ private void ValididtyCheck()
41
54
  {
42
55
  const string searching = "attempting to find";
43
56
  const string _ = "Quests/Channels"; // search target
44
57
  const string searchLocation = "the resources folder";
45
58
  const string readInstructions = "please read the package instruction for further help";
46
-
59
+
60
+
61
+ var validityCheck = true;
62
+ var invalidObjects = new List<object>();
63
+ var errorMessages = new List<string>();
64
+
47
65
  if (QuestProgress == null)
48
66
  {
49
67
  if (isDebug) Debug.Log($"{searching} {_}/QuestsProgressChannel in {searchLocation} ", this);
50
68
  QuestProgress = Resources.Load<StringFloatEventChannelSO>($"{_}/QuestsProgressChannel");
51
69
  if (QuestProgress == null)
52
- Debug.LogError($"{_}/QuestsProgressChannel is not in {searchLocation} {readInstructions}", this);
70
+ {
71
+ errorMessages.Add($"{_}/QuestsProgressChannel is not in {searchLocation} {readInstructions}");
72
+ validityCheck = false;
73
+ invalidObjects.Add(QuestProgress);
74
+ }
75
+
53
76
  }
54
77
 
55
78
  if (StartQuestEventChannel == null)
56
79
  {
57
80
  if (isDebug) Debug.Log($"{searching} {_}/StartQuestEventChannel in {searchLocation}", this);
58
81
  StartQuestEventChannel = Resources.Load<StringEventChannelSO>($"{_}/StartQuestEventChannel");
59
- if (QuestProgress == null)
60
- Debug.LogError($"{_}/StartQuestEventChannel is not {searchLocation} {readInstructions}", this);
82
+ if (StartQuestEventChannel == null)
83
+ {
84
+ errorMessages.Add($"{_}/StartQuestEventChannel is not {searchLocation} {readInstructions}");
85
+ validityCheck = false;
86
+ invalidObjects.Add(StartQuestEventChannel);
87
+ }
61
88
  }
62
89
 
63
- questId = questInfoForPoint.id;
90
+
91
+ if (requirementCheck == null)
92
+ {
93
+ if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
94
+ requirementCheck = Resources.Load<StringEventChannelSO>($"{_}/QuestRequirementCheck");
95
+ if (requirementCheck == null)
96
+ {
97
+ errorMessages.Add($"{_}/QuestRequirementCheck is not {searchLocation} {readInstructions}");
98
+ validityCheck = false;
99
+ invalidObjects.Add(requirementCheck);
100
+ }
101
+ }
102
+
103
+ IsValid = validityCheck;
104
+ if(!IsValid) return;
105
+
106
+ if (IsValid && !Application.isPlaying) return;
107
+ for(var i = 0 ; i < invalidObjects.Count ; i++)
108
+ {
109
+ Debug.LogError($"Error: {errorMessages[i]} " , this.gameObject);
110
+ }
64
111
  }
65
112
 
66
113
  private void OnEnable()
@@ -152,5 +199,6 @@ namespace jeanf.questsystem
152
199
  AllClear(true);
153
200
  if(isDebug) Debug.Log($"Quest start was requested for quest {id}.", this);
154
201
  }
202
+
155
203
  }
156
204
  }
@@ -2,29 +2,31 @@ using System;
2
2
  using System.Collections;
3
3
  using System.Collections.Generic;
4
4
  using jeanf.EventSystem;
5
+ using jeanf.validationTools;
5
6
  using UnityEngine;
6
7
  using UnityEngine.Serialization;
7
8
 
8
9
  namespace jeanf.questsystem
9
10
  {
10
- public class QuestManager : MonoBehaviour, IDebugBehaviour
11
+ public class QuestManager : MonoBehaviour, IDebugBehaviour, IValidatable
11
12
  {
12
13
  public bool isDebug
13
14
  {
14
15
  get => _isDebug;
15
16
  set => _isDebug = value;
16
17
  }
18
+ public bool IsValid { get; private set; }
17
19
 
18
20
  [SerializeField] private bool _isDebug = false;
19
21
 
20
22
  [FormerlySerializedAs("loadQuestState")] [Header("Config")] [SerializeField]
21
23
  private bool loadSavedQuestState = true;
22
24
 
23
- [Header("Broadcasting on:")] [SerializeField]
24
- private StringEventChannelSO questStatusUpdateChannel;
25
- private StringFloatEventChannelSO questProgress;
25
+ [Header("Broadcasting on:")]
26
+ [SerializeField] [Validation("A reference to the questStatusUpdateChannel is required.")] private StringEventChannelSO questStatusUpdateChannel;
27
+ [SerializeField] [Validation("A reference to the questProgress is required.")] private StringFloatEventChannelSO questProgress;
26
28
 
27
- [Header("Listening on:")] [SerializeField] private StringEventChannelSO questStatusUpdateRequested;
29
+ [Header("Listening on:")] [SerializeField] [Validation("A reference to the questStatusUpdateRequested is required.")] private StringEventChannelSO questStatusUpdateRequested;
28
30
 
29
31
  private Dictionary<string, Quest> questMap;
30
32
 
@@ -275,5 +277,68 @@ namespace jeanf.questsystem
275
277
 
276
278
  return quest;
277
279
  }
280
+ private void ValididtyCheck()
281
+ {
282
+ const string searching = "attempting to find";
283
+ const string _ = "Quests/Channels"; // search target
284
+ const string searchLocation = "the resources folder";
285
+ const string readInstructions = "please read the package instruction for further help";
286
+
287
+
288
+ var validityCheck = true;
289
+ var invalidObjects = new List<object>();
290
+ var errorMessages = new List<string>();
291
+
292
+ if (questStatusUpdateChannel == null)
293
+ {
294
+ if (isDebug) Debug.Log($"{searching} {_}/QuestStatusUpdate in {searchLocation}", this);
295
+ questStatusUpdateChannel = Resources.Load<StringEventChannelSO>($"{_}/QuestStatusUpdate");
296
+ if (questStatusUpdateChannel == null)
297
+ {
298
+ errorMessages.Add($"{_}/QuestStatusUpdate is not {searchLocation} {readInstructions}");
299
+ validityCheck = false;
300
+ invalidObjects.Add(questStatusUpdateChannel);
301
+ }
302
+ }
303
+
304
+ if (questProgress == null)
305
+ {
306
+ if (isDebug) Debug.Log($"{searching} {_}/QuestsProgressChannel in {searchLocation}", this);
307
+ questProgress = Resources.Load<StringFloatEventChannelSO>($"{_}/QuestsProgressChannel");
308
+ if (questProgress == null)
309
+ {
310
+ errorMessages.Add($"{_}/QuestsProgressChannel is not {searchLocation} {readInstructions}");
311
+ validityCheck = false;
312
+ invalidObjects.Add(questProgress);
313
+ }
314
+ }
315
+
316
+ if (questStatusUpdateRequested == null)
317
+ {
318
+ if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
319
+ questStatusUpdateRequested = Resources.Load<StringEventChannelSO>($"{_}/QuestRequirementCheck");
320
+ if (questStatusUpdateRequested == null)
321
+ {
322
+ errorMessages.Add($"{_}/QuestRequirementCheck is not {searchLocation} {readInstructions}");
323
+ validityCheck = false;
324
+ invalidObjects.Add(questStatusUpdateRequested);
325
+ }
326
+ }
327
+
328
+ IsValid = validityCheck;
329
+ if(!IsValid) return;
330
+
331
+ if (IsValid && !Application.isPlaying) return;
332
+ for(var i = 0 ; i < invalidObjects.Count ; i++)
333
+ {
334
+ Debug.LogError($"Error: {errorMessages[i]} " , this.gameObject);
335
+ }
336
+ }
337
+ public void OnValidate()
338
+ {
339
+ #if UNITY_EDITOR
340
+ ValididtyCheck();
341
+ #endif
342
+ }
278
343
  }
279
344
  }
@@ -5,7 +5,7 @@ using UnityEngine.Playables;
5
5
 
6
6
  namespace jeanf.questsystem
7
7
  {
8
- public abstract class QuestStep : MonoBehaviour
8
+ public abstract class QuestStep : MonoBehaviour, IDebugBehaviour
9
9
  {
10
10
  private bool isFinished = false;
11
11
  private string questId;
@@ -32,6 +32,7 @@ namespace jeanf.questsystem
32
32
 
33
33
  if (isUsingIntroTimeline && timeline)
34
34
  {
35
+ if(isDebug) Debug.Log($"sending trigger to timeline: {timeline.name}, triggerValue: true");
35
36
  _timelineTriggerEventChannelSo.RaiseEvent(timeline, true);
36
37
  }
37
38
  }
@@ -47,7 +48,8 @@ namespace jeanf.questsystem
47
48
 
48
49
  if (isUsingIntroTimeline && timeline)
49
50
  {
50
- _timelineTriggerEventChannelSo.RaiseEvent(timeline, false);
51
+ if(isDebug) Debug.Log($"sending trigger to timeline: {timeline.name}, triggerValue: false");
52
+ //_timelineTriggerEventChannelSo.RaiseEvent(timeline, false);
51
53
  }
52
54
  }
53
55
  }
@@ -59,5 +61,6 @@ namespace jeanf.questsystem
59
61
  }
60
62
 
61
63
  protected abstract void SetQuestStepState(string state);
64
+ public bool isDebug { get; set; }
62
65
  }
63
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name":"fr.jeanf.questsystem",
3
- "version":"0.0.9",
3
+ "version":"0.0.12",
4
4
  "displayName":"Quest system",
5
5
  "description":"This package uses Scriptable Objects to define quests.",
6
6
  "unity": "2021.3",