Scriptum/Assets/Scripts/REFACTORING/Application/Dialogue/Save/MultiDialogue/MultiDialogueDataManager.cs

145 lines
4.4 KiB
C#
Raw Normal View History

2023-01-01 17:03:35 +01:00
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"; } }
2023-01-02 00:05:47 +01:00
[SerializeField]
public List<MultiDialogueData> MultiDialogueDataList;
2023-01-01 17:03:35 +01:00
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();
}
2023-01-02 00:05:47 +01:00
2023-01-01 17:03:35 +01:00
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<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>());
2023-01-02 00:05:47 +01:00
MultiDialogueDataList = DynamicDataList.GetList();
2023-01-01 17:03:35 +01:00
// 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();
2023-01-02 00:05:47 +01:00
2023-01-01 17:03:35 +01:00
// VERy VERY provisional SOLUTION
if (DynamicDataList.GetList().Count == 0)
{
UseDefaultSettings();
}
2023-01-02 00:05:47 +01:00
MultiDialogueDataList = DynamicDataList.GetList();
2023-01-01 17:03:35 +01:00
}
public void RegisterDialogue(MultiDialogue newDialogue)
{
if (DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any())
2023-01-02 00:05:47 +01:00
{
// if dial is already registered - update it
UpdateDialogue(newDialogue);
}
2023-01-01 17:03:35 +01:00
else
{
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
2023-01-02 00:05:47 +01:00
//DynamicDataList.AddElementToList(multiDialogueData); - nie dodwaca bo modyfikacja jednej duplikuje
MultiDialogueDataList.Add(multiDialogueData);
2023-01-01 17:03:35 +01:00
}
}
// update proggress in dialogue - BUT FUNCTION BELOW SYNCH THIS ALREADY righhr???
public void UpdateDialogue(MultiDialogue newDialogue)
{
2023-01-02 00:05:47 +01:00
if (!DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any())
Debug.LogError($"There is no registered dialoge like {newDialogue.SpeakerName}");
2023-01-01 17:03:35 +01:00
else
{
2023-01-02 00:05:47 +01:00
Debug.Log($"Dialogue {newDialogue.SpeakerName} - updated");
2023-01-01 17:03:35 +01:00
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
2023-01-02 00:05:47 +01:00
MultiDialogueDataList.RemoveAll(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName);
// duplicated from registerDialogue
MultiDialogueDataList.Add(multiDialogueData);
2023-01-01 17:03:35 +01:00
}
}
2023-01-02 00:05:47 +01:00
public MultiDialogueData? GetDialogue(MultiDialogue newDialogue)
2023-01-01 17:03:35 +01:00
{
2023-01-02 00:05:47 +01:00
return DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).FirstOrDefault();
2023-01-01 17:03:35 +01:00
}
public override bool SaveDynamicData()
{
2023-01-02 00:05:47 +01:00
return SaveData(MultiDialogueDataList, SceneElementTypeEnum.Dynamic);
2023-01-01 17:03:35 +01:00
}
}