-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add json loader for Component Designs
Migrate the conventional rocket engine designs to use the new loader
- Loading branch information
1 parent
1cb4f51
commit 1cba9dd
Showing
6 changed files
with
84 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "F1", | ||
"templateId": "conventional-engine", | ||
"attributes": [ | ||
{ "key": "Size", "value": 50 } | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
Pulsar4X/GameEngine/Data/basemod/componentDesigns/merlin.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "Merlin", | ||
"templateId": "conventional-engine", | ||
"attributes": [ | ||
{ "key": "Size", "value": 30 } | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
Pulsar4X/GameEngine/Data/basemod/componentDesigns/raptor.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "Raptor-Vac", | ||
"templateId": "conventional-engine", | ||
"attributes": [ | ||
{ "key": "Size", "value": 15 }, | ||
{ "key": "Fuel Type", "value": "methalox" } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "RS-25", | ||
"templateId": "conventional-engine", | ||
"attributes": [ | ||
{ "key": "Size", "value": 100 }, | ||
{ "key": "Fuel Type", "value": "hydrolox" } | ||
] | ||
} |
49 changes: 49 additions & 0 deletions
49
Pulsar4X/GameEngine/Engine/Factories/ComponentDesignFromJson.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.IO; | ||
using Newtonsoft.Json.Linq; | ||
using Pulsar4X.Blueprints; | ||
using Pulsar4X.Components; | ||
using Pulsar4X.Datablobs; | ||
|
||
namespace Pulsar4X.Engine.Factories; | ||
|
||
public static class ComponentDesignFromJson | ||
{ | ||
public static ComponentDesign Create(Game game, Entity faction, FactionDataStore factionDataStore, string filePath) | ||
{ | ||
string fileContents = File.ReadAllText(filePath); | ||
var rootJson = JObject.Parse(fileContents); | ||
|
||
var templateName = rootJson["templateId"].ToString(); | ||
var designName = rootJson["name"].ToString(); | ||
|
||
ComponentDesign design; | ||
var blueprint = factionDataStore.ComponentTemplates[templateName]; | ||
var designer = new ComponentDesigner(blueprint, factionDataStore, faction.GetDataBlob<FactionTechDB>()){ | ||
Name = designName | ||
}; | ||
|
||
var attributes = (JArray?)rootJson["attributes"]; | ||
foreach(var attribute in attributes) | ||
{ | ||
var key = attribute["key"].ToString(); | ||
var valueType = attribute["value"]; | ||
if(valueType.Type == JTokenType.Integer) | ||
{ | ||
designer.ComponentDesignAttributes[key].SetValueFromInput((int?)attribute["value"] ?? 0); | ||
} | ||
else if(valueType.Type == JTokenType.Float) | ||
{ | ||
designer.ComponentDesignAttributes[key].SetValueFromInput((double?)attribute["value"] ?? 0.0); | ||
} | ||
else | ||
{ | ||
designer.ComponentDesignAttributes[key].SetValueFromString(attribute["value"].ToString()); | ||
} | ||
} | ||
|
||
design = designer.CreateDesign(faction); | ||
factionDataStore.IncrementTechLevel(design.TechID); | ||
|
||
return design; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters