Scriptum/Assets/Scripts/REFACTORING/Application/Panel/Shop/SceneShopDataLoader.cs
kabix09 88ab6bcee7 Add Shop module
Add Shop panel & saving module
2022-12-19 03:34:45 +01:00

109 lines
4.0 KiB
C#

using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class SceneShopDataLoader : SceneBaseDataLoader<Shop>
{
public SceneShopDataLoader(string _objectListName, string _objectFolderName)
{
SaveModelSystem = new SaveShopManager();
SaveModelSystem.ObjectFolderName = _objectFolderName;
SaveModelSystem.ObjectListName = _objectListName;
}
/*
public void LoadInventoryItemsList()
{
string path = SaveSystem.GetSavePath();
if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load
return;
FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles();
foreach(FileInfo file in fileInfo)
{
if(file.Name != this.ItemsListName + ".fun")
continue;
Dictionary<int, EquippableItemPrefabAssetData> equippableItemsList = SaveInventorySystem.LoadInventoryItemsList(this.ItemsListName);
// itemEntry.Value.MapDataToObject() - map data format to object
// save object
foreach(KeyValuePair<int, EquippableItemPrefabAssetData> itemEntry in equippableItemsList)
{
InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.MapDataToEquippableItemPrefarbAsset().equippableItem);
}
}
}
public void SaveInventoryItems()
{
// 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(InventoryManager.Instance._items.Count > 0) {
// 1. Map From Dictionary<int, Item>' to 'Dictionary<int, EquippableItemPrefabAsset>'
Dictionary<int, EquippableItemPrefabAsset> mappedList = new Dictionary<int, EquippableItemPrefabAsset>();
foreach(KeyValuePair<int, Item> itemElement in InventoryManager.Instance._items)
{
mappedList[itemElement.Key] = new EquippableItemPrefabAsset(
itemElement.Value.Name,
itemElement.Value.ItemModel.name,
new Vector3(0,0,0),
(EquippableItem) itemElement.Value
);
}
// 2. Save Items
SaveInventorySystem.SaveInventoryItemsList(mappedList, this.ItemsListName);
} else {
string _path = SaveSystem.GetSavePath() + "/" + this.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<Shop> LoadDynamicData()
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString();
return SaveModelSystem.LoadModelList();
}
protected override bool SaveDynamicData(List<Shop> _elements)
{
SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString();
return base.SaveDynamicData(_elements);
}
protected override List<Shop> LoadGenericData() { throw new NotImplementedException(); }
protected override bool SaveGenericData(List<Shop> _elements) { throw new NotImplementedException(); }
}