A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.7KB

  1. using System;
  2. using System.Collections.Generic;
  3. using HarmonyLib;
  4. using RobocraftX;
  5. using RobocraftX.Common;
  6. using RobocraftX.Schedulers;
  7. using RobocraftX.SimulationModeState;
  8. using Svelto.ECS;
  9. using Svelto.Tasks;
  10. using Svelto.Tasks.Lean;
  11. using GamecraftModdingAPI.Engines;
  12. using GamecraftModdingAPI.Utility;
  13. namespace GamecraftModdingAPI.App
  14. {
  15. public class GameGameEngine : IApiEngine
  16. {
  17. public event EventHandler<GameEventArgs> EnterGame;
  18. public event EventHandler<GameEventArgs> ExitGame;
  19. public string Name => "GamecraftModdingAPIGameInfoMenuEngine";
  20. public bool isRemovable => false;
  21. public EntitiesDB entitiesDB { set; private get; }
  22. public void Dispose()
  23. {
  24. ExceptionUtil.InvokeEvent(ExitGame, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder });
  25. IsInGame = false;
  26. }
  27. public void Ready()
  28. {
  29. ExceptionUtil.InvokeEvent(EnterGame, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder });
  30. IsInGame = true;
  31. }
  32. // game functionality
  33. public bool IsInGame
  34. {
  35. get;
  36. private set;
  37. } = false;
  38. public void ExitCurrentGame(bool async = false)
  39. {
  40. if (async)
  41. {
  42. ExitCurrentGameAsync().RunOn(Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING);
  43. }
  44. else
  45. {
  46. entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID).WantsToQuit = true;
  47. entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
  48. }
  49. }
  50. public IEnumerator<TaskContract> ExitCurrentGameAsync()
  51. {
  52. /*
  53. while (Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING.isStopping) { yield return Yield.It; }
  54. AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToMenu").Invoke(FullGameFields.Instance, new object[0]);*/
  55. yield return Yield.It;
  56. entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID).WantsToQuit = true;
  57. entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
  58. }
  59. public void SaveCurrentGame()
  60. {
  61. ref GameSceneEntityStruct gses = ref entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
  62. gses.LoadAfterSaving = false;
  63. gses.SaveNow = true;
  64. entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
  65. }
  66. public bool IsTimeRunningMode()
  67. {
  68. return TimeRunningModeUtil.IsTimeRunningMode(entitiesDB);
  69. }
  70. public bool IsTimeStoppedMode()
  71. {
  72. return TimeRunningModeUtil.IsTimeStoppedMode(entitiesDB);
  73. }
  74. public void ToggleTimeMode()
  75. {
  76. TimeRunningModeUtil.ToggleTimeRunningState(entitiesDB);
  77. }
  78. }
  79. }