From 1c26fc648b5b03ffca21ae128d3ba29e95de1d5f Mon Sep 17 00:00:00 2001 From: kabix09 Date: Sun, 1 Jan 2023 17:03:35 +0100 Subject: [PATCH] Dialogues - saving --- .../Mission/New Mission Dialogue.asset | 177 ++++++++++++++++++ .../Mission/New Mission Dialogue.asset.meta | 8 + .../Application/Dialogue/Dialogue.cs | 15 ++ .../Dialogue/Manager/DialogueManager.cs | 13 +- .../Application/Dialogue/MultiDialogue.cs | 1 + .../Application/Dialogue/Save.meta | 8 + .../Application/Dialogue/Save/Dialogue.meta | 8 + .../Save/Dialogue/SaveDialogueManager.cs | 103 ++++++++++ .../Save/Dialogue/SaveDialogueManager.cs.meta | 11 ++ .../Save/Dialogue/SceneDialogueDataLoader.cs | 39 ++++ .../Dialogue/SceneDialogueDataLoader.cs.meta | 11 ++ .../Dialogue/Save/MissionDialogue.meta | 8 + .../SaveMissionDialogueManager.cs | 99 ++++++++++ .../SaveMissionDialogueManager.cs.meta | 11 ++ .../Dialogue/Save/MultiDialogue.meta | 8 + .../MultiDialogueDataListManager.cs | 21 +++ .../MultiDialogueDataListManager.cs.meta | 11 ++ .../MultiDialogue/MultiDialogueDataLoader.cs | 39 ++++ .../MultiDialogueDataLoader.cs.meta | 11 ++ .../MultiDialogue/MultiDialogueDataManager.cs | 149 +++++++++++++++ .../MultiDialogueDataManager.cs.meta | 11 ++ .../MultiDialogue/SaveMultiDialogueManager.cs | 102 ++++++++++ .../SaveMultiDialogueManager.cs.meta | 11 ++ .../Application/Mission/Manager.meta | 8 + .../Application/Mission/NpcMissionManager.cs | 2 +- .../REFACTORING/Application/Mission/Save.meta | 8 + .../Mission/Save/SaveMissionManager.cs | 100 ++++++++++ .../Mission/Save/SaveMissionManager.cs.meta | 11 ++ .../Application/NPC/NpcDialogueManager.cs | 30 +++ .../Scripts/REFACTORING/Models/Dialogue.meta | 8 + .../Models/Dialogue/DialogueData.cs | 66 +++++++ .../Models/Dialogue/DialogueData.cs.meta | 11 ++ .../Models/Dialogue/DialogueStepData.cs | 32 ++++ .../Models/Dialogue/DialogueStepData.cs.meta | 11 ++ .../Models/Dialogue/MultiDialogueData.cs | 62 ++++++ .../Models/Dialogue/MultiDialogueData.cs.meta | 11 ++ .../REFACTORING/Models/Mission/Dialogue.meta | 8 + .../Mission/Dialogue/MissionDialogueData.cs | 30 +++ .../Dialogue/MissionDialogueData.cs.meta | 11 ++ .../Dialogue/MissionDialogueStepData.cs | 11 ++ .../Dialogue/MissionDialogueStepData.cs.meta | 11 ++ .../REFACTORING/Models/Mission/MissionData.cs | 34 ++++ .../Models/Mission/MissionData.cs.meta | 11 ++ .../REFACTORING/Models/Mission/Step.meta | 8 + .../Models/Mission/Step/MissionStepData.cs | 23 +++ .../Mission/Step/MissionStepData.cs.meta | 11 ++ .../REFACTORING/Models/Shared/ModelData.cs | 5 + 47 files changed, 1395 insertions(+), 3 deletions(-) create mode 100644 Assets/Resources/Mission/New Mission Dialogue.asset create mode 100644 Assets/Resources/Mission/New Mission Dialogue.asset.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Mission/Manager.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Mission/Save.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Dialogue.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Dialogue.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Step.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs.meta diff --git a/Assets/Resources/Mission/New Mission Dialogue.asset b/Assets/Resources/Mission/New Mission Dialogue.asset new file mode 100644 index 00000000..7be2ee0f --- /dev/null +++ b/Assets/Resources/Mission/New Mission Dialogue.asset @@ -0,0 +1,177 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67587597537a4344cad65ddbcebee119, type: 3} + m_Name: New Mission Dialogue + m_EditorClassIdentifier: + SpeakerName: Luberjack 2 + CurrentStep: 0 + DialogueSteps: + - Header: Luberjack 2 + WasDisplayed: 0 + ListOfSentences: + - Sentence: Could you help me? + Buttons: [] + - Sentence: I lost my chestplate, please found one for me + Buttons: + - ButtonName: Reject miss + Type: 1 + ButtonActions: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp + m_MethodName: RejectMission + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - ButtonName: Accept miss + Type: 1 + ButtonActions: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp + m_MethodName: AcceptMission + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - Sentence: Thank you very much, now go! + Buttons: [] + EndOfDialogueStepAction: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp + m_MethodName: ShowNextPanel + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - Header: Luberjack 2 + WasDisplayed: 0 + ListOfSentences: + - Sentence: Fantastic!! + Buttons: [] + - Sentence: Please take this reward + Buttons: + - ButtonName: Take + Type: 1 + ButtonActions: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp + m_MethodName: GiveReward + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp + m_MethodName: GoToNextSentence + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + EndOfDialogueStepAction: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp + m_MethodName: FinishMission + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - Header: Luberjack 2 + WasDisplayed: 0 + ListOfSentences: + - Sentence: Fantastic!! + Buttons: [] + - Sentence: Please take this reward + Buttons: + - ButtonName: Take + Type: 1 + ButtonActions: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp + m_MethodName: GiveReward + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp + m_MethodName: GoToNextSentence + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + EndOfDialogueStepAction: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 11400000} + m_TargetAssemblyTypeName: MissionDialogue, Assembly-CSharp + m_MethodName: FinishMission + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 diff --git a/Assets/Resources/Mission/New Mission Dialogue.asset.meta b/Assets/Resources/Mission/New Mission Dialogue.asset.meta new file mode 100644 index 00000000..b15bcc3e --- /dev/null +++ b/Assets/Resources/Mission/New Mission Dialogue.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fe2810d79ff17f74eab5cf9a916167b4 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs index 3a8295f6..b70f46ed 100644 --- a/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs @@ -187,11 +187,26 @@ public class Dialogue : ScriptableObject, IDialogue DialogueSteps.ForEach(step => step.WasDisplayed = false); } + public void UpdateDialogueState(DialogueData dialogueData) + { + // 1 Rule - speaker name shouldnt change !!! its our 'key' + + + CurrentStep = dialogueData.CurrentStep; + + for(int i=0; i < dialogueData.DialogueStepModelDataList.Count; i++) + { + DialogueSteps[i].WasDisplayed = dialogueData.DialogueStepModelDataList[i].WasDisplayed; + } + } + public DialogueStepModel GetCurrentStep() {// TODO - argument out of colection :/ return DialogueSteps[CurrentStep]; } + + /* public DialogueStepModel GetCurrentStep() { diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs index b3ee241c..cb67189f 100644 --- a/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs @@ -38,8 +38,8 @@ public class DialogueManager : MonoBehaviour public virtual void Start() { - Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage()); - Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterDialogueStep(dial.Key, dial.Value.ResetDialogue)); // reset dial + // create and config dailogue + CreateInstanceBasedOnLanguage(); } @@ -65,6 +65,7 @@ public class DialogueManager : MonoBehaviour SpeakerName = collision.gameObject.name; } } + public virtual void OnTriggerExit2D(Collider2D collision) { // don't listen when component is disabled @@ -82,6 +83,13 @@ public class DialogueManager : MonoBehaviour } } + public virtual void CreateInstanceBasedOnLanguage() + { + Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage()); + Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterDialogueStep(dial.Key, dial.Value.ResetDialogue)); // reset dial + } + + #region Open Panel API public void OpenDialoguePanel() { if(OpenPanelCondition()) @@ -111,6 +119,7 @@ public class DialogueManager : MonoBehaviour { return !gameObject.GetComponent().enabled; } + #endregion /// /// Opened = 1 diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs index 46468523..76d2c757 100644 --- a/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs @@ -159,6 +159,7 @@ public class MultiDialogue : ScriptableObject, IDialogue public (int, int) DialogueStepStatus() { + Debug.Log(CurrentDialogue); var currentDialogueStepIndex = Dialogues .Where(el => el.Key == CurrentDialogue) .Select(el => el.Value) diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save.meta new file mode 100644 index 00000000..f1bf780f --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bcfd2b5592f0f7448b3f5e7531eb477b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue.meta new file mode 100644 index 00000000..9c2a883d --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0c78516732b397e4dab36038c6b9b48a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs new file mode 100644 index 00000000..4357001c --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs @@ -0,0 +1,103 @@ +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using UnityEngine; + +class SaveDialogueManager : SaveModelSystem +{ + public override bool SaveModelItem(DialogueData model) + { + return base.SaveModelItem(model); + } + + public override bool SaveModelList(List list) + { + BinaryFormatter formatter = new BinaryFormatter(); + + Debug.Log("Saved Dialogue list at " + Path); + + if (!Directory.Exists(Path)) Directory.CreateDirectory(Path); + + /* Main logic of conversion data format */ + var data = list; // ConvertObjectsListToListOfDataModels(list); + + FileStream stream = new FileStream( + Path + GetFileName(ObjectListName), + FileMode.Create + ); + + formatter.Serialize(stream, data); + stream.Close(); + + return true; + } + + public override DialogueData LoadModelItem() + { + return base.LoadModelItem(); + } + + public override List LoadModelList() + { + string path = Path + GetFileName(ObjectListName); + + if (File.Exists(path)) + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream stream = new FileStream(path, FileMode.Open); + + List dialogueList = formatter.Deserialize(stream) as List; + stream.Close(); + + return dialogueList; // ConvertListOfDataModelsToListOfObject(questsList); + } + else + { + Debug.Log("Save file not found in " + path); + } + + return new List(); + } + + // ----------------- USELLES IN THIS CLASS ----------------- + #region unused + // Support function + + // 1. From model to data format + public static DialogueData ConvertObjectToDataModel(Dialogue model) + { + return new DialogueData(model); + } + + public static List ConvertObjectsListToListOfDataModels(List modelsList) + { + List convertedList = new List(); + + foreach (Dialogue model in modelsList) + { + convertedList.Add(ConvertObjectToDataModel(model)); + } + + return convertedList; + } + + // 2. From data to model format + public static Dialogue ConvertDataModelToObject(DialogueData dataModel) + { + return (Dialogue)dataModel.MapDataToObject(); + } + + public static List ConvertListOfDataModelsToListOfObject(List dataModelsList) + { + List convertedList = new List(); + + foreach (DialogueData dataModel in dataModelsList) + { + convertedList.Add(ConvertDataModelToObject(dataModel)); + } + + return convertedList; + } + #endregion +} + diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs.meta new file mode 100644 index 00000000..26c3e509 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SaveDialogueManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5848318111a931049bb98f6b4ca78da2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs new file mode 100644 index 00000000..d3345c88 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +class SceneDialogueDataLoader : SceneBaseDataLoader +{ + public SceneDialogueDataLoader(string _objectListName, string _objectFolderName) + { + SaveModelSystem = new SaveDialogueManager(); + SaveModelSystem.ObjectFolderName = _objectFolderName; + SaveModelSystem.ObjectListName = _objectListName; + } + + protected override List LoadDynamicData() + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString(); + + return SaveModelSystem.LoadModelList(); + } + + protected override bool SaveDynamicData(List _elements) + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString(); + + return base.SaveDynamicData(_elements); + } + + protected override List LoadGenericData() + { + throw new NotImplementedException(); + } + + protected override bool SaveGenericData(List _elements) + { + throw new NotImplementedException(); + } +} + diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs.meta new file mode 100644 index 00000000..6a2a3ee5 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/Dialogue/SceneDialogueDataLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 97f93c62abf28c4478dd2498cbdc6bb2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue.meta new file mode 100644 index 00000000..8204d97a --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f9901c90ea94816419fb6bae13203bc0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs new file mode 100644 index 00000000..1f952590 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using UnityEngine; + +class SaveMissionDialogueManager : SaveModelSystem +{ + public override bool SaveModelItem(MissionDialogue model) + { + return base.SaveModelItem(model); + } + + public override bool SaveModelList(List list) + { + BinaryFormatter formatter = new BinaryFormatter(); + + Debug.Log("Saved MissionDialogue list at " + Path); + + if (!Directory.Exists(Path)) Directory.CreateDirectory(Path); + + /* Main logic of conversion data format */ + var data = ConvertObjectsListToListOfDataModels(list); + + FileStream stream = new FileStream( + Path + GetFileName(ObjectListName), + FileMode.Create + ); + + formatter.Serialize(stream, data); + stream.Close(); + + return true; + } + + public override MissionDialogue LoadModelItem() + { + return base.LoadModelItem(); + } + + public override List LoadModelList() + { + string path = Path + GetFileName(ObjectListName); + + if (File.Exists(path)) + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream stream = new FileStream(path, FileMode.Open); + + List questsList = formatter.Deserialize(stream) as List; + stream.Close(); + + return ConvertListOfDataModelsToListOfObject(questsList); + } + else + { + Debug.Log("Save file not found in " + path); + } + + return new List(); + } + + // Support function + + // 1. From model to data format + public static MissionDialogueData ConvertObjectToDataModel(MissionDialogue model) + { + return new MissionDialogueData(); //model + } + + public static List ConvertObjectsListToListOfDataModels(List modelsList) + { + List convertedList = new List(); + + foreach (MissionDialogue model in modelsList) + { + convertedList.Add(ConvertObjectToDataModel(model)); + } + + return convertedList; + } + + // 2. From data to model format + public static MissionDialogue ConvertDataModelToObject(MissionDialogueData dataModel) + { + return (MissionDialogue)dataModel.MapDataToObject(); + } + + public static List ConvertListOfDataModelsToListOfObject(List dataModelsList) + { + List convertedList = new List(); + + foreach (MissionDialogueData dataModel in dataModelsList) + { + convertedList.Add(ConvertDataModelToObject(dataModel)); + } + + return convertedList; + } +} diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs.meta new file mode 100644 index 00000000..b64b804e --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MissionDialogue/SaveMissionDialogueManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3c2c75847d80f84419115a7391404cb7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue.meta new file mode 100644 index 00000000..aed15f93 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 62b16bbb03d6dce4cbb52d00e48d1279 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs new file mode 100644 index 00000000..3c0f6917 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +public class MultiDialogueDataListManager : DataListManager +{ + // WE DONT NEED HERE UI MANAGER - because dialoges ane;t associated with ui panels in way like inventory / chest or shop + + public override void AddElementToList(MultiDialogueData newElement) + { + Elements.Add(newElement); + } + + public override void RemoveElementFromList(MultiDialogueData element) + { + throw new NotImplementedException(); + } +} + diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs.meta new file mode 100644 index 00000000..c4af7911 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataListManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45bf2866ffc8d3e4fb559f39001e686f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs new file mode 100644 index 00000000..89dc6d22 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +class MultiDialogueDataLoader : SceneBaseDataLoader +{ + public MultiDialogueDataLoader(string _objectListName, string _objectFolderName) + { + SaveModelSystem = new SaveMultiDialogueManager(); + SaveModelSystem.ObjectFolderName = _objectFolderName; + SaveModelSystem.ObjectListName = _objectListName; + } + + protected override List LoadDynamicData() + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString(); + + return SaveModelSystem.LoadModelList(); + } + + protected override bool SaveDynamicData(List _elements) + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString(); + + return base.SaveDynamicData(_elements); + } + + protected override List LoadGenericData() + { + throw new NotImplementedException(); + } + + protected override bool SaveGenericData(List _elements) + { + throw new NotImplementedException(); + } +} + diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs.meta new file mode 100644 index 00000000..2c0f5fd1 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 28e9da3ea5847074892b3af3d9cd1027 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs new file mode 100644 index 00000000..82f213ff --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs @@ -0,0 +1,149 @@ +using System; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.SceneManagement; + +class MultiDialogueDataManager : SceneBaseDataManager +{ + protected override string OBJECT_FOLDER_NAME { get { return "MultiDialogue"; } } + protected override string OBJECT_LIST_NAME { get { return "MultiDialogueList"; } } + + public override void Awake() + { + if (Instance == null) + { + Instance = this; + } + else + { + Destroy(gameObject); + } + } + + // ZMIANA KONCEPCJI + // ZMIAST TRZYMAC SUROWE OBIEKTY TYM RAZEM ZAPISUJMY modele Datai updatujmy obiket w NPC Managerze + public override void Start() + { + Debug.Log("Start MultiDialogueData manager"); + + + DynamicDataList = new MultiDialogueDataListManager(); + + DataLoader = new MultiDialogueDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME); + + + base.Start(); + } + + // TODO - save ChestPrefabAsset (we need to save coords...) but in manager handle Chest data.. + // + protected override void AfterStart() + { + if (OnMapAppearanceMethod.GameStatus == GameStatus.NewGame) + { + if (OnMapAppearanceMethod.Gateway != OnMapAppearanceMethodEnum.NewGame) + UseDynamicSettings(); // if there is nothing saved we will use UseDefaultSettings + else + UseDefaultSettings(); + } + else + { + UseDynamicSettings(); + } + } + + + protected SceneBaseDataManager GetObjectType() + { + return GameObject.FindObjectOfType(); + } + + protected SceneBaseDataManager CreateInstance(ref GameObject managerGameObject) + { + return managerGameObject.AddComponent(); + } + + + + protected override void UseDefaultSettings() + { + DynamicDataList.SetList(new List()); + UiManager.SetList(new List()); + // we dont need to convert anything + // Instead of build elements on scene we collect shops distracted on scene from npc's + } + + protected override void UseDynamicSettings() + { + // when chest detect player in near arrea and player press "c" + // open panel -> chest controller handle Open panel in Scene Chest Manager passing info about what Chest Palyer want to open + // Manager Build panel and pass info about chest content + + LoadDynamicData(); + + // VERy VERY provisional SOLUTION + if (DynamicDataList.GetList().Count == 0) + { + UseDefaultSettings(); + return; + } + + UiManager.SetList(DynamicDataList.GetList()); + } + + + public void RegisterDialogue(MultiDialogue newDialogue) + { + if (DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any()) + Debug.LogError("In MultiDialgoue Manager there is register this dialogue already"); + else + { + var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue); + + DynamicDataList.AddElementToList(multiDialogueData); + + UiManager.SetList(DynamicDataList.GetList()); + } + } + + // update proggress in dialogue - BUT FUNCTION BELOW SYNCH THIS ALREADY righhr??? + public void UpdateDialogue(MultiDialogue newDialogue) + { + Debug.Log("Update multi-dialogue ion manager list"); + if (DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any()) + Debug.LogError("In MultiDialgoue Manager there is register this dialogue already"); + else + { + var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue); + + DynamicDataList.AddElementToList(multiDialogueData); + + UiManager.SetList(DynamicDataList.GetList()); + } + } + + public MultiDialogueData GetDialogue(MultiDialogue newDialogue) + { + return DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).First(); + } + + public override bool SaveDynamicData() + { + // TODO + // how to get list + // 1. List in UI manager should be synchronized with list in this manager + foreach (MultiDialogueData multiDialogue in UiManager.GetList()) + { + DynamicDataList.GetList().Where(el => el.SpeakerName == multiDialogue.SpeakerName).ToList().ForEach(el => el = multiDialogue); + } + + //DynamicDataList.SetList(tmp); + + // approach: + // 1. get from outside, update local list && us it + // 2. Handle list synchronized all the time & pass local list + return SaveData(DynamicDataList?.GetList(), SceneElementTypeEnum.Dynamic); + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs.meta new file mode 100644 index 00000000..bd5416bf --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ebc89f7b8b469d448c3787923ceb966 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs new file mode 100644 index 00000000..a0064608 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs @@ -0,0 +1,102 @@ +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using UnityEngine; + +class SaveMultiDialogueManager : SaveModelSystem +{ + public override bool SaveModelItem(MultiDialogueData model) + { + return base.SaveModelItem(model); + } + + public override bool SaveModelList(List list) + { + BinaryFormatter formatter = new BinaryFormatter(); + + Debug.Log("Saved MultiDialogue list at " + Path); + + if (!Directory.Exists(Path)) Directory.CreateDirectory(Path); + + /* Main logic of conversion data format */ + var data = list; // ConvertObjectsListToListOfDataModels(list); + + FileStream stream = new FileStream( + Path + GetFileName(ObjectListName), + FileMode.Create + ); + + formatter.Serialize(stream, data); + stream.Close(); + + return true; + } + + public override MultiDialogueData LoadModelItem() + { + return base.LoadModelItem(); + } + + public override List LoadModelList() + { + string path = Path + GetFileName(ObjectListName); + + if (File.Exists(path)) + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream stream = new FileStream(path, FileMode.Open); + + List dialogueList = formatter.Deserialize(stream) as List; + stream.Close(); + + return dialogueList; // ConvertListOfDataModelsToListOfObject(questsList); + } + else + { + Debug.Log("Save file not found in " + path); + } + + return new List(); + } + + // ----------------- USELLES IN THIS CLASS ----------------- + #region unused + // Support function + + // 1. From model to data format + public static MultiDialogueData ConvertObjectToDataModel(MultiDialogue model) + { + return new MultiDialogueData(model); + } + + public static List ConvertObjectsListToListOfDataModels(List modelsList) + { + List convertedList = new List(); + + foreach (MultiDialogue model in modelsList) + { + convertedList.Add(ConvertObjectToDataModel(model)); + } + + return convertedList; + } + + // 2. From data to model format + public static MultiDialogue ConvertDataModelToObject(MultiDialogueData dataModel) + { + return (MultiDialogue)dataModel.MapDataToObject(); + } + + public static List ConvertListOfDataModelsToListOfObject(List dataModelsList) + { + List convertedList = new List(); + + foreach (MultiDialogueData dataModel in dataModelsList) + { + convertedList.Add(ConvertDataModelToObject(dataModel)); + } + + return convertedList; + } + #endregion +} diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs.meta new file mode 100644 index 00000000..3277641a --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/SaveMultiDialogueManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 472171b0cb138d546baea600f3576cc6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Mission/Manager.meta b/Assets/Scripts/REFACTORING/Application/Mission/Manager.meta new file mode 100644 index 00000000..b48ff023 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Mission/Manager.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4dac101751423ca41b7ef883b0c6288c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Mission/NpcMissionManager.cs b/Assets/Scripts/REFACTORING/Application/Mission/NpcMissionManager.cs index 03b7f027..fa0994b5 100644 --- a/Assets/Scripts/REFACTORING/Application/Mission/NpcMissionManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Mission/NpcMissionManager.cs @@ -20,7 +20,7 @@ public class NpcMissionManager : DialogueManager // ScriptableObject public DialogueStepModel FreeDialogue; // List, Value : UnityEvent> - public List, MissionProcess>> EndactionEventList; + //public List, MissionCondition>> EndactionEventList; public void Start() diff --git a/Assets/Scripts/REFACTORING/Application/Mission/Save.meta b/Assets/Scripts/REFACTORING/Application/Mission/Save.meta new file mode 100644 index 00000000..a9beb4df --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Mission/Save.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 447e7b25e59ae614982fb6e6c7d1d314 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs b/Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs new file mode 100644 index 00000000..97147a40 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs @@ -0,0 +1,100 @@ +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using UnityEngine; + + +class SaveMissionManager : SaveModelSystem +{ + public override bool SaveModelItem(Mission model) + { + return base.SaveModelItem(model); + } + + public override bool SaveModelList(List list) + { + BinaryFormatter formatter = new BinaryFormatter(); + + Debug.Log("Saved Mision list at " + Path); + + if (!Directory.Exists(Path)) Directory.CreateDirectory(Path); + + /* Main logic of conversion data format */ + var data = ConvertObjectsListToListOfDataModels(list); + + FileStream stream = new FileStream( + Path + GetFileName(ObjectListName), + FileMode.Create + ); + + formatter.Serialize(stream, data); + stream.Close(); + + return true; + } + + public override Mission LoadModelItem() + { + return base.LoadModelItem(); + } + + public override List LoadModelList() + { + string path = Path + GetFileName(ObjectListName); + + if (File.Exists(path)) + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream stream = new FileStream(path, FileMode.Open); + + List questsList = formatter.Deserialize(stream) as List; + stream.Close(); + + return ConvertListOfDataModelsToListOfObject(questsList); + } + else + { + Debug.Log("Save file not found in " + path); + } + + return new List(); + } + + // Support function + + // 1. From model to data format + public static MissionData ConvertObjectToDataModel(Mission model) + { + return new MissionData(); //model + } + + public static List ConvertObjectsListToListOfDataModels(List modelsList) + { + List convertedList = new List(); + + foreach (Mission model in modelsList) + { + convertedList.Add(ConvertObjectToDataModel(model)); + } + + return convertedList; + } + + // 2. From data to model format + public static Mission ConvertDataModelToObject(MissionData dataModel) + { + return (Mission)dataModel.MapDataToObject(); + } + + public static List ConvertListOfDataModelsToListOfObject(List dataModelsList) + { + List convertedList = new List(); + + foreach (MissionData dataModel in dataModelsList) + { + convertedList.Add(ConvertDataModelToObject(dataModel)); + } + + return convertedList; + } +} diff --git a/Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs.meta new file mode 100644 index 00000000..69cdbfc0 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Mission/Save/SaveMissionManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 09be5e44216394646872bb93d0de295e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs b/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs index 6fbf70ee..a14277e3 100644 --- a/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs +++ b/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs @@ -14,7 +14,18 @@ public class NpcDialogueManager : DialogueManager CanBeOpened = false; OpenInDefaultWay = false; + + // UPDATE DIALOGUE + // search in scene manager list + var machedDialogueData = ((MultiDialogueDataManager)MultiDialogueDataManager.Instance).GetDialogue(Dialogue); + if(Dialogue != null && machedDialogueData != null) + { + Debug.Log("Multi Dialogue - updated"); + UpdateDialogueState(machedDialogueData); + } } + + #region Open Panel API public override bool OpenPanelCondition() { /* @@ -30,7 +41,25 @@ public class NpcDialogueManager : DialogueManager { return !gameObject.GetComponent().enabled; } + #endregion + public void UpdateDialogueState(MultiDialogueData dialogueData) + { + // 1 Rule - speaker name shouldnt change !!! its our 'key' + + Dialogue.CurrentDialogue = dialogueData.CurrentDialogue; + + foreach(var singleDialogue in dialogueData.DialogueStepModelDataList) + { + Dialogue.Dialogues + .Where(dial => dial.Key == singleDialogue.Key) + .Select(dial => dial.Value) + .ToList() + .ForEach(dial => dial.UpdateDialogueState(singleDialogue.Value) ); + } + } + + #region Dialogue actions API /// /// Function to invoke actions declared in manager on object from scene not onto asset /// @@ -74,4 +103,5 @@ public class NpcDialogueManager : DialogueManager EndactionEventList.Where(el => el.Key.Key == dialogueProgress.Item1 & el.Key.Value == dialogueProgress.Item2).ToList().ForEach(el => el.Value.Invoke()); } + #endregion } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Dialogue.meta b/Assets/Scripts/REFACTORING/Models/Dialogue.meta new file mode 100644 index 00000000..864cfb2f --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Dialogue.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7c493b82cec044e45be26deb952b98b0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs new file mode 100644 index 00000000..f1b0c5a9 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +[Serializable] +public abstract class DialogueData : ModelData +{ + protected override string SPRITE_LOCALIZATION => ""; + protected override string MODEL_LOCALIZATION => "Dialogue/"; + + [SerializeField] + public int CurrentStep; + + [SerializeField] + public List DialogueStepModelDataList = new List(); +} + +public class DialogueData : DialogueData +{ + + /// + /// build Data model based on Object + /// + /// + public DialogueData(Dialogue dialogue) + { + CurrentStep = dialogue.CurrentStep; + + DialogueStepModelDataList.Clear(); + + foreach(DialogueStepModel dialogueStepModelData in dialogue.DialogueSteps) + { + /* + * pass WasDisplayed value from model to data representative class + */ + DialogueStepModelDataList.Add(new DialogueStepData(dialogueStepModelData.WasDisplayed)); + } + } + + #region NotImplemented + /* + * we dont want to map it here, we will mark fields in NpcDialogfeManager after each loading and fetching dialogue + */ + public override Dialogue MapDataToObject(string prefarbAssetName) + { + throw new NotImplementedException(); + } + + /* + * we dont want to map it here, we will mark fields in NpcDialogfeManager after each loading and fetching dialogue + */ + public override Dialogue MapDataToObject() + { + throw new NotImplementedException(); + } + + protected override Dialogue TryFindResource(string modelName) + { + throw new NotImplementedException(); + } + #endregion +} + diff --git a/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs.meta b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs.meta new file mode 100644 index 00000000..a46e0a36 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 062452edb267909499c0d6c30f831583 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs new file mode 100644 index 00000000..d48d4b49 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +[Serializable] +public class DialogueStepData : IModelMapper +{ + [SerializeField] + public bool WasDisplayed; + + // we dont need nothig more from mapped class model + //public List ListOfSentences = new List(); + + public DialogueStepData(bool wasDisplayed = false) + { + WasDisplayed = wasDisplayed; + } + + public DialogueStepModel MapDataToObject(string prefarbAssetName) + { + throw new NotImplementedException(); + } + + public DialogueStepModel MapDataToObject() + { + throw new NotImplementedException(); + } +} + diff --git a/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs.meta b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs.meta new file mode 100644 index 00000000..a11befd9 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Dialogue/DialogueStepData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1058be8a3d7c1474c923356995db1a96 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs b/Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs new file mode 100644 index 00000000..4ffc5a18 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +[Serializable] +public abstract class MultiDialogueData : ModelData +{ + protected override string SPRITE_LOCALIZATION => ""; + protected override string MODEL_LOCALIZATION => "Dialogue/"; + + [SerializeField] + public string SpeakerName; + + [SerializeField] + public int CurrentDialogue; + + [SerializeField] + public List> DialogueStepModelDataList = new List>(); +} + +public class MultiDialogueData : MultiDialogueData +{ + public MultiDialogueData(MultiDialogue dialogue) + { + SpeakerName = dialogue.SpeakerName; + + CurrentDialogue = dialogue.CurrentDialogue; + + DialogueStepModelDataList.Clear(); + + foreach(IndexValuePair DialogueStepModelData in dialogue.Dialogues) + { + DialogueStepModelDataList.Add( + new IndexValuePair( + DialogueStepModelData.Key, + new DialogueData(DialogueStepModelData.Value) + ) + ); + } + } + + #region NotImplemented + public override MultiDialogue MapDataToObject(string prefarbAssetName) + { + throw new NotImplementedException(); + } + + public override MultiDialogue MapDataToObject() + { + throw new NotImplementedException(); + } + + protected override MultiDialogue TryFindResource(string modelName) + { + throw new NotImplementedException(); + } + #endregion +} + diff --git a/Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs.meta b/Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs.meta new file mode 100644 index 00000000..4a043390 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Dialogue/MultiDialogueData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 60a249cd2c2f413428cdf925f2a9afe1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Dialogue.meta b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue.meta new file mode 100644 index 00000000..ce83ab33 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 55458af5ff6b5d74d8aeb510212280cf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs new file mode 100644 index 00000000..9074947c --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +class MissionDialogueData : DialogueData +{ + protected override string SPRITE_LOCALIZATION => ""; + protected override string MODEL_LOCALIZATION => "Mission/Dialogue/"; + + + + + public override MissionDialogue MapDataToObject(string prefarbAssetName) + { + throw new NotImplementedException(); + } + + public override MissionDialogue MapDataToObject() + { + throw new NotImplementedException(); + } + + protected override MissionDialogue TryFindResource(string modelName) + { + throw new NotImplementedException(); + } +} + diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs.meta b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs.meta new file mode 100644 index 00000000..9c347124 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13df471a010fd0144a583d1b723e97cf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs new file mode 100644 index 00000000..af7d5266 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +class MissionDialogueStepData +{ + +} + diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs.meta b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs.meta new file mode 100644 index 00000000..6829356b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Dialogue/MissionDialogueStepData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 65cb4fb8a7aa29641b4979c6ea2ad31f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs b/Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs new file mode 100644 index 00000000..968c786b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +[Serializable] +class MissionData : ModelData +{ + [SerializeField] + public MissionStatusEnum Status = MissionStatusEnum.None; + + [SerializeField] + public int CurrentStep = 0; + + [SerializeField] + public List MissionStepsDataList = new List(); + + public override Mission MapDataToObject(string prefarbAssetName) + { + throw new NotImplementedException(); + } + + public override Mission MapDataToObject() + { + throw new NotImplementedException(); + } + + protected override Mission TryFindResource(string modelName) + { + throw new NotImplementedException(); + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs.meta b/Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs.meta new file mode 100644 index 00000000..c87dc73e --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/MissionData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a81a0be5f1e38674889a76e2e3766565 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Step.meta b/Assets/Scripts/REFACTORING/Models/Mission/Step.meta new file mode 100644 index 00000000..c7e9454b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Step.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a64ddd7881e399144bc46d4de971b2f7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs b/Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs new file mode 100644 index 00000000..8371c195 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +class MissionStepData : IModelMapper +{ + MissionStepStatusEnum Status; + + MissionDialogueData MissionDialogueData; + + public MissionStepModel MapDataToObject(string prefarbAssetName) + { + throw new NotImplementedException(); + } + + public MissionStepModel MapDataToObject() + { + throw new NotImplementedException(); + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs.meta b/Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs.meta new file mode 100644 index 00000000..a6e7721b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Mission/Step/MissionStepData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f5c259e2178013d4b86ee505e90a4716 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs b/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs index 931489a7..8ff4125d 100644 --- a/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs +++ b/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs @@ -37,4 +37,9 @@ public abstract class ModelData : IModelMapper public abstract T MapDataToObject(string prefarbAssetName); public abstract T MapDataToObject(); +} + +public abstract class ModelData : ModelData +{ + } \ No newline at end of file