| | 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 | |
|
| 8 | 14 | | private void Awake() { model = new QuestModel(); } |
| | 15 | |
|
| 0 | 16 | | new public QuestModel GetModel() { return cachedModel; } |
| | 17 | |
|
| | 18 | | public override void UpdateFromModel(BaseModel newModel) |
| | 19 | | { |
| 8 | 20 | | if (newModel == null) |
| 1 | 21 | | return; |
| | 22 | |
|
| 7 | 23 | | base.UpdateFromModel(newModel); |
| 7 | 24 | | if (!(newModel is QuestModel quest)) |
| 0 | 25 | | return; |
| | 26 | |
|
| 7 | 27 | | bool isDifferentQuest = cachedModel != null && quest.id != cachedModel.id; |
| 7 | 28 | | cachedModel = (QuestModel) this.model; |
| 7 | 29 | | if (isDifferentQuest) |
| 4 | 30 | | questsController.RemoveQuest(cachedModel); |
| | 31 | |
|
| 7 | 32 | | cachedModel = quest; |
| 7 | 33 | | if (cachedModel != null) |
| 7 | 34 | | questsController.UpdateQuestProgress(cachedModel); |
| 7 | 35 | | } |
| | 36 | |
|
| 0 | 37 | | public override int GetClassId() { return (int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION; } |
| | 38 | |
|
| 6 | 39 | | public override IEnumerator ApplyChanges(BaseModel newJson) { yield break; } |
| | 40 | |
|
| | 41 | | private void OnDestroy() |
| | 42 | | { |
| 4 | 43 | | if (cachedModel != null) |
| 3 | 44 | | questsController.RemoveQuest(cachedModel); |
| 4 | 45 | | } |
| | 46 | | } |