Module.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Input;
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. namespace OpenVIII.Fields
  7. {
  8. //issues found.
  9. //558 //color looks off on glow. with purple around it.
  10. //267 //text showing with white background.
  11. //132 missing lava.
  12. //pupu states that there is are 2 widths of the texture for Type1 and Type2
  13. //we are only using 1 so might be reading the wrong pixels somewhere.
  14. public static class Module
  15. {
  16. #region Fields
  17. private static Archive _archive;
  18. #endregion Fields
  19. #region Properties
  20. public static FF8String AreaName => _archive?.GetAreaNames()?.FirstOrDefault();
  21. public static Background Background => _archive?.Background;
  22. /*
  23. public static Cameras Cameras => _archive?.Cameras;
  24. */
  25. /*
  26. private static EventEngine EventEngine => _archive?.EventEngine;
  27. */
  28. public static FieldMenu FieldMenu { get; set; }
  29. /*
  30. private static INF INF => _archive?.INF;
  31. */
  32. /*
  33. public static ushort GetForcedBattleEncounter
  34. {
  35. get
  36. {
  37. HashSet<ushort> t = _archive?.GetForcedBattleEncounters();
  38. if (t == null || t.Count == 0)
  39. return ushort.MaxValue;
  40. return t.First();
  41. }
  42. }
  43. */
  44. public static FieldModes Mod
  45. {
  46. get => _archive.Mod; private set => _archive.Mod = value;
  47. }
  48. /*
  49. public static MrtRat MrtRat => _archive.MrtRat;
  50. */
  51. /*
  52. private static MSK MSK => _archive.MSK;
  53. */
  54. public static PMP PMP => _archive.PMP;
  55. /*
  56. private static IServices Services => _archive.Services;
  57. */
  58. /*
  59. private static SFX SFX => _archive.SFX;
  60. */
  61. /*
  62. private static TDW TDW => _archive.TDW;
  63. */
  64. public static Toggles Toggles { get; set; } = Toggles.Quad | Toggles.Menu; //| Toggles.DumpingData;
  65. public static WalkMesh WalkMesh => _archive.WalkMesh;
  66. #endregion Properties
  67. #region Methods
  68. public static void Draw()
  69. {
  70. Memory.SpriteBatch.GraphicsDevice.Clear(Color.Black);
  71. switch (Mod)
  72. {
  73. case FieldModes.Init:
  74. break; //null
  75. case FieldModes.DebugRender:
  76. case FieldModes.NoJSM:
  77. _archive.Draw();
  78. if (Toggles.HasFlag(Toggles.Menu))
  79. FieldMenu.Draw();
  80. break;
  81. case FieldModes.Disabled:
  82. FieldMenu.Draw();
  83. break;
  84. default:
  85. throw new ArgumentOutOfRangeException();
  86. }
  87. }
  88. public static string GetFieldName()
  89. {
  90. var fieldName = Memory.FieldHolder.Fields[Memory.FieldHolder.FieldID].ToLower();
  91. if (string.IsNullOrWhiteSpace(fieldName))
  92. fieldName = $"unk{Memory.FieldHolder.FieldID}";
  93. return fieldName;
  94. }
  95. public static string GetFolder(string fieldName = null, string subfolder = "")
  96. {
  97. if (string.IsNullOrWhiteSpace(fieldName))
  98. fieldName = GetFieldName();
  99. var folder = Path.Combine(Path.GetTempPath(), "Fields", fieldName.Substring(0, 2), fieldName, subfolder);
  100. Directory.CreateDirectory(folder);
  101. return folder;
  102. }
  103. public static void ResetField()
  104. {
  105. Memory.SuppressDraw = true;
  106. if (_archive != null)
  107. Mod = FieldModes.Init;
  108. }
  109. public static void Update()
  110. {
  111. if (Input2.DelayedButton(Keys.D0))
  112. Toggles = Toggles.Flip(Toggles.Menu);
  113. else
  114. {
  115. if (_archive == null)
  116. _archive = new Archive();
  117. switch (Mod)
  118. {
  119. case FieldModes.Init:
  120. var init = _archive.Init();
  121. if (init && Mod == FieldModes.Init)
  122. Mod++;
  123. if (FieldMenu == null)
  124. FieldMenu = FieldMenu.Create();
  125. FieldMenu.Refresh();
  126. break;
  127. case FieldModes.DebugRender:
  128. _archive.Update();
  129. if (Toggles.HasFlag(Toggles.Menu))
  130. FieldMenu.Update();
  131. break; //await events here
  132. case FieldModes.NoJSM://no scripts but has background.
  133. _archive.Update();
  134. if (Toggles.HasFlag(Toggles.Menu))
  135. FieldMenu.Update();
  136. break; //await events here
  137. case FieldModes.Disabled:
  138. FieldMenu.Update();
  139. break;
  140. default:
  141. throw new ArgumentOutOfRangeException();
  142. }
  143. }
  144. }
  145. #endregion Methods
  146. }
  147. }