From c1e644e57551f76c6b0639d30108a5d300227915 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 08:12:12 +0000 Subject: [PATCH 1/2] Initial plan From 3454d849777e1d4dbd6813d6f2789497289cce1e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 08:19:41 +0000 Subject: [PATCH 2/2] Avoid attaching pasted objects during collision checks Agent-Logs-Url: https://github.com/TombEngine/Tomb-Editor/sessions/95d6c9ac-8ca4-475a-97ad-50ef9cc4f33f Co-authored-by: Nickelony <20436882+Nickelony@users.noreply.github.com> --- TombEditor/ObjectClipboardData.cs | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/TombEditor/ObjectClipboardData.cs b/TombEditor/ObjectClipboardData.cs index a8790518a..6b7c823c3 100644 --- a/TombEditor/ObjectClipboardData.cs +++ b/TombEditor/ObjectClipboardData.cs @@ -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) { @@ -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().Any(existingObject => existingObject.LuaName == luaObject.LuaName)) + luaObject.LuaName = string.Empty; + } + private static void NormalizePastedFlybyCameras(Editor editor, IReadOnlyCollection unpackedObjects) { var pastedFlybys = unpackedObjects.OfType().ToList(); @@ -159,4 +159,4 @@ private static void NormalizePastedFlybyCameras(Editor editor, IReadOnlyCollecti } } } -} \ No newline at end of file +}