SettlementTestHelper.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using UnityEngine;
  2. /// <summary>
  3. /// Test helper to simulate entering different settlement types
  4. /// Use this to test town vs village generation
  5. /// </summary>
  6. public class SettlementTestHelper : MonoBehaviour
  7. {
  8. [Header("Test Controls")]
  9. public bool createContextOnStart = false; // DISABLED - Don't override real settlement context
  10. public SettlementType testSettlementType = SettlementType.Town;
  11. public string testSettlementName = "Test Town";
  12. public bool testHasHarbor = false;
  13. void Start()
  14. {
  15. // COMPLETELY DISABLED - This component should never interfere with real settlement system
  16. Debug.Log("SettlementTestHelper: DISABLED - No test context creation allowed");
  17. return;
  18. // if (createContextOnStart)
  19. // {
  20. // Debug.Log("SettlementTestHelper: Creating test context (should only happen during testing)");
  21. // CreateTestSettlementContext();
  22. // }
  23. // else
  24. // {
  25. // Debug.Log("SettlementTestHelper: Disabled - not creating test context");
  26. // }
  27. }
  28. [ContextMenu("Create Test Town Context")]
  29. public void CreateTestTownContext()
  30. {
  31. CreateSettlementContext("Test Town", SettlementType.Town, new Vector2Int(100, 100), true);
  32. }
  33. [ContextMenu("Create Test Village Context")]
  34. public void CreateTestVillageContext()
  35. {
  36. CreateSettlementContext("Test Village", SettlementType.Village, new Vector2Int(50, 50), false);
  37. }
  38. [ContextMenu("Create Custom Test Context")]
  39. public void CreateTestSettlementContext()
  40. {
  41. CreateSettlementContext(testSettlementName, testSettlementType, new Vector2Int(75, 75), testHasHarbor);
  42. }
  43. private void CreateSettlementContext(string name, SettlementType type, Vector2Int position, bool harbor)
  44. {
  45. // Find or create SettlementContext
  46. var existingContext = FindFirstObjectByType<SettlementContext>();
  47. SettlementContext context;
  48. if (existingContext != null)
  49. {
  50. context = existingContext;
  51. Debug.Log("Using existing SettlementContext");
  52. }
  53. else
  54. {
  55. var contextObject = new GameObject("SettlementContext");
  56. context = contextObject.AddComponent<SettlementContext>();
  57. Debug.Log("Created new SettlementContext");
  58. }
  59. // Set settlement data
  60. context.SetSettlement(name, type, position, harbor);
  61. Debug.Log($"✅ Settlement context configured: {name} ({type}) - Harbor: {harbor}");
  62. // Force regenerate shops to see immediate effect
  63. var shops = context.GenerateShops();
  64. Debug.Log($"Generated shops: {string.Join(", ", System.Array.ConvertAll(shops, s => s.buildingName))}");
  65. // Update any existing TownShopManager
  66. var shopManager = FindFirstObjectByType<TownShopManager>();
  67. if (shopManager != null)
  68. {
  69. Debug.Log("Forcing TownShopManager to reinitialize with new settlement data");
  70. // Force clear the shops and reinitialize everything properly
  71. shopManager.allShops = null;
  72. shopManager.ReinitializeShopsAndUI(); // Use the new method that handles UI properly
  73. }
  74. // Update TownManager if it exists
  75. var townManager = FindFirstObjectByType<TownManager>();
  76. if (townManager != null)
  77. {
  78. townManager.townName = name;
  79. townManager.hasHarbor = harbor;
  80. Debug.Log("Updated TownManager with settlement data");
  81. }
  82. }
  83. [ContextMenu("Clear Settlement Context")]
  84. public void ClearSettlementContext()
  85. {
  86. var context = FindFirstObjectByType<SettlementContext>();
  87. if (context != null)
  88. {
  89. context.ClearSettlementData();
  90. Debug.Log("Settlement context cleared");
  91. }
  92. else
  93. {
  94. Debug.Log("No settlement context found to clear");
  95. }
  96. }
  97. [ContextMenu("Print Current Context")]
  98. public void PrintCurrentContext()
  99. {
  100. if (SettlementContext.Instance != null)
  101. {
  102. var ctx = SettlementContext.Instance;
  103. Debug.Log($"Current Settlement Context:");
  104. Debug.Log($" Name: {ctx.settlementName}");
  105. Debug.Log($" Type: {ctx.settlementType}");
  106. Debug.Log($" Position: {ctx.mapPosition}");
  107. Debug.Log($" Harbor: {ctx.hasHarbor}");
  108. Debug.Log($" Generated: {ctx.isGenerated}");
  109. Debug.Log($" Shop Count: {(ctx.availableShops?.Length ?? 0)}");
  110. }
  111. else
  112. {
  113. Debug.Log("No SettlementContext instance found");
  114. }
  115. }
  116. }