void FSpawnVehiclePathConfig::DeserializeFromJson()

in Ambit/Source/Ambit/Actors/SpawnerConfigs/SpawnVehiclePathConfig.cpp [119:221]


void FSpawnVehiclePathConfig::DeserializeFromJson(TSharedPtr<FJsonObject> JsonObject)
{
    // Configure location of spawner
    const TArray<TSharedPtr<FJsonValue>>& LocationJson = JsonObject->GetArrayField(JsonKeys::KSpawnerLocationKey);
    SpawnerLocation = FJsonHelpers::DeserializeToVector3(LocationJson);

    // Configure rotation of spawner
    const TArray<TSharedPtr<FJsonValue>>& RotationJson = JsonObject->GetArrayField(JsonKeys::KSpawnerRotationKey);
    SpawnerRotation = FJsonHelpers::DeserializeToRotation(RotationJson);

    FString VehicleToSpawnPath;
    if (JsonObject->TryGetStringField(JsonVehiclePathKeys::KVehicleToSpawnKey, VehicleToSpawnPath))
    {
        const FSoftClassPath ClassPath(VehicleToSpawnPath);
        const auto& Actor = ClassPath.TryLoadClass<AWheeledVehicle>();
        if (Actor == nullptr)
        {
            UE_LOG(LogAmbit, Error, TEXT("%s is not a valid path."), *VehicleToSpawnPath)
        }
        else
        {
            VehicleToSpawn = Actor;
        }
    }

    SpeedLimit = JsonObject->GetNumberField(JsonVehiclePathKeys::KSpeedLimit);

    DistanceBetweenWaypoints = JsonObject->GetNumberField(JsonVehiclePathKeys::KDistanceBetweenWaypoints);

    ShowDebugWaypoint = JsonObject->GetBoolField(JsonVehiclePathKeys::KShowDebugWaypoints);

    CloseLoop = JsonObject->GetBoolField(JsonKeys::KSplineCloseLoopKey);

    //Configure spline points
    SplinePoints.Empty();
    FVector SplinePointLocation(0, 0, 0);
    FVector ArriveTangent(0, 0, 0);
    FVector LeaveTangent(0, 0, 0);
    FRotator SplinePointRotation(0, 0, 0);
    FVector SplinePointScale(0, 0, 0);
    TEnumAsByte<ESplinePointType::Type> SplinePointType = ESplinePointType::Curve;
    const TArray<TSharedPtr<FJsonValue>>* SplinePointsJson;
    if (JsonObject->TryGetArrayField(JsonKeys::KSplinePointsKey, SplinePointsJson))
    {
        for (const TSharedPtr<FJsonValue>& JsonValue : *SplinePointsJson)
        {
            const TSharedPtr<FJsonObject>& PointObject = JsonValue->AsObject();

            const float SplinePointInputKey = PointObject->GetNumberField(JsonKeys::KSplinePointInputKey);

            const TArray<TSharedPtr<FJsonValue>>& SplinePointLocationJson = PointObject->GetArrayField(
                JsonKeys::KSplinePointRelativeLocationKey);
            SplinePointLocation = FJsonHelpers::DeserializeToVector3(SplinePointLocationJson);

            const TArray<TSharedPtr<FJsonValue>>& ArriveTangentJson = PointObject->GetArrayField(
                JsonKeys::KSplineArriveKey);
            ArriveTangent = FJsonHelpers::DeserializeToVector3(ArriveTangentJson);

            const TArray<TSharedPtr<FJsonValue>>& LeaveTangentJson = PointObject->GetArrayField(
                JsonKeys::KSplineLeaveKey);
            LeaveTangent = FJsonHelpers::DeserializeToVector3(LeaveTangentJson);

            const TArray<TSharedPtr<FJsonValue>>& SplinePointRotationJson = PointObject->GetArrayField(
                JsonKeys::KSplinePointRelativeRotationKey);
            SplinePointRotation = FJsonHelpers::DeserializeToRotation(SplinePointRotationJson);

            const TArray<TSharedPtr<FJsonValue>>& SplinePointScaleJson = PointObject->GetArrayField(
                JsonKeys::KSplinePointScaleKey);
            SplinePointScale = FJsonHelpers::DeserializeToVector3(SplinePointScaleJson);

            const FString& SplinePointTypeString = PointObject->GetStringField(JsonKeys::KSplinePointTypeKey);

            if (SplinePointTypeString.Equals(JsonKeys::KSplineTypeLinear))
            {
                SplinePointType = ESplinePointType::Linear;
            }
            else if (SplinePointTypeString.Equals(JsonKeys::KSplineTypeCurve))
            {
                SplinePointType = ESplinePointType::Curve;
            }
            else if (SplinePointTypeString.Equals(JsonKeys::KSplineTypeConstant))
            {
                SplinePointType = ESplinePointType::Constant;
            }
            else if (SplinePointTypeString.Equals(JsonKeys::KSplineTypeCurveClamped))
            {
                SplinePointType = ESplinePointType::CurveClamped;
            }
            else if (SplinePointTypeString.Equals(JsonKeys::KSplineTypeCustom))
            {
                SplinePointType = ESplinePointType::CurveCustomTangent;
            }

            const FSplinePoint Point(SplinePointInputKey, SplinePointLocation, ArriveTangent, LeaveTangent,
                                     SplinePointRotation, SplinePointScale, SplinePointType);
            SplinePoints.Add(Point);
        }
    }
    else
    {
        UE_LOG(LogAmbit, Warning, TEXT("No spline point data found in JSON."));
    }
}