Esempio n. 1
0
void UActorComponent::ConsolidatedPostEditChange(const FPropertyChangedEvent& PropertyChangedEvent)
{
	FComponentReregisterContext* ReregisterContext = nullptr;
	if(EditReregisterContexts.RemoveAndCopyValue(this, ReregisterContext))
	{
		delete ReregisterContext;

		AActor* MyOwner = GetOwner();
		if ( MyOwner && !MyOwner->IsTemplate() && PropertyChangedEvent.ChangeType != EPropertyChangeType::Interactive )
		{
			MyOwner->RerunConstructionScripts();
		}
	}
	else
	{
		// This means there are likely some stale elements left in there now, strip them out
		for (auto It(EditReregisterContexts.CreateIterator()); It; ++It)
		{
			if (!It.Key().IsValid())
			{
				It.RemoveCurrent();
			}
		}
	}

	// The component or its outer could be pending kill when calling PostEditChange when applying a transaction.
	// Don't do do a full recreate in this situation, and instead simply detach.
	if( IsPendingKill() )
	{
		// @todo UE4 james should this call UnregisterComponent instead to remove itself from the RegisteredComponents array on the owner?
		ExecuteUnregisterEvents();
		World = NULL;
	}
}
Esempio n. 2
0
FPlot ParsePlot(int32 nPlotID)
{
	FString sValue;

	FString sPlot = FString::FromInt(nPlotID);

	FString aFullPath = FPaths::GameDevelopersDir();
	aFullPath += "Source/JSON/PLO/";
	aFullPath += *sPlot;
	aFullPath += ".json";
	FString JsonStr;
	FFileHelper::LoadFileToString(JsonStr, *aFullPath);

	TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonStr);
	TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());

	FPlot plot;

	if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
	{
		plot.ResRefID = nPlotID;

		TMap<FString, TSharedPtr<FJsonValue>> JsonValuesMap = JsonObject->Values;
		TSharedPtr<FJsonValue> rootValues;
		JsonValuesMap.RemoveAndCopyValue("Resource", rootValues);
		TSharedPtr<FJsonObject> rootObject = rootValues->AsObject();

		TMap<FString, TSharedPtr<FJsonValue>> rootValuesMap = rootObject->Values;
		TSharedPtr<FJsonValue> agentValues;
		rootValuesMap.RemoveAndCopyValue("Agent", agentValues);
		TSharedPtr<FJsonObject> agentObject = agentValues->AsObject();

		TMap<FString, TSharedPtr<FJsonValue>> agentValuesMap = agentObject->Values;

		for (auto const& y : agentValuesMap)
		{
			if (y.Key == "ResRefName")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.ResRefName = sValue;
			}
			if (y.Key == "LocalCopy")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.LocalCopy = sValue == "False" ? false : true;
			}
			if (y.Key == "Name")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.Name = sValue;
			}
			if (y.Key == "NameStringID")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.NameStringID = FCString::Atoi(*sValue);
			}
			if (y.Key == "NameRequiresReTranslation")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.NameRequiresReTranslation = sValue == "False" ? false : true;
			}
			if (y.Key == "GUID")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.GUID = sValue;
			}
			if (y.Key == "ScriptURI")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.ScriptURI = FCString::Atoi(*sValue);
			}
			if (y.Key == "Priority")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.Priority = FCString::Atoi(*sValue);
			}
			if (y.Key == "JournalImage")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.JournalImage = sValue;
			}
			if (y.Key == "ParentPlotURI")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.ParentPlotURI = FCString::Atoi(*sValue);
			}
			if (y.Key == "EntryType")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.EntryType = FCString::Atoi(*sValue);
			}
			if (y.Key == "AllowPausing")
			{
				y.Value.Get()->TryGetString(sValue);
				plot.AllowPausing = sValue == "False" ? false : true;
			}
		}

		TSharedPtr<FJsonValue> StatusListValues;
		agentValuesMap.RemoveAndCopyValue("StatusList", StatusListValues);
		TSharedPtr<FJsonObject> StatusListObject = StatusListValues->AsObject();

		TArray<TSharedPtr<FJsonValue>> StatusArray = StatusListObject->GetArrayField("Agent");

		FPlotNode statusNode;

		if (StatusArray.Num() > 0)
		{
			int32 counter = 0;
			do {
				TSharedPtr<FJsonValue> StatusValue = StatusArray[counter];
				TSharedPtr<FJsonObject> StatusObject = StatusValue->AsObject();

				TMap<FString, TSharedPtr<FJsonValue>> StatusValuesMap = StatusObject->Values;
				for (auto const& x : StatusValuesMap)
				{
					if (x.Key == "Flag")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.Flag = FCString::Atoi64(*sValue);
					}
					if (x.Key == "Name")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.Name = sValue;
					}
					if (x.Key == "Final")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.Final = sValue == "False" ? false : true;
					}
					if (x.Key == "Repeatable")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.Repeatable = sValue == "False" ? false : true;
					}
					if (x.Key == "JournalText")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.JournalText = sValue;
					}
					if (x.Key == "JournalTextStringID")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.JournalTextStringID = FCString::Atoi(*sValue);
					}
					if (x.Key == "JournalTextRequiresReTranslation")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.JournalTextRequiresReTranslation = sValue == "False" ? false : true;
					}
					if (x.Key == "RewardID")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.RewardID = FCString::Atoi(*sValue);
					}
					if (x.Key == "Comment")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.Comment = sValue;
					}
					if (x.Key == "DefaultValue")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.DefaultValue = FCString::Atoi(*sValue);
					}
					if (x.Key == "AreaLocationTag")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.AreaLocationTag = sValue;
					}
					if (x.Key == "OfferID")
					{
						x.Value.Get()->TryGetString(sValue);
						statusNode.OfferID = FCString::Atoi(*sValue);
					}
				}

				//update Flag with pattern ResRefID+"000"+Flag
				statusNode.Flag = PlotFlagConversion(plot.ResRefID, statusNode.Flag);

				FPlotElement ePlot;
				ePlot.pNode = statusNode;
				ePlot.pValue = 0; //false by default
				plot.StatusList.Add(ePlot);

				counter++;
			} while (counter < StatusArray.Num());
		}
