| | 1 | | using System; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.QuestsController; |
| | 4 | | using System.Collections; |
| | 5 | | using DCL.Models; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | public class QuestTrackingInfo : BaseComponent |
| | 9 | | { |
| 0 | 10 | | private static IQuestsController questsController => QuestsController.i; |
| | 11 | |
|
| | 12 | | private QuestModel cachedModel; |
| | 13 | |
|
| 5 | 14 | | public override string componentName => "questTrackingComponent"; |
| | 15 | |
|
| 10 | 16 | | private void Awake() { model = new QuestModel(); } |
| | 17 | |
|
| 0 | 18 | | new public QuestModel GetModel() { return cachedModel; } |
| | 19 | |
|
| | 20 | | public override void UpdateFromModel(BaseModel newModel) |
| | 21 | | { |
| 9 | 22 | | if (newModel == null) |
| 1 | 23 | | return; |
| | 24 | |
|
| 8 | 25 | | base.UpdateFromModel(newModel); |
| 8 | 26 | | if (!(newModel is QuestModel quest)) |
| 0 | 27 | | return; |
| | 28 | |
|
| 8 | 29 | | if (string.IsNullOrEmpty(quest.id)) |
| 4 | 30 | | return; |
| | 31 | |
|
| 4 | 32 | | bool isDifferentQuest = cachedModel == null || quest.id != cachedModel.id; |
| 4 | 33 | | if (isDifferentQuest && cachedModel != null) |
| 1 | 34 | | questsController.RemoveQuest(cachedModel); |
| | 35 | |
|
| 4 | 36 | | cachedModel = quest; |
| 4 | 37 | | if (cachedModel != null) |
| 4 | 38 | | questsController.UpdateQuestProgress(cachedModel); |
| 4 | 39 | | } |
| | 40 | |
|
| 1 | 41 | | public override int GetClassId() { return (int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION; } |
| | 42 | |
|
| 7 | 43 | | public override IEnumerator ApplyChanges(BaseModel newJson) { yield break; } |
| | 44 | |
|
| | 45 | | private void OnDestroy() |
| | 46 | | { |
| 5 | 47 | | if (cachedModel != null) |
| 3 | 48 | | questsController.RemoveQuest(cachedModel); |
| 5 | 49 | | } |
| | 50 | | } |