-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Patch #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patch #1033
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,26 @@ private static object RemoveComponent(JObject @params, JToken targetToken, strin | |
| return new ErrorResponse($"Component type '{componentTypeName}' not found."); | ||
| } | ||
|
|
||
| // Use ComponentOps for the actual operation | ||
| int? componentIndex = ParamCoercion.CoerceIntNullable(@params["componentIndex"] ?? @params["component_index"]); | ||
| if (componentIndex.HasValue) | ||
| { | ||
| var components = targetGo.GetComponents(type); | ||
| if (componentIndex.Value < 0 || componentIndex.Value >= components.Length) | ||
| return new ErrorResponse($"component_index {componentIndex.Value} out of range. Found {components.Length} '{componentTypeName}' component(s)."); | ||
| if (type == typeof(Transform) || type == typeof(RectTransform)) | ||
| return new ErrorResponse("Cannot remove Transform or RectTransform components."); | ||
| Undo.DestroyObjectImmediate(components[componentIndex.Value]); | ||
|
Comment on lines
+149
to
+157
|
||
| EditorUtility.SetDirty(targetGo); | ||
| MarkOwningSceneDirty(targetGo); | ||
| return new | ||
| { | ||
| success = true, | ||
| message = $"Component '{componentTypeName}' (index {componentIndex.Value}) removed from '{targetGo.name}'.", | ||
| data = new { instanceID = targetGo.GetInstanceID(), componentIndex = componentIndex.Value } | ||
| }; | ||
| } | ||
|
|
||
| // Use ComponentOps for the actual operation (removes first instance) | ||
| bool removed = ComponentOps.RemoveComponent(targetGo, type, out string error); | ||
| if (!removed) | ||
| { | ||
|
|
@@ -188,7 +207,19 @@ private static object SetProperty(JObject @params, JToken targetToken, string se | |
| return new ErrorResponse($"Component type '{componentType}' not found."); | ||
| } | ||
|
|
||
| Component component = targetGo.GetComponent(type); | ||
| int? componentIndex = ParamCoercion.CoerceIntNullable(@params["componentIndex"] ?? @params["component_index"]); | ||
| Component component; | ||
| if (componentIndex.HasValue) | ||
| { | ||
| var components = targetGo.GetComponents(type); | ||
| if (componentIndex.Value < 0 || componentIndex.Value >= components.Length) | ||
| return new ErrorResponse($"component_index {componentIndex.Value} out of range. Found {components.Length} '{componentType}' component(s)."); | ||
| component = components[componentIndex.Value]; | ||
| } | ||
| else | ||
| { | ||
| component = targetGo.GetComponent(type); | ||
| } | ||
| if (component == null) | ||
| { | ||
| return new ErrorResponse($"Component '{componentType}' not found on '{targetGo.name}'."); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,9 +161,17 @@ public static object ConfigureJoint(JObject @params) | |
| return new ErrorResponse($"Target GameObject '{targetStr}' not found."); | ||
|
|
||
| string jointTypeStr = p.Get("joint_type"); | ||
| Component joint = ResolveJoint(go, jointTypeStr); | ||
| int? componentIndex = ParamCoercion.CoerceIntNullable(@params["componentIndex"] ?? @params["component_index"]); | ||
|
|
||
| if (componentIndex.HasValue && string.IsNullOrEmpty(jointTypeStr)) | ||
| return new ErrorResponse("component_index requires joint_type to be specified."); | ||
|
|
||
| Component joint = ResolveJoint(go, jointTypeStr, componentIndex, out int foundCount); | ||
| if (joint == null) | ||
| { | ||
| if (componentIndex.HasValue && foundCount >= 0) | ||
| return new ErrorResponse($"component_index {componentIndex.Value} out of range. Found {foundCount} joint(s) on '{go.name}'."); | ||
|
|
||
| if (!string.IsNullOrEmpty(jointTypeStr)) | ||
| return new ErrorResponse($"No joint of type '{jointTypeStr}' found on '{go.name}'."); | ||
|
|
||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
|
|
@@ -324,6 +332,10 @@ public static object RemoveJoint(JObject @params) | |
| return new ErrorResponse($"Target GameObject '{targetStr}' not found."); | ||
|
|
||
| string jointTypeStr = p.Get("joint_type"); | ||
| int? componentIndex = ParamCoercion.CoerceIntNullable(@params["componentIndex"] ?? @params["component_index"]); | ||
|
|
||
| if (componentIndex.HasValue && string.IsNullOrEmpty(jointTypeStr)) | ||
| return new ErrorResponse("component_index requires joint_type to be specified."); | ||
|
|
||
| var jointsToRemove = new List<Component>(); | ||
|
|
||
|
|
@@ -342,7 +354,17 @@ public static object RemoveJoint(JObject @params) | |
| } | ||
|
|
||
| var components = go.GetComponents(jointComponentType); | ||
| jointsToRemove.AddRange(components); | ||
|
|
||
| if (componentIndex.HasValue) | ||
| { | ||
| if (componentIndex.Value < 0 || componentIndex.Value >= components.Length) | ||
| return new ErrorResponse($"component_index {componentIndex.Value} out of range. Found {components.Length} '{jointComponentType.Name}' joint(s) on '{go.name}'."); | ||
| jointsToRemove.Add(components[componentIndex.Value]); | ||
| } | ||
| else | ||
| { | ||
| jointsToRemove.AddRange(components); | ||
| } | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -403,16 +425,27 @@ private static GameObject FindTarget(JToken targetToken, string searchMethod) | |
| return GameObjectLookup.FindByTarget(targetToken, searchMethod ?? "by_name", true); | ||
| } | ||
|
|
||
| private static Component ResolveJoint(GameObject go, string jointTypeStr) | ||
| private static Component ResolveJoint(GameObject go, string jointTypeStr, int? index, out int foundCount) | ||
| { | ||
| foundCount = -1; | ||
| if (!string.IsNullOrEmpty(jointTypeStr)) | ||
|
Comment on lines
+428
to
431
|
||
| { | ||
| bool is2D = go.GetComponent<Rigidbody2D>() != null; | ||
| var typeMap = is2D ? JointTypes2D : JointTypes3D; | ||
| string key = jointTypeStr.ToLowerInvariant(); | ||
|
|
||
| if (typeMap.TryGetValue(key, out Type jointType)) | ||
| { | ||
| if (index.HasValue) | ||
| { | ||
| var components = go.GetComponents(jointType); | ||
| foundCount = components.Length; | ||
| if (index.Value < 0 || index.Value >= components.Length) | ||
| return null; | ||
| return components[index.Value]; | ||
| } | ||
| return go.GetComponent(jointType); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject malformed
component_indexinstead of silently falling back.If
componentIndex/component_indexis present but non-numeric,CoerceIntNullablereturnsnull, and the code currently falls back to first-match behavior. That can remove or modify the wrong component.🛠️ Proposed fix
Also applies to: 168-169, 210-212, 220-222
🤖 Prompt for AI Agents