|
6 | 6 | from services.tools import get_unity_instance_from_context |
7 | 7 | from transport.unity_transport import send_with_unity_instance |
8 | 8 | from transport.legacy.unity_connection import async_send_command_with_retry |
| 9 | +from services.tools.utils import coerce_bool |
9 | 10 |
|
10 | 11 |
|
11 | 12 | @mcp_for_unity_tool( |
@@ -86,19 +87,6 @@ async def manage_gameobject( |
86 | 87 | unity_instance = get_unity_instance_from_context(ctx) |
87 | 88 |
|
88 | 89 | # Coercers to tolerate stringified booleans and vectors |
89 | | - def _coerce_bool(value, default=None): |
90 | | - if value is None: |
91 | | - return default |
92 | | - if isinstance(value, bool): |
93 | | - return value |
94 | | - if isinstance(value, str): |
95 | | - v = value.strip().lower() |
96 | | - if v in ("true", "1", "yes", "on"): |
97 | | - return True |
98 | | - if v in ("false", "0", "no", "off"): |
99 | | - return False |
100 | | - return bool(value) |
101 | | - |
102 | 90 | def _coerce_vec(value, default=None): |
103 | 91 | if value is None: |
104 | 92 | return default |
@@ -128,13 +116,13 @@ def _to_vec3(parts): |
128 | 116 | rotation = _coerce_vec(rotation, default=rotation) |
129 | 117 | scale = _coerce_vec(scale, default=scale) |
130 | 118 | offset = _coerce_vec(offset, default=offset) |
131 | | - save_as_prefab = _coerce_bool(save_as_prefab) |
132 | | - set_active = _coerce_bool(set_active) |
133 | | - find_all = _coerce_bool(find_all) |
134 | | - search_in_children = _coerce_bool(search_in_children) |
135 | | - search_inactive = _coerce_bool(search_inactive) |
136 | | - includeNonPublicSerialized = _coerce_bool(includeNonPublicSerialized) |
137 | | - world_space = _coerce_bool(world_space, default=True) |
| 119 | + save_as_prefab = coerce_bool(save_as_prefab) |
| 120 | + set_active = coerce_bool(set_active) |
| 121 | + find_all = coerce_bool(find_all) |
| 122 | + search_in_children = coerce_bool(search_in_children) |
| 123 | + search_inactive = coerce_bool(search_inactive) |
| 124 | + includeNonPublicSerialized = coerce_bool(includeNonPublicSerialized) |
| 125 | + world_space = coerce_bool(world_space, default=True) |
138 | 126 |
|
139 | 127 | # Coerce 'component_properties' from JSON string to dict for client compatibility |
140 | 128 | if isinstance(component_properties, str): |
|
0 commit comments