| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Text;
- using Unity.EditorCoroutines.Editor;
- using UnityEditor;
- using UnityEngine;
- using System.Linq;
- using System;
- [CustomEditor(typeof(LoadCSV_CardEntity))]
- public class CsvLoader_CardEntity : Editor
- {
- public override void OnInspectorGUI()
- {
- var LoadCSV = target as LoadCSV_CardEntity;
- DrawDefaultInspector();
- if (GUILayout.Button("Create Scriptable Objects"))
- {
- EditorCoroutineUtility.StartCoroutine(SetCsvDataToScriptableObject(LoadCSV), this);
- }
- }
- IEnumerator SetCsvDataToScriptableObject(LoadCSV_CardEntity loadCSV)
- {
- List<TextAsset> CardListTexts = GetAsset.LoadAll<TextAsset>("Assets/TextAsset");
- int value = 0;
- // Check if CSV file is null
- if (loadCSV.csvFile == null)
- {
- Debug.LogWarning("CSV File is null: " + loadCSV.name);
- yield break;
- }
- Debug.Log("CSV File Found: " + loadCSV.name);
- // CSV‚ Text
- string csvText = loadCSV.csvFile.text;
- //Split by new line
- string[] afterParse = csvText.Split('\n');
- //Skip the first line, parse by ","
- for (int i = 1; i < afterParse.Length; i++)
- {
- string[] parseByComma = afterParse[i].Split(',');
- // Ťskip if first column is empty
- if (string.IsNullOrEmpty(parseByComma[0]))
- {
- continue;
- }
- int column = 0;
- string cardImageName = parseByComma[column].CleanTrimString().Replace(".jpg", "").Replace(".png", "").Trim();
- column++;
- yield return EditorCoroutineUtility.StartCoroutine(CreateCardData(cardImageName), this);
- IEnumerator CreateCardData(string CardImageName)
- {
-
- // CardEntity‚ instance created
- CEntity_Base cardEntity = CreateInstance<CEntity_Base>();
- cardEntity.CardSpriteName = CardImageName;
- //Set card effect class name
- cardEntity.CardEffectClassName = parseByComma[column];
- column++;
- //Set card index number
- if (int.TryParse(parseByComma[column], out value))
- {
- cardEntity.CardIndex = value;
- }
- column++;
- //Parse max count (most csv this is empty)
- if (!string.IsNullOrEmpty(parseByComma[column]))
- {
- if (int.TryParse(parseByComma[column], out value))
- {
- cardEntity.MaxCountInDeck = value;
- }
- }
- column++;
- //Get Card Image Name
- string[] parseByUnderBar = CEntity_Base.GetParseByUnderBar(CardImageName);
- cardEntity.CardID = $"{parseByUnderBar[0]}";
- string customCardID = "";
- if (parseByComma.Length >= column + 1)
- {
- if (!string.IsNullOrEmpty(parseByComma[column]))
- {
- if (parseByComma[column].Contains("-"))
- {
- customCardID = parseByComma[column];
- }
- }
- }
- column++;
- //Get Japanese and English card ID
- List<string> CardListIDs_JPN = DataBase.CardListIDs(CEntity_Base.GetParseByHyphen(CardImageName)[0], false);
- List<string> CardListIDs_ENG = DataBase.CardListIDs(CEntity_Base.GetParseByHyphen(CardImageName)[0], true);
- List<TextAsset> CardListTexts_JPN = new List<TextAsset>();
- foreach (TextAsset textAsset in CardListTexts)
- {
- if (CardListIDs_JPN.Contains(textAsset.name))
- {
- CardListTexts_JPN.Add(textAsset);
- }
- }
- List<TextAsset> CardListTexts_ENG = new List<TextAsset>();
- foreach (TextAsset textAsset in CardListTexts)
- {
- if (CardListIDs_ENG.Contains(textAsset.name))
- {
- CardListTexts_ENG.Add(textAsset);
- }
- }
- List<string[]> CardDatas_JPN = OfficialCardListUtility.GetCardDatas(CardListTexts_JPN);
- List<string[]> CardDatas_ENG = OfficialCardListUtility.GetCardDatas(CardListTexts_ENG);
- List<int> evoCosts_level = new List<int>();
- List<int> evoCosts_memory = new List<int>();
- OfficialCardListUtility.AttachCardData(cardEntity, CardDatas_JPN, CardDatas_ENG, ref evoCosts_level, ref evoCosts_memory);
- if (cardEntity.cardKind.Contains(CardKind.Digimon))
- {
- if (evoCosts_level.Count >= 1)
- {
- List<CardColor> evoCosts_color = new List<CardColor>();
- //wiki‚grab text from site
- yield return new EditorWaitForSeconds(0.5f);
- WebClient wc = new WebClient();
- wc.Encoding = Encoding.UTF8;
- string resultText = wc.DownloadString($"https://wikimon.net/{cardEntity.CardID}_(DCG)");
- string[] parseByEnter = resultText.Split('\n');
- //�i‰»�R�X�g‚Ě�F
- for (int j = 0; j < parseByEnter.Length; j++)
- {
- string text = parseByEnter[j];
- if (!string.IsNullOrEmpty(text))
- {
- text = text.Replace("\n", "").Replace("\t", "").Replace(" ", "").Trim();
- if (text.Contains(">fromLv."))
- {
- if (text.Contains("linear-gradient"))
- {
- evoCosts_color.Add(CardColor.Red);
- evoCosts_color.Add(CardColor.Blue);
- evoCosts_color.Add(CardColor.Yellow);
- evoCosts_color.Add(CardColor.Green);
- evoCosts_color.Add(CardColor.Black);
- evoCosts_color.Add(CardColor.Purple);
- evoCosts_color.Add(CardColor.White);
- }
- else
- {
- int startIndex = text.IndexOf('#');
- int length = 7;
- text = text.Substring(startIndex, length);
- switch (text)
- {
- case "#cb2e32":
- evoCosts_color.Add(CardColor.Red);
- break;
- case "#0099dc":
- evoCosts_color.Add(CardColor.Blue);
- break;
- case "#f0ac09":
- evoCosts_color.Add(CardColor.Yellow);
- break;
- case "#009f6d":
- evoCosts_color.Add(CardColor.Green);
- break;
- case "#4e4e4e":
- evoCosts_color.Add(CardColor.Black);
- break;
- case "#7e67aa":
- evoCosts_color.Add(CardColor.Purple);
- break;
- case "#ceddef":
- evoCosts_color.Add(CardColor.White);
- break;
- }
- }
- }
- }
- }
- if (evoCosts_color.Count < evoCosts_level.Count)
- {
- if (cardEntity.cardColors.Count >= 1)
- {
- evoCosts_color.Add(cardEntity.cardColors[0]);
- }
- }
- for (int j = 0; j < evoCosts_color.Count; j++)
- {
- EvoCost evoCost = new EvoCost();
- evoCost.CardColor = evoCosts_color[j];
- int level = evoCosts_level[evoCosts_level.Count - 1];
- if (j < evoCosts_level.Count)
- {
- level = evoCosts_level[j];
- }
- evoCost.Level = level;
- int memoryCost = evoCosts_memory[evoCosts_memory.Count - 1];
- if (j < evoCosts_memory.Count)
- {
- memoryCost = evoCosts_memory[j];
- }
- evoCost.MemoryCost = memoryCost;
- cardEntity.EvoCosts.Add(evoCost);
- }
- }
- #region BT9-059(�o�N�‚�“)
- if (cardEntity.CardID == "BT9-059")
- {
- if (cardEntity.EvoCosts.Count((evoCost) => evoCost.CardColor == CardColor.Black && evoCost.MemoryCost == 0 && evoCost.Level == 2) == 0)
- {
- EvoCost evoCost = new EvoCost();
- evoCost.CardColor = CardColor.Black;
- evoCost.MemoryCost = 0;
- evoCost.Level = 2;
- cardEntity.EvoCosts.Add(evoCost);
- }
- }
- #endregion
- #region BT9-041(�‰�C�Y�O�Ś�C�‚�“XŤR‘Ě)
- if (cardEntity.CardID == "BT9-041")
- {
- if (cardEntity.EvoCosts.Count((evoCost) => evoCost.CardColor == CardColor.Red && evoCost.MemoryCost == 4 && evoCost.Level == 4) == 0)
- {
- EvoCost evoCost = new EvoCost();
- evoCost.CardColor = CardColor.Red;
- evoCost.MemoryCost = 4;
- evoCost.Level = 4;
- cardEntity.EvoCosts.Add(evoCost);
- }
- }
- #endregion
- #region BT14-018(�S�b�h�h�‰�‚�“)
- if (cardEntity.CardID == "BT14-018")
- {
- if (cardEntity.EvoCosts.Count((evoCost) => evoCost.CardColor == CardColor.Yellow && evoCost.MemoryCost == 4 && evoCost.Level == 5) == 0)
- {
- EvoCost evoCost = new EvoCost();
- evoCost.CardColor = CardColor.Yellow;
- evoCost.MemoryCost = 4;
- evoCost.Level = 5;
- cardEntity.EvoCosts.Add(evoCost);
- }
- }
- #endregion
- #region ST12-09(�{�‹�P�[�‚�“)
- if (cardEntity.CardID == "ST12-09")
- {
- if (cardEntity.EvoCosts.Count((evoCost) => evoCost.CardColor == CardColor.Black && evoCost.MemoryCost == 4 && evoCost.Level == 4) == 0)
- {
- EvoCost evoCost = new EvoCost();
- evoCost.CardColor = CardColor.Black;
- evoCost.MemoryCost = 4;
- evoCost.Level = 4;
- cardEntity.EvoCosts.Add(evoCost);
- }
- }
- #endregion
- cardEntity.EvoCosts = cardEntity.EvoCosts.Distinct().ToList();
- }
- #region �t�@�C�‹–Ľ‚ƕۑ¶�ć
- //�t�@�C�‹–Ľ
- string fileName = $"{cardEntity.CardName_ENG}-{CardImageName}.asset";
- fileName = fileName.Replace("?", "�H").Replace(":", "�F");
- cardEntity.name = fileName.Replace(".asset", "");
- //•Ű‘¶�ć
- string folderName_SetID = $"{cardEntity.SetID}";
- string folderName_CardColor = $"{DataBase.CardColorNameDictionary[cardEntity.cardColors[0]]}";
- folderName_CardColor = char.ToUpper(folderName_CardColor[0]) + folderName_CardColor.Substring(1);
- string folderName_CardKind = $"{DataBase.CardKindENNameDictionary[cardEntity.cardKind[0]]}";
- string folderPath = $"Assets/CardBaseEntity/{folderName_SetID}/{folderName_CardColor}/{folderName_CardKind}";
- string filePath = $"{folderPath}/{fileName}".Trim().Replace("\t", "").Replace("\n", "").Replace("\r", "").Replace(" ", "");
- //�t�H�‹�_‚Ş–ł‚Ż‚ę‚ÎŤě�¬
- if (!Directory.Exists(folderPath))
- {
- Directory.CreateDirectory(folderPath);
- }
- #endregion
- if (!string.IsNullOrEmpty(customCardID))
- {
- cardEntity.CardID = customCardID;
- }
- // �A�Z�b�g‚Ć‚µ‚ĕۑ¶
- var asset = (CEntity_Base)AssetDatabase.LoadAssetAtPath(filePath, typeof(CEntity_Base));
- if (asset == null)
- {
- // Attempt to create Asset
- AssetDatabase.CreateAsset(cardEntity, filePath);
- }
- else
- {
- // •Ű‘¶�ć‚Ě�p�X‚É�t�@�C�‹‚Ş‚ ‚ę‚Ώ㏑‚«
- EditorUtility.CopySerialized(cardEntity, asset);
- AssetDatabase.SaveAssets();
- }
- AssetDatabase.Refresh();
- Debug.Log($"{i}/{afterParse.Length - 1}:{cardImageName}‚Scriptable Object Created");
- }
- }
- Debug.Log("Card Data Created for: " + loadCSV.name);
- }
- string GetCardDataURL(string CardImageName)
- {
- string URL = "";
- string[] parseByUnderBar = CEntity_Base.GetParseByUnderBar(CardImageName);
- URL = $"https://www.unionarena-tcg.com/jp/cardlist/detail_iframe.php?card_no={parseByUnderBar[3]}/{parseByUnderBar[0]}-{parseByUnderBar[1]}-{parseByUnderBar[2]}";
- return URL;
- }
- }
- /// <summary>
- /// string extension methods
- /// </summary>
- public static partial class StringExtensions
- {
- /// <summary>
- /// Žw’肵‚˝•¶Žš—ń‚Ş‚˘‚‚‚ ‚é‚©
- /// </summary>
- public static int CountOf(this string self, params string[] strArray)
- {
- int count = 0;
- foreach (string str in strArray)
- {
- int index = self.IndexOf(str, 0);
- while (index != -1)
- {
- count++;
- index = self.IndexOf(str, index + str.Length);
- }
- }
- return count;
- }
- /// <summary>
- /// Removes all instances of the specified string from the current string.
- /// </summary>
- public static string CleanTrimString(this string self)
- {
- string cleanString = self;
- if (!string.IsNullOrEmpty(self))
- {
- foreach (string str in new string[] { " ", "\n", "\r", "\t" })
- {
- cleanString = cleanString.Replace(str, "");
- }
- }
- return cleanString.Trim();
- }
- }
|