Example #1
0
TSharedRef<FJsonObject> UFlareSaveWriter::SaveSpacecraft(FFlareSpacecraftSave* Data)
{
	TSharedRef<FJsonObject> JsonObject = MakeShareable(new FJsonObject());

	JsonObject->SetStringField("Immatriculation", Data->Immatriculation.ToString());
	JsonObject->SetStringField("NickName", Data->NickName.ToString());
	JsonObject->SetStringField("Identifier", Data->Identifier.ToString());
	JsonObject->SetStringField("CompanyIdentifier", Data->CompanyIdentifier.ToString());
	JsonObject->SetStringField("Location", FormatVector(Data->Location));
	JsonObject->SetStringField("Rotation", FormatRotator(Data->Rotation));
	JsonObject->SetStringField("SpawnMode", FormatEnum<EFlareSpawnMode::Type>("EFlareSpawnMode",Data->SpawnMode));
	JsonObject->SetStringField("LinearVelocity", FormatVector(Data->LinearVelocity));
	JsonObject->SetStringField("AngularVelocity", FormatVector(Data->AngularVelocity));
	JsonObject->SetStringField("DockedTo", Data->DockedTo.ToString());
	JsonObject->SetStringField("DockedAt", FormatInt32(Data->DockedAt));
	SaveFloat(JsonObject,"Heat", Data->Heat);
	SaveFloat(JsonObject,"PowerOutageDelay", Data->PowerOutageDelay);
	SaveFloat(JsonObject,"PowerOutageAcculumator", Data->PowerOutageAcculumator);
	JsonObject->SetStringField("DynamicComponentStateIdentifier", Data->DynamicComponentStateIdentifier.ToString());
	SaveFloat(JsonObject,"DynamicComponentStateProgress", Data->DynamicComponentStateProgress);
	JsonObject->SetStringField("Level", FormatInt32(Data->Level));
	JsonObject->SetBoolField("IsTrading", Data->IsTrading);
	JsonObject->SetObjectField("Pilot", SavePilot(&Data->Pilot));
	JsonObject->SetObjectField("Asteroid", SaveAsteroid(&Data->AsteroidData));

	TArray< TSharedPtr<FJsonValue> > Components;
	for(int i = 0; i < Data->Components.Num(); i++)
	{
		Components.Add(MakeShareable(new FJsonValueObject(SaveSpacecraftComponent(&Data->Components[i]))));
	}
	JsonObject->SetArrayField("Components", Components);

	TArray< TSharedPtr<FJsonValue> > Cargo;
	for(int i = 0; i < Data->Cargo.Num(); i++)
	{
		Cargo.Add(MakeShareable(new FJsonValueObject(SaveCargo(&Data->Cargo[i]))));
	}
	JsonObject->SetArrayField("Cargo", Cargo);

	TArray< TSharedPtr<FJsonValue> > FactoryStates;
	for(int i = 0; i < Data->FactoryStates.Num(); i++)
	{
		FactoryStates.Add(MakeShareable(new FJsonValueObject(SaveFactory(&Data->FactoryStates[i]))));
	}
	JsonObject->SetArrayField("FactoryStates", FactoryStates);


	TArray< TSharedPtr<FJsonValue> > SalesExcludedResources;
	for(int i = 0; i < Data->SalesExcludedResources.Num(); i++)
	{
		SalesExcludedResources.Add(MakeShareable(new FJsonValueString(Data->SalesExcludedResources[i].ToString())));
	}
	JsonObject->SetArrayField("SalesExcludedResources", SalesExcludedResources);

	return JsonObject;
}
TSharedRef<FJsonObject> UFlareSaveWriter::SaveSector(FFlareSectorSave* Data)
{
	TSharedRef<FJsonObject> JsonObject = MakeShareable(new FJsonObject());

	JsonObject->SetStringField("GivenName", Data->GivenName.ToString());
	JsonObject->SetStringField("Identifier", Data->Identifier.ToString());
	JsonObject->SetStringField("LocalTime", FormatInt64(Data->LocalTime));
	JsonObject->SetObjectField("People", SavePeople(&Data->PeopleData));


	TArray< TSharedPtr<FJsonValue> > Bombs;
	for(int i = 0; i < Data->BombData.Num(); i++)
	{
		Bombs.Add(MakeShareable(new FJsonValueObject(SaveBomb(&Data->BombData[i]))));
	}
	JsonObject->SetArrayField("Bombs", Bombs);


	TArray< TSharedPtr<FJsonValue> > Asteroids;
	for(int i = 0; i < Data->AsteroidData.Num(); i++)
	{
		Asteroids.Add(MakeShareable(new FJsonValueObject(SaveAsteroid(&Data->AsteroidData[i]))));
	}
	JsonObject->SetArrayField("Asteroids", Asteroids);

	TArray< TSharedPtr<FJsonValue> > FleetIdentifiers;
	for(int i = 0; i < Data->FleetIdentifiers.Num(); i++)
	{
		FleetIdentifiers.Add(MakeShareable(new FJsonValueString(Data->FleetIdentifiers[i].ToString())));
	}
	JsonObject->SetArrayField("FleetIdentifiers", FleetIdentifiers);

	TArray< TSharedPtr<FJsonValue> > SpacecraftIdentifiers;
	for(int i = 0; i < Data->SpacecraftIdentifiers.Num(); i++)
	{
		SpacecraftIdentifiers.Add(MakeShareable(new FJsonValueString(Data->SpacecraftIdentifiers[i].ToString())));
	}
	JsonObject->SetArrayField("SpacecraftIdentifiers", SpacecraftIdentifiers);


	TArray< TSharedPtr<FJsonValue> > ResourcePrices;
	for(int i = 0; i < Data->ResourcePrices.Num(); i++)
	{
		ResourcePrices.Add(MakeShareable(new FJsonValueObject(SaveResourcePrice(&Data->ResourcePrices[i]))));
	}
	JsonObject->SetArrayField("ResourcePrices", ResourcePrices);

	JsonObject->SetBoolField("IsTravelSector", Data->IsTravelSector);

	return JsonObject;
}