Scriptum/Assets/Scripts/REFACTORING/Models/Chest/ChestBuildModel.cs

85 lines
2.5 KiB
C#
Raw Normal View History

2022-12-21 17:12:47 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
public class ChestBuildModel
{
[SerializeField] public string ChestName;
[SerializeField] public GameObject ChestPrefab;
[SerializeField] public Vector3 Position;
2022-12-21 23:32:51 +01:00
[SerializeField] public List<IndexValuePair<Item>> Content = new List<IndexValuePair<Item>>();
public ChestBuildModel(ChestPrefabAsset chestPrefabAsset)
{
ChestName = chestPrefabAsset.Chest.Name;
ChestPrefab = chestPrefabAsset.Chest.ChestModel;
Position = chestPrefabAsset.Position;
2022-12-21 17:12:47 +01:00
2022-12-21 23:32:51 +01:00
Content.Clear();
foreach (IndexValuePair<EquippableItem> item in chestPrefabAsset.Chest.Content)
{
Content.Add(
new IndexValuePair<Item>(item.Key, item.Value)
);
}
}
2022-12-21 17:12:47 +01:00
public ChestPrefabAsset MapBuildModelToPrefabAssetModel()
{
ChestPrefabAsset chestPrefabAsset = new ChestPrefabAsset(
ChestName,
ChestPrefab.gameObject.name,
Position
);
chestPrefabAsset.Chest = new Chest(ChestPrefab.GetComponent<ChestWrapper>().Chest);
2022-12-21 23:32:51 +01:00
chestPrefabAsset.Chest.ChestModel = ChestPrefab;
2022-12-21 17:12:47 +01:00
chestPrefabAsset.Chest.Name = ChestName;
2022-12-21 23:32:51 +01:00
2022-12-21 17:12:47 +01:00
chestPrefabAsset.Chest.Content = new List<IndexValuePair<EquippableItem>>();
foreach (var ChestElement in Content)
{
var castedObject = ChestElement.Value as EquippableItem;
if (castedObject == null)
chestPrefabAsset.Chest.Content.Add(
new IndexValuePair<EquippableItem>(ChestElement.Key, new EquippableItem(ChestElement.Value))
);
else
chestPrefabAsset.Chest.Content.Add(
new IndexValuePair<EquippableItem>(ChestElement.Key, castedObject)
);
}
return chestPrefabAsset;
}
2022-12-21 23:32:51 +01:00
public static List<ChestBuildModel> ConvertPrefabAssetListToBuildModelList(List<ChestPrefabAsset> chestPrefabAssetList)
{
List<ChestBuildModel> convertedList = new List<ChestBuildModel>();
foreach(var element in chestPrefabAssetList)
{
convertedList.Add(ChestBuildModel.ConvertPrefabAssetModelToBuildModel(element));
}
return convertedList;
}
public static ChestBuildModel ConvertPrefabAssetModelToBuildModel(ChestPrefabAsset chestPrefabAsset)
{
return new ChestBuildModel(chestPrefabAsset);
}
2022-12-21 17:12:47 +01:00
}