Преглед на файлове

Load JSON, Fixer scripts

mbunch_kascope преди 2 години
родител
ревизия
6d62857ff5

+ 8 - 0
Assets/Editor/Fixing Scripts.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 0eecb10b23bf22140b086092069658c6
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 66 - 0
Assets/Editor/Fixing Scripts/CleanUpClassName.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEditor.SceneManagement;
+using UnityEditor;
+using UnityEngine;
+using UnityEngine.SceneManagement;
+using DCGO.CardEntities;
+
+namespace DCGO.Tools.Repair{
+    public class CleanUpClassName : MonoBehaviour
+    {
+        [MenuItem("Window/DCGO/Repair/Fix Entity Class Names")]
+        static void FixEntityClassNames()
+        {
+            List<CEntity_Base> List = GetAsset.LoadAll<CEntity_Base>("Assets/CardBaseEntity/");
+
+            foreach (CEntity_Base card in List)
+            {
+                card.CardEffectClassName = FixCharactersInClassName(card.CardEffectClassName);
+                EditorUtility.SetDirty(card);
+            }
+                
+
+            Debug.Log("Fixed all class names in CardBaseEntity");
+            return;
+
+            //Parse ScriptableObject Class Name
+            string FixCharactersInClassName(string str)
+            {
+                string name = str;
+
+                name = FixCharactersInName(name);
+
+                name = name
+                    .Replace("-", "_")
+                    .Replace(".", "")
+                    .Replace("'", "")
+                    .Replace("&", "And")
+                    .Replace("(", "")
+                    .Replace(")", "");
+
+                return name;
+            }
+
+            //Parse ScriptableObject Name
+            string FixCharactersInName(string str)
+            {
+                string name = str;
+
+                name = name
+                    .Replace(" ", "_")
+                    .Replace(":", "")
+                    .Replace("?", "")
+                    .Replace("!", "")
+                    .Replace("<", "")
+                    .Replace(">", "");
+
+                return name;
+            }
+        }
+
+        
+    }
+}
+

+ 11 - 0
Assets/Editor/Fixing Scripts/CleanUpClassName.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5a47d53c3e3059143a9e75c648f09280
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 62 - 0
Assets/Editor/Fixing Scripts/GetListOfInvalidClassNames.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEditor.SceneManagement;
+using UnityEditor;
+using UnityEngine;
+using UnityEngine.SceneManagement;
+using DCGO.CardEntities;
+
+namespace DCGO.Tools.Repair 
+{
+    public class GetListOfInvalidClassNames : MonoBehaviour
+    {
+        [MenuItem("Window/DCGO/Repair/Get List of Invalid Class Names")]
+        static void FixEntityClassNames()
+        {
+            List<CEntity_Base> Entities = GetAsset.LoadAll<CEntity_Base>("Assets/CardBaseEntity/");
+            List<string> InvalidClassNames = new List<string>();
+
+            foreach (CEntity_Base card in Entities)
+            {
+                if (CanAttachEffectComponent(card.SetID, card.CardEffectClassName))
+                    continue;
+
+                if(card.EffectDiscription_ENG.Equals("-") 
+                    && card.InheritedEffectDiscription_ENG.Equals("-")
+                    && card.SecurityEffectDiscription_ENG.Equals("-"))
+                    continue;
+
+                if(InvalidClassNames.Contains(card.CardEffectClassName))
+                    continue;
+
+                InvalidClassNames.Add(card.CardEffectClassName);
+                Debug.LogError($"Invalid Class Name: {card.CardEffectClassName}");
+            }
+
+            Debug.Log($"Total Invalid Class Names: {InvalidClassNames.Count}");
+
+            bool CanAttachEffectComponent(string ID, string ClassName)
+            {
+                if (string.IsNullOrEmpty(ClassName))
+                    return false;
+
+                if (Type.GetType(ClassName + ",Assembly-CSharp") == null)
+                {
+                    if (!ClassName.Contains("token"))
+                    {
+                        if (Type.GetType($"DCGO.CardEffects.{ID}.{ClassName},Assembly-CSharp") == null)
+                            return false;
+                    }
+                    else
+                    {
+                        if (Type.GetType($"DCGO.CardEffects.Tokens.{ClassName},Assembly-CSharp") == null)
+                            return false;
+                    }
+                }
+                
+                return true;
+            }
+        }
+    }
+}

+ 11 - 0
Assets/Editor/Fixing Scripts/GetListOfInvalidClassNames.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8e72e82afeed9cf47b793f2e5f64919b
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 396 - 0
Assets/Editor/JSONLoader_CardEntity.cs

