-
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.
Showing
3 changed files
with
73 additions
and
18 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Pulsar4X/GameEngine/Data/basemod/shipDesigns/obennDropship.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,20 @@ | ||
{ | ||
"name": "Ob'enn Dropship", | ||
"armor": { | ||
"id": "plastic-armor", | ||
"thickness": 3 | ||
}, | ||
"components": [ | ||
{ "id": "default-design-passive-sensor-s50", "amount": 1 }, | ||
{ "id": "default-design-laser-weapon", "amount": 2 }, | ||
{ "id": "default-design-beam-fire-control", "amount": 1 }, | ||
{ "id": "default-design-cargo-hold-1t", "amount": 1 }, | ||
{ "id": "default-design-geo-surveyor", "amount": 1 }, | ||
{ "id": "default-design-gravitational-surveyor", "amount": 1 }, | ||
{ "id": "default-design-fuel-tank-1000", "amount": 2 }, | ||
{ "id": "default-design-alcubierre-500", "amount": 4 }, | ||
{ "id": "default-design-battery-2t", "amount": 3 }, | ||
{ "id": "default-design-reactor-15k", "amount": 1 }, | ||
{ "id": "default-design-merlin", "amount": 3 } | ||
] | ||
} |
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
49 changes: 49 additions & 0 deletions
49
Pulsar4X/GameEngine/Engine/Factories/ShipDesignFromJson.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.Collections.Generic; | ||
using System.IO; | ||
using Newtonsoft.Json.Linq; | ||
using Pulsar4X.Blueprints; | ||
using Pulsar4X.Components; | ||
using Pulsar4X.Datablobs; | ||
using Pulsar4X.Engine.Designs; | ||
|
||
namespace Pulsar4X.Engine.Factories; | ||
|
||
public static class ShipDesignFromJson | ||
{ | ||
public static ShipDesign Create(Entity faction, FactionDataStore factionDataStore, string filePath) | ||
{ | ||
string fileContents = File.ReadAllText(filePath); | ||
var rootJson = JObject.Parse(fileContents); | ||
|
||
var factionInfoDB = faction.GetDataBlob<FactionInfoDB>(); | ||
var shipComponents = new List<(ComponentDesign, int)>(); | ||
|
||
var designName = rootJson["name"].ToString(); | ||
|
||
var components = (JArray?)rootJson["components"]; | ||
if(components != null) | ||
{ | ||
foreach(var component in components) | ||
{ | ||
var id = component["id"].ToString(); | ||
var amount = (int?)component["amount"] ?? 0; | ||
|
||
shipComponents.Add(( | ||
factionInfoDB.InternalComponentDesigns[id], | ||
amount | ||
)); | ||
} | ||
} | ||
|
||
var armorId = rootJson["armor"]["id"].ToString(); | ||
var armorThickness = (int?)rootJson["armor"]["thickness"] ?? 1; | ||
|
||
var armor = factionDataStore.Armor[armorId]; | ||
var design = new ShipDesign(factionInfoDB, designName, shipComponents, (armor, armorThickness)) | ||
{ | ||
DamageProfileDB = new EntityDamageProfileDB(shipComponents, (armor, armorThickness)) | ||
}; | ||
|
||
return design; | ||
} | ||
} |