using System; using System.Collections.Generic; using System.Linq; using DDD.Interfaces; using DDD.Uis.Tycoon; using Newtonsoft.Json; using Sirenix.OdinInspector; using UnityEngine; namespace DDD.ScriptableObjects { /// /// 제작 도구 열거형 /// 1: 손질, 2: 솥, 3: 튀김, 4: 플레이팅 /// public enum CraftingTool { Cutting = 1, Pot = 2, Frying = 3, Plating = 4 } [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; } [JsonProperty] [field: SerializeField, Tooltip("해시 태그"), BoxGroup("Json 데이터 영역")] public string HashTag { get; set; } [BoxGroup("직접 추가하는 영역")] [JsonIgnore] [field: SerializeField, BoxGroup("직접 추가하는 영역")] public Sprite Sprite { get; set; } [JsonIgnore] [field: SerializeField] public List ValidIngredients { get; set; } [JsonIgnore] [field: ShowInInspector] public Queue CraftingToolQueue { get; set; } [JsonIgnore] [field: SerializeField] public List ValidHashTags { get; set; } [JsonConstructor] public CraftRecipeData(string idx, string name, string description, int price, string ingredientIdx1, int ingredientCount1, string ingredientIdx2, int ingredientCount2, string ingredientIdx3, int ingredientCount3, int craftOrder, string hashTag) { Idx = idx; Name = name; Description = description; Price = price; IngredientIdx1 = ingredientIdx1; IngredientCount1 = ingredientCount1; IngredientIdx2 = ingredientIdx2; IngredientCount2 = ingredientCount2; IngredientIdx3 = ingredientIdx3; IngredientCount3 = ingredientCount3; CraftOrder = craftOrder; HashTag = hashTag; } 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(copy.ValidIngredients); CraftingToolQueue = new Queue(copy.CraftingToolQueue); ValidHashTags = new List(copy.ValidHashTags); } public List GetValidIngredients() { List newList = new List(); 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; } /// /// 제작 순서 큐 /// CraftOrder의 각 자리 숫자를 제작 도구(CraftingTool)로 변환하여 순서대로 큐에 저장합니다. /// 예를 들어 CraftOrder가 213이면, 큐에는 [솥, 손질, 튀김] 순으로 저장됩니다. /// public Queue GetCraftingToolQueue() { Queue newQueue = new Queue(); 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; } public List GetValidHashTags() { List newList = new List(3); newList = HashTag.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); return newList; } } }