CapersProject/Assets/02.Scripts/DDD/ScriptableObject/Class/CraftRecipeData.cs

161 lines
5.9 KiB
C#
Raw Normal View History

2025-02-03 10:03:41 +00:00
using System;
2025-02-10 02:13:46 +00:00
using System.Collections.Generic;
2025-02-17 21:47:56 +00:00
using System.Linq;
2025-02-10 02:13:46 +00:00
using DDD.Interfaces;
using DDD.Uis.Tycoon;
2025-02-03 10:03:41 +00:00
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using UnityEngine;
namespace DDD.ScriptableObjects
{
2025-02-10 02:13:46 +00:00
/// <summary>
/// 제작 도구 열거형
/// 1: 손질, 2: 솥, 3: 튀김, 4: 플레이팅
/// </summary>
public enum CraftingTool
{
Cutting = 1,
Pot = 2,
Frying = 3,
Plating = 4
}
2025-02-03 10:03:41 +00:00
[Serializable]
public class CraftRecipeData : IIdx
{
[BoxGroup("Json 데이터 영역")]
[JsonProperty]
[field: SerializeField, Tooltip("Idx"), BoxGroup("Json 데이터 영역")]
public string Idx { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("이름"), BoxGroup("Json 데이터 영역")]
public string Name { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("설명"), BoxGroup("Json 데이터 영역")]
public string Description { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("가격"), BoxGroup("Json 데이터 영역")]
public int Price { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("1번 재료 Idx"), BoxGroup("Json 데이터 영역")]
public string IngredientIdx1 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("1번 재료 갯수"), BoxGroup("Json 데이터 영역")]
public int IngredientCount1 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("2번 재료 Idx"), BoxGroup("Json 데이터 영역")]
public string IngredientIdx2 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("2번 재료 갯수"), BoxGroup("Json 데이터 영역")]
public int IngredientCount2 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("3번 재료 Idx"), BoxGroup("Json 데이터 영역")]
public string IngredientIdx3 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("3번 재료 갯수"), BoxGroup("Json 데이터 영역")]
public int IngredientCount3 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("제작 순서"), BoxGroup("Json 데이터 영역")]
public int CraftOrder { get; set; }
2025-02-17 21:47:56 +00:00
[JsonProperty]
[field: SerializeField, Tooltip("해시 태그"), BoxGroup("Json 데이터 영역")]
public string HashTag { get; set; }
2025-02-03 10:03:41 +00:00
[BoxGroup("직접 추가하는 영역")]
2025-02-10 02:13:46 +00:00
[JsonIgnore]
2025-02-03 10:03:41 +00:00
[field: SerializeField, BoxGroup("직접 추가하는 영역")]
public Sprite Sprite { get; set; }
2025-02-10 02:13:46 +00:00
[JsonIgnore]
[field: SerializeField]
2025-02-17 21:47:56 +00:00
public List<CraftingIngredient> ValidIngredients { get; set; }
2025-02-10 02:13:46 +00:00
[JsonIgnore]
[field: ShowInInspector]
2025-02-17 21:47:56 +00:00
public Queue<CraftingTool> CraftingToolQueue { get; set; }
2025-02-10 02:13:46 +00:00
2025-02-17 21:47:56 +00:00
[JsonIgnore]
[field: SerializeField]
public List<string> ValidHashTags { get; set; }
public CraftRecipeData(CraftRecipeData copy)
{
Idx = copy.Idx;
Name = copy.Name;
Description = copy.Description;
Price = copy.Price;
IngredientIdx1 = copy.IngredientIdx1;
IngredientCount1 = copy.IngredientCount1;
IngredientIdx2 = copy.IngredientIdx2;
IngredientCount2 = copy.IngredientCount2;
IngredientIdx3 = copy.IngredientIdx3;
IngredientCount3 = copy.IngredientCount3;
CraftOrder = copy.CraftOrder;
HashTag = copy.HashTag;
Sprite = copy.Sprite;
ValidIngredients = new List<CraftingIngredient>(copy.ValidIngredients);
CraftingToolQueue = new Queue<CraftingTool>(copy.CraftingToolQueue);
ValidHashTags = new List<string>(copy.ValidHashTags);
}
2025-02-10 02:13:46 +00:00
public List<CraftingIngredient> GetValidIngredients()
{
List<CraftingIngredient> newList = new List<CraftingIngredient>();
if (!string.IsNullOrEmpty(IngredientIdx1)) newList.Add(new CraftingIngredient(IngredientIdx1, IngredientCount1));
if (!string.IsNullOrEmpty(IngredientIdx2)) newList.Add(new CraftingIngredient(IngredientIdx2, IngredientCount2));
if (!string.IsNullOrEmpty(IngredientIdx3)) newList.Add(new CraftingIngredient(IngredientIdx3, IngredientCount3));
return newList;
}
/// <summary>
/// 제작 순서 큐
/// CraftOrder의 각 자리 숫자를 제작 도구(CraftingTool)로 변환하여 순서대로 큐에 저장합니다.
/// 예를 들어 CraftOrder가 213이면, 큐에는 [솥, 손질, 튀김] 순으로 저장됩니다.
/// </summary>
public Queue<CraftingTool> GetCraftingToolQueue()
{
Queue<CraftingTool> newQueue = new Queue<CraftingTool>();
string orderString = CraftOrder.ToString();
foreach (char c in orderString)
{
if (int.TryParse(c.ToString(), out int step))
{
// Enum에 정의된 값인지 확인
if (Enum.IsDefined(typeof(CraftingTool), step))
{
newQueue.Enqueue((CraftingTool)step);
}
else
{
Debug.LogError($"유효하지 않은 제작 순서 단계: {step}");
}
}
}
return newQueue;
}
2025-02-17 21:47:56 +00:00
public List<string> GetValidHashTags()
{
List<string> newList = new List<string>(3);
newList = HashTag.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
return newList;
}
2025-02-03 10:03:41 +00:00
}
}