Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions TombEditor/ObjectClipboardData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,7 @@ public ObjectInstance MergeGetSingleObject(Editor editor)
obj.CopyDependentLevelSettings(
new Room.CopyDependentLevelSettingsArgs(null, newLevelSettings, loadedObjects.Settings, true));

// A little workaround to detect collisions

if (obj is IHasScriptID)
{
try
{
editor.SelectedRoom.AddObject(editor.Level, obj);
editor.SelectedRoom.RemoveObject(editor.Level, obj);
}
catch (ScriptIdCollisionException)
{
((IHasScriptID)obj).ScriptId = null;
}
}

if (obj is IHasLuaName)
{
editor.SelectedRoom.AddObject(editor.Level, obj);
var luaObj = obj as IHasLuaName;

if (!luaObj.CanSetLuaName(luaObj.LuaName))
luaObj.LuaName = string.Empty;

editor.SelectedRoom.RemoveObject(editor.Level, obj);
}
ResolveIdentifierCollisions(editor, obj);

if (obj is VolumeInstance)
{
Expand Down Expand Up @@ -113,6 +89,30 @@ public ObjectInstance MergeGetSingleObject(Editor editor)
}
}

private static void ResolveIdentifierCollisions(Editor editor, ObjectInstance obj)
{
ResetCollidingScriptId(editor, obj);
ResetCollidingLuaName(editor, obj);
}

private static void ResetCollidingScriptId(Editor editor, ObjectInstance obj)
{
if (obj is not IHasScriptID scriptObject || !scriptObject.ScriptId.HasValue)
return;

if (editor.Level.GlobalScriptingIdsTable[(int)scriptObject.ScriptId.Value] != null)
scriptObject.ScriptId = null;
}

private static void ResetCollidingLuaName(Editor editor, ObjectInstance obj)
{
if (obj is not IHasLuaName luaObject || string.IsNullOrEmpty(luaObject.LuaName))
return;

if (editor.Level.GetAllObjects().OfType<IHasLuaName>().Any(existingObject => existingObject.LuaName == luaObject.LuaName))
luaObject.LuaName = string.Empty;
}

private static void NormalizePastedFlybyCameras(Editor editor, IReadOnlyCollection<ObjectInstance> unpackedObjects)
{
var pastedFlybys = unpackedObjects.OfType<FlybyCameraInstance>().ToList();
Expand Down Expand Up @@ -159,4 +159,4 @@ private static void NormalizePastedFlybyCameras(Editor editor, IReadOnlyCollecti
}
}
}
}
}