Skip to content

Commit

Permalink
Update the energy gen and sensors when a game is created
Browse files Browse the repository at this point in the history
  • Loading branch information
behindcurtain3 committed Jan 1, 2025
1 parent d6ea9fc commit 34853e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Pulsar4X/GameEngine/Engine/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Pulsar4X.Events;
using Pulsar4X.Factions;
using Pulsar4X.Galaxy;
using Pulsar4X.Energy;
using Pulsar4X.Sensors;
[assembly: InternalsVisibleTo("Pulsar4X.Tests")]

namespace Pulsar4X.Engine
Expand Down Expand Up @@ -201,6 +203,25 @@ public static Game Load(string json)

return loadedGame;
}

public void PostNewGameInitialization()
{
// There are few DB's that need to run the processor when the game begins
foreach(var system in Systems)
{
var entitiesWithEnergyGen = system.GetAllEntitiesWithDataBlob<EnergyGenAbilityDB>();
foreach (var entity in entitiesWithEnergyGen)
{
ProcessorManager.GetInstanceProcessor(nameof(EnergyGenProcessor)).ProcessEntity(entity, TimePulse.GameGlobalDateTime);
}

var entitiesWithSensors = system.GetAllEntitiesWithDataBlob<SensorAbilityDB>();
foreach (var entity in entitiesWithSensors)
{
ProcessorManager.GetInstanceProcessor(nameof(SensorScan)).ProcessEntity(entity, TimePulse.GameGlobalDateTime);
}
}
}
}

// public class GameConverter : JsonConverter
Expand Down
4 changes: 4 additions & 0 deletions Pulsar4X/Pulsar4X.Client/Interface/Menus/NewGameMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Pulsar4X.Client.Interface.Widgets;
using Pulsar4X.Client.State;
using Pulsar4X.Colonies;
using Pulsar4X.Energy;
using Pulsar4X.Engine;
using Pulsar4X.Extensions;
using Pulsar4X.Factions;
Expand Down Expand Up @@ -433,6 +434,9 @@ void CreateNewGame()
// TODO: need to find a way to handle this via the mods instead of loading it here
//var (newGameFaction, systemId) = Pulsar4X.Engine.DefaultStartFactory.LoadFromJson(game, "Data/basemod/defaultStart.json");

// Call the game post new game initialization
game.PostNewGameInitialization();

_uiState.Game = game;
_uiState.SetFaction(playerFaction, true);
_uiState.SetActiveSystem(startingSystem.ManagerID);
Expand Down

0 comments on commit 34853e0

Please sign in to comment.