Scriptum/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs

108 lines
3.2 KiB
C#
Raw Permalink Normal View History

2022-10-22 18:04:21 +02:00
using System;
using System.Collections.Generic;
using UnityEngine;
public class SceneTaskDataLoader : SceneBaseDataLoader<Task>
{
public SceneTaskDataLoader(string _objectListName, string _objectFolderName)
{
SaveModelSystem = new SaveTaskDataManager();
SaveModelSystem.ObjectFolderName = _objectFolderName;
SaveModelSystem.ObjectListName = _objectListName;
}
// public override List<Task> LoadData(SceneElementTypeEnum type)
// {
// string path = SaveSystem.GetSavePath();
//
// if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load
// return new List<Task>();
//
// FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles();
//
// foreach(FileInfo file in fileInfo)
// {
// if(file.Name != ItemsListName + ".fun")
// continue;
//
// List<Task> taskList = SaveQuestSystem.LoadQuestsList(ItemsListName);
//
// foreach(Task task in taskList)
// Elements.Add(task);
// }
//
// return Elements;
// }
// public override void SaveData(List<Task> _elements, SceneElementTypeEnum type)
// {
// // Case I - if we remember all list
// // 1) if after removed item form DynamicList is empty - remove all file
// // 2) if after removed item form DynamciList there are another one - save updated list again
// if(TaskManager.Instance.taskList.Count > 0) {
// SaveQuestSystem.SaveQuestsList(_elements, ItemsListName);
// } else {
// string _path = SaveSystem.GetSavePath() + "/" + ItemsListName + ".fun";
//
// try
// {
// Debug.Log("File to remove: " + _path);
//
// if(File.Exists(_path))
// {
// File.Delete(_path);
// }
// }
// catch (IOException ioExp)
// {
// Debug.LogError(ioExp.Message);
// }
// }
//
// // Case II - if we rememenber object per file
// // 1) remove specyfic file
// //
// // Unfortunatelly we don't use this way of saving items yet :D
//
// }
protected override List<Task> LoadGenericData()
2022-10-22 18:04:21 +02:00
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();
return SaveModelSystem.LoadModelList();
}
protected override bool SaveGenericData(List<Task> _elements)
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();
try
{
SaveModelSystem.SaveModelList(_elements);
return true;
}
catch (Exception e) { Debug.LogError(e.Message); }
return false;
}
2022-11-27 21:28:55 +01:00
protected override List<Task> LoadDynamicData()
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();
return SaveModelSystem.LoadModelList();
}
2022-10-22 18:04:21 +02:00
2022-11-27 21:28:55 +01:00
protected override bool SaveDynamicData(List<Task> _elements)
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString();
2022-10-22 18:04:21 +02:00
2022-11-27 21:28:55 +01:00
return base.SaveDynamicData(_elements);
}
2022-10-22 18:04:21 +02:00
}