#ifdef DEBUG
		LogWarning("Plot " + IntToString(nPlotID) + " parsed!!");
#endif // DEBUG

		//TODO PlotAssistInfoList
		GetParty()->Plots.Add(plot);
	}
	else {
#ifdef DEBUG
		LogError("Not Deserialized" + aFullPath);
#endif
	}
	return plot;
}
Esempio n. 3
0
void UActorComponent::PostEditUndo()
{
	// Objects marked pending kill don't call PostEditChange() from UObject::PostEditUndo(),
	// so they can leave an EditReregisterContexts entry around if they are deleted by an undo action.
	if( IsPendingKill() )
	{
		// The reregister context won't bother attaching components that are 'pending kill'. 
		FComponentReregisterContext* ReregisterContext = nullptr;
		if (EditReregisterContexts.RemoveAndCopyValue(this, ReregisterContext))
		{
			delete ReregisterContext;
		}
		else
		{
			// This means there are likely some stale elements left in there now, strip them out
			for (auto It(EditReregisterContexts.CreateIterator()); It; ++It)
			{
				if (!It.Key().IsValid())
				{
					It.RemoveCurrent();
				}
			}
		}
	}
	else
	{
		bIsBeingDestroyed = false;

		Owner = GetTypedOuter<AActor>();
		bCanUseCachedOwner = true;

		// Let the component be properly registered, after it was restored.
		if (Owner)
		{
			Owner->AddOwnedComponent(this);
		}

		TArray<UObject*> Children;
		GetObjectsWithOuter(this, Children);

		for (UObject* Child : Children)
		{
			if (UActorComponent* ChildComponent = Cast<UActorComponent>(Child))
			{
				if (ChildComponent->Owner)
				{
					ChildComponent->Owner->RemoveOwnedComponent(ChildComponent);
				}
				ChildComponent->Owner = Owner;
				if (Owner)
				{
					Owner->AddOwnedComponent(ChildComponent);
				}
			}
		}

		if (GetWorld())
		{
			GetWorld()->UpdateActorComponentEndOfFrameUpdateState(this);
		}
	}
	Super::PostEditUndo();
}