Scriptum/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs
2023-01-06 21:54:50 +01:00

150 lines
4.5 KiB
C#

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
class MultiDialogueDataManager : SceneBaseDataManager<MultiDialogueData>
{
protected override string OBJECT_FOLDER_NAME { get { return "MultiDialogue"; } }
protected override string OBJECT_LIST_NAME { get { return "MultiDialogueList"; } }
[SerializeField]
public List<MultiDialogueData> MultiDialogueDataList;
public override void Awake()
{
if (Instance == null)
{
Instance = this;
Debug.Log("Start MultiDialogueData manager");
DynamicDataList = new MultiDialogueDataListManager();
DataLoader = new MultiDialogueDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME);
base.Start();
}
else
{
Destroy(gameObject);
}
}
// ZMIANA KONCEPCJI
// ZMIAST TRZYMAC SUROWE OBIEKTY TYM RAZEM ZAPISUJMY modele Datai updatujmy obiket w NPC Managerze
public override void Start()
{
}
protected override void AfterStart()
{
Debug.Log("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<MultiDialogueData> GetObjectType()
{
return GameObject.FindObjectOfType<MultiDialogueDataManager>();
}
protected SceneBaseDataManager<MultiDialogueData> CreateInstance(ref GameObject managerGameObject)
{
return managerGameObject.AddComponent<MultiDialogueDataManager>();
}
protected override void UseDefaultSettings()
{
DynamicDataList.SetList(new List<MultiDialogueData>());
MultiDialogueDataList = DynamicDataList.GetList();
// 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();
}
MultiDialogueDataList = DynamicDataList.GetList();
}
public void RegisterDialogue(MultiDialogue newDialogue)
{
if (DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any())
{
// if dial is already registered - update it
UpdateDialogue(newDialogue);
}
else
{
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
//DynamicDataList.AddElementToList(multiDialogueData); - nie dodwaca bo modyfikacja jednej duplikuje
MultiDialogueDataList.Add(multiDialogueData);
}
}
// update proggress in dialogue - BUT FUNCTION BELOW SYNCH THIS ALREADY righhr???
public void UpdateDialogue(MultiDialogue newDialogue)
{
if (!DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any())
Debug.LogError($"There is no registered dialoge like {newDialogue.SpeakerName}");
else
{
Debug.Log($"Dialogue {newDialogue.SpeakerName} - updated");
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
MultiDialogueDataList.RemoveAll(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName);
// duplicated from registerDialogue
MultiDialogueDataList.Add(multiDialogueData);
}
}
public MultiDialogueData? GetDialogue(MultiDialogue newDialogue)
{
Debug.Log(DynamicDataList.GetList());
Debug.Log(newDialogue);
return DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).FirstOrDefault();
}
public override bool SaveDynamicData()
{
return SaveData(MultiDialogueDataList, SceneElementTypeEnum.Dynamic);
}
}