CheckDeckCodeParse.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. using UnityEditor;
  8. using UnityEngine;
  9. public class CheckDeckCodeParse : MonoBehaviour
  10. {
  11. static CEntity_Base GetCardFromCardID(string cardID)
  12. {
  13. CEntity_Base card = null;
  14. card = ContinuousController.instance.CardList.ToList().Find(cEntity_Base => cEntity_Base.CardID == cardID);
  15. if(card == null)
  16. return ContinuousController.instance.CardList.ToList().Find(cEntity_Base => cEntity_Base.CardSpriteName == cardID);
  17. return card;
  18. }
  19. static string GetCardID(string line)
  20. {
  21. line = line.TrimEnd();
  22. int lastSpaceIndex = line.LastIndexOf(" ");
  23. string cardID = line.Substring(lastSpaceIndex + 1);
  24. return cardID;
  25. }
  26. [MenuItem("Window/DCGO/CheckDeckCodeParse")]
  27. static void CheckDeckParse()
  28. {
  29. string deckCode = GUIUtility.systemCopyBuffer;
  30. Debug.Log($"DeckCode\n{deckCode}");
  31. int value;
  32. List<CEntity_Base> AllDeckCards = new List<CEntity_Base>();
  33. if (!string.IsNullOrEmpty(deckCode))
  34. {
  35. Debug.Log($"DeckCode\n{deckCode}");
  36. using (StringReader reader = new StringReader(deckCode))
  37. {
  38. string line;
  39. while ((line = reader.ReadLine()) != null)
  40. {
  41. if (String.IsNullOrEmpty(line))
  42. continue;
  43. if(char.IsDigit(line[0]))
  44. {
  45. int count = 0;
  46. int spaceIndex = line.IndexOf(" ");
  47. if (int.TryParse(line.Substring(0,spaceIndex).Trim(), out value))
  48. count = value;
  49. Debug.Log($"Card Count: {count}");
  50. for (int i = 0; i < 4; i++)
  51. {
  52. Debug.Log($"Found Card Count: {line}");
  53. string cardID = GetCardID(line);
  54. Debug.Log($"Identified ID: {cardID}");
  55. CEntity_Base cEntity_Base = GetCardFromCardID(cardID);
  56. if (cEntity_Base != null)
  57. {
  58. Debug.Log($"SUCCESSFULLY ADDED: {count}: {cardID}");
  59. break;
  60. }
  61. else
  62. {
  63. line += "/" + reader.ReadLine();
  64. Debug.Log($"cardIDString:{cardID}, cardEntity = null");
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }