Skip to content

Commit

Permalink
Create jump points from json
Browse files Browse the repository at this point in the history
  • Loading branch information
behindcurtain3 committed Apr 15, 2024
1 parent b630ebe commit d115ad2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Pulsar4X/GameEngine/Data/basemod/defaultStart.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"sol/",
"alphaCentauri/"
],
"jumpPoints": [
{ "from": "sol", "to": "alpha-centauri" }
],
"factions": [
"defaultStart/uef.json",
"defaultStart/opposition.json"
Expand Down
19 changes: 19 additions & 0 deletions Pulsar4X/GameEngine/Engine/Factories/DefaultStartFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ public static (Entity?, string) LoadFromJson(Game game, string filePath)
startingSystem = system;
}

var jumpPoints = (JArray?)rootJson["jumpPoints"];
if(jumpPoints != null)
{
foreach(var pair in jumpPoints)
{
var from = (string?)pair["from"];
var to = (string?)pair["to"];

var fromSystem = game.Systems.First(s => s.Guid.Equals(from));
var fromJP = JPFactory.CreateJumpPoint(starSystemFactory, fromSystem);

var toSystem = game.Systems.First(s => s.Guid.Equals(to));
var toJP = JPFactory.CreateJumpPoint(starSystemFactory, toSystem);

fromJP.GetDataBlob<JumpPointDB>().DestinationId = toJP.Id;
toJP.GetDataBlob<JumpPointDB>().DestinationId = fromJP.Id;
}
}

var factionsToLoad = (JArray?)rootJson["factions"];
foreach(var factionToLoad in factionsToLoad)
{
Expand Down

0 comments on commit d115ad2

Please sign in to comment.