@@ -0,0 +1,396 @@
+using System;
+using System.IO;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Unity.EditorCoroutines.Editor;
+using UnityEditor;
+using UnityEngine;
+using UnityEngine.Networking;
+using System.Drawing.Text;
+
+namespace DCGO.CardEntities
+{
+    [CustomEditor(typeof(LoadJSON_CardEntity))]
+    public class JSONLoader_CardEntity : Editor
+    {
+        LoadJSON_CardEntity _loadJSON;
+        string baseURL = "https://raw.githubusercontent.com/TakaOtaku/Digimon-Card-App/main/src/";
+
+        public List<CardData> _cardData;
+
+        string cardIDString = "";
+
+        public override void OnInspectorGUI()
+        {
+            _loadJSON = target as LoadJSON_CardEntity;
+            DrawDefaultInspector();
+
+            if (GUILayout.Button("Get JSON Object"))
+                EditorCoroutineUtility.StartCoroutine(GetJsonData(_loadJSON), this);
+
+            if (_cardData != null)
+            {
+                GUILayout.Label("Card ID: ");
+                cardIDString = GUILayout.TextField(cardIDString, 10).ToUpper();
+
+                if (cardIDString != "")
+                {
+                    if (GUILayout.Button("Create Scriptable Object"))
+                    {
+                        List<CardData> card = _cardData.Where(x => x.cardNumber.Contains(cardIDString)).ToList();
+                        SetDataToScriptableObject(card);
+                    }
+                }
+            }
+        }
+
+        IEnumerator GetJsonData(LoadJSON_CardEntity loadJSON)
+        {
+            string url = baseURL + "assets/cardlists/DigimonCards.json";
+            UnityWebRequest jsonWebRequest = UnityWebRequest.Get(url);
+
+            yield return jsonWebRequest.SendWebRequest();
+
+            if (jsonWebRequest.result != UnityWebRequest.Result.Success)
+            {
+                Debug.Log(jsonWebRequest.error);
+            }
+            else
+            {
+               
+                RootObject root = JsonUtility.FromJson<RootObject>("{\"cards\":" + jsonWebRequest.downloadHandler.text + "}");
+                _cardData = root.cards;
+            }
+
+            yield return null;
+        }
+
+        void SetDataToScriptableObject(List<CardData> data)
+        {
+            foreach (CardData card in data)
+            {
+                CreateScriptableObject(card, card.cardNumber);
+                CreateAA(card);
+            }
+        }
+
+        string GetImageURL(string url, string ID, List<AlternateArt> AA)
+        {
+            string[] urlSplit = url.Split(".");
+            string startURL = urlSplit[0].Substring(0, urlSplit[0].LastIndexOf("/"));
+
+            if (!ID.Contains("Errata") && !ID.Contains("_") && AA.Count > 0)
+            {
+                AlternateArt errata = AA.Where(x => x.id.StartsWith(ID) && x.id.Contains("Errata")).FirstOrDefault();
+
+                if (errata != null)
+                    ID = errata.id;
+            }
+
+            return $"{ID}";
+        }
+
+
+        void CreateScriptableObject(CardData card, string imageID)
+        {
+            // CardEntity‚ instance created
+            CEntity_Base cardEntity = CreateInstance<CEntity_Base>();
+
+            cardEntity.cardColors = GetCardColors(card.color);
+
+            cardEntity.PlayCost = intParse(card.playCost);
+            cardEntity.EvoCosts = GetEvoCosts(card.digivolveCondition,cardEntity.cardColors);
+
+            cardEntity.Level = levelParse(card.cardLv);
+            cardEntity.CardName_ENG = card.name.english;
+
+            cardEntity.Form_ENG = GetCardInfo(card.form);
+            cardEntity.Attribute_ENG = GetCardInfo(card.attribute);
+            cardEntity.Type_ENG = GetCardInfo(card.type);
+
+            cardEntity.CardSpriteName = GetImageURL(card.cardImage, imageID, card.AAs);
+
+            cardEntity.cardKind = DictionaryUtility.GetCardKind(card.cardType.Replace("-",""), DataBase.CardKindENNameDictionary);
+
+            cardEntity.EffectDiscription_ENG = GetEffectDescription(card);
+            cardEntity.InheritedEffectDiscription_ENG = card.digivolveEffect;
+            cardEntity.SecurityEffectDiscription_ENG = card.securityEffect;
+
+            cardEntity.CardEffectClassName = FixCharactersInClassName($"{card.name.english}_{card.cardNumber}");
+
+            cardEntity.DP = intParse(card.dp);
+            cardEntity.rarity = (Rarity)Enum.Parse(typeof(Rarity), card.rarity);
+            cardEntity.OverflowMemory = GetOverflowMemory(card.aceEffect);
+            cardEntity.CardID = card.id;
+            cardEntity.MaxCountInDeck = GetMaxCount(card.restrictions.japanese);
+
+            cardEntity.name = FixCharactersInName($"{cardEntity.CardName_ENG}-{cardEntity.CardSpriteName}"); 
+            cardEntity.CardIndex = GetCardIndex(cardEntity);
+            Debug.Log($"created: {cardEntity.name}");
+
+            SaveScriptableObject(cardEntity);
+        }
+
+        void CreateAA(CardData data)
+        {
+            foreach (AlternateArt AA in data.AAs)
+            {
+                if (!AA.id.Contains("_"))
+                    continue;
+
+                CreateScriptableObject(data, AA.id);
+            }
+        }
+
+        #region Save Scriptable Object
+        void SaveScriptableObject(CEntity_Base entity)
+        {
+            string fileName = $"{entity.name}.asset";
+
+            string folderName_SetID = $"{entity.SetID}";
+            string folderName_CardColor = $"{DataBase.CardColorNameDictionary[entity.cardColors[0]]}";
+            folderName_CardColor = char.ToUpper(folderName_CardColor[0]) + folderName_CardColor.Substring(1);
+
+            string folderName_CardKind = $"{DataBase.CardKindENNameDictionary[entity.cardKind]}";
+            string folderPath = $"Assets/CardBaseEntity/{folderName_SetID}/{folderName_CardColor}/{folderName_CardKind}";
+            string filePath = $"{folderPath}/{fileName}".Trim().Replace("\t", "").Replace("\n", "").Replace("\r", "").Replace(" ", "");
+
+            if (!Directory.Exists(folderPath))
+                Directory.CreateDirectory(folderPath);
+
+            if(File.Exists(filePath))
+            {
+                Debug.Log($"{entity.name} already exists");
+                CEntity_Base asset = (CEntity_Base)AssetDatabase.LoadAssetAtPath(filePath, typeof(CEntity_Base));
+                
+                entity.CardIndex = asset.CardIndex;
+
+                EditorUtility.CopySerialized(entity, asset);
+                AssetDatabase.SaveAssets();
+            }
+            else
+            {
+                AssetDatabase.CreateAsset(entity, filePath);
+            }
+
+            AssetDatabase.Refresh();
+
+            Debug.Log($"{entity.name}: Scriptable Object Created");
+        }
+        #endregion
+
+        #region Parsing Methods
+
+        //Get Card Index
+        int GetCardIndex(CEntity_Base entity)
+        {
+            int index = _loadJSON.setCardIndex;
+
+            if (entity.SetID.Equals("P"))
+            {
+                index = _loadJSON.promoCardIndex;
+                _loadJSON.promoCardIndex++;
+            }
+            else
+                _loadJSON.setCardIndex++;
+
+            EditorUtility.SetDirty(_loadJSON);
+
+            return index;
+        }
+
+        //Parse ScriptableObject Name
+        string FixCharactersInName(string str)
+        {
+            string name = str;
+
+            name = name
+                .Replace(" ", "_")
+                .Replace(":","")
+                .Replace("?","")
+                .Replace("!","")
+                .Replace("<", "")
+                .Replace(">", "");
+
+            return name;
+        }
+
+        //Parse ScriptableObject Class Name
+        public string FixCharactersInClassName(string str)
+        {
+            string name = str;
+
+            name = FixCharactersInName(name);
+
+            name = name
+                .Replace("-", "_")
+                .Replace(".", "")
+                .Replace("'", "")
+                .Replace("&", "And")
+                .Replace("(", "")
+                .Replace(")", "");
+
+            return name;
+        }
+
+        //Parse effect description
+        string GetEffectDescription(CardData card)
+        {
+            string effect = "-";
+            List<string> effects = new List<string>();
+
+            if (card.specialDigivolve != "-")
+                effects.Add($"{card.specialDigivolve}");
+
+            if(card.effect != "-")
+                effects.Add($"{card.effect}");
+
+            if(card.digiXros != "-")
+                effects.Add($"{card.digiXros}");
+
+            if (effects.Count > 0)
+            {
+                effect = "";
+
+                string lastEffect = effects.Last();
+                foreach (string e in effects)
+                {
+                    effect += $"{e}";
+
+                    if (!e.Equals(lastEffect))
+                        effect += "\n\n";
+                }
+                
+            }
+
+            return effect;
+        }
+        //Parse card info split by "/" to list
+        List<string> GetCardInfo(string str)
+        {
+            List<string> strings = new List<string>();
+
+            foreach (string data in str.Split("/"))
+            {
+                strings.Add(data.Trim());
+            }
+
+            return strings;
+        }
+
+        //Parse digivolve conditions to list
+        List<EvoCost> GetEvoCosts(List<DigivolveCondition> digivolveConditions, List<CardColor> cardColors)
+        {
+            List<EvoCost> evoCosts = new List<EvoCost>();
+
+            foreach (DigivolveCondition digivolveCondition in digivolveConditions)
+            {
+                if (digivolveCondition.color.ToLower() == "all")
+                {
+                    foreach (CardColor color in DataBase.cardColors)
+                    {
+                        if (color == CardColor.White || color == CardColor.None)
+                            continue;
+
+                        EvoCost evoCost = new EvoCost();
+
+                        evoCost.CardColor = color;
+
+                        evoCost.Level = int.Parse(digivolveCondition.level);
+                        evoCost.MemoryCost = int.Parse(digivolveCondition.cost);
+
+                        evoCosts.Add(evoCost);
+                    }
+                }
+                else
+                {
+                    EvoCost evoCost = new EvoCost();
+
+                    if (digivolveCondition.color.ToLower() == "")
+                        evoCost.CardColor = cardColors[0];
+                    else
+                        evoCost.CardColor = DictionaryUtility.GetCardColor(digivolveCondition.color.ToLower(), DataBase.CardColorNameDictionary);
+
+                    evoCost.Level = int.Parse(digivolveCondition.level);
+                    evoCost.MemoryCost = int.Parse(digivolveCondition.cost);
+
+                    evoCosts.Add(evoCost);
+                }
+            }
+
+            return evoCosts;
+        }
+
+        //Parse card colors to list
+        List<CardColor> GetCardColors(string colors)
+        {
+            List<CardColor> cardColors = new List<CardColor>();
+
+            foreach (string cardColorName in colors.Split("/"))
+            {
+                foreach (string cardColorNameValues in DataBase.CardColorNameDictionary.Values)
+                {
+                    if (cardColorName.ToLower().Trim() == cardColorNameValues)
+                    {
+                        cardColors.Add(DictionaryUtility.GetCardColor(cardColorName.ToLower().Trim(), DataBase.CardColorNameDictionary));
+                    }
+                }
+            }
+
+            return cardColors;
+        }
+
+        //Parse overflow memory
+        int GetOverflowMemory(string aceEffect)
+        {
+            int value = 0;
+
+            if(aceEffect != "-")
+            {
+                int startIndex = aceEffect.IndexOf("\uff1c") + 1;
+                int endIndex = aceEffect.IndexOf("\uff1e") - startIndex;
+                string overflowMemory = aceEffect.Substring(startIndex, endIndex);
+
+                if (int.TryParse(overflowMemory, out value))
+                    return Math.Abs(value);
+            }
+
+            return value;
+        }
+
+        //Parse Max count in deck
+        int GetMaxCount(string restriction)
+        {
+            int value = 4;
+            if (restriction == "Banned")
+                value = 0;
+
+            if(restriction.StartsWith("Restricted"))
+                value = int.Parse(restriction.Substring(restriction.Length-1));
+
+            return value;
+        }
+
+        int intParse(string str)
+        {
+            int value = 0;
+
+            if (int.TryParse(str, out value))
+                return value;
+
+            return value;
+        }
+
+        int levelParse(string str)
+        {
+            int value = 0;
+
+            if (str.Contains("Lv") && int.TryParse(str.Substring(3, 1), out value))
+                return value;
+
+            return value;
+        }
+        #endregion
+    }
+}

+ 11 - 0
Assets/Editor/JSONLoader_CardEntity.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3df56444aa4cb8c458614eaa845f7245
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 13 - 0
Assets/Scripts/LoadJSON_CardEntity.cs

@@ -0,0 +1,13 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace DCGO.CardEntities
+{
+    [CreateAssetMenu(fileName = "CardEntity_JSONLoader", menuName = "Create JSONLoader/Create JSONLoader_CardEntity")]
+    public class LoadJSON_CardEntity : ScriptableObject
+    {
+        public int setCardIndex;
+        public int promoCardIndex;
+    }
+}

+ 11 - 0
Assets/Scripts/LoadJSON_CardEntity.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f9ac13da4f60f1c4cb0d1a4e2c3b986c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: