aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Console/ConsoleUtil.cs78
1 files changed, 65 insertions, 13 deletions
diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs
index 794bfaf..b7a3494 100644
--- a/OpenSim/Framework/Console/ConsoleUtil.cs
+++ b/OpenSim/Framework/Console/ConsoleUtil.cs
@@ -252,24 +252,80 @@ namespace OpenSim.Framework.Console
252 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue 252 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue
253 /// Other than that, component values must be numeric. 253 /// Other than that, component values must be numeric.
254 /// </param> 254 /// </param>
255 /// <param name='blankComponentFunc'></param> 255 /// <param name='blankComponentFunc'>
256 /// Behaviour if component is blank. If null then conversion fails on a blank component.
257 /// </param>
256 /// <param name='vector'></param> 258 /// <param name='vector'></param>
257 /// <returns></returns> 259 /// <returns></returns>
258 public static bool TryParseConsoleVector( 260 public static bool TryParseConsoleVector(
259 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector) 261 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector)
260 { 262 {
261 List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList(); 263 return Vector3.TryParse(CookVector(rawConsoleVector, 3, blankComponentFunc), out vector);
262 264 }
263 if (components.Count < 1 || components.Count > 3) 265
266 /// <summary>
267 /// Convert a vector input from the console to an OpenMetaverse.Vector2
268 /// </summary>
269 /// <param name='rawConsoleVector'>
270 /// A string in the form <x>,<y> where there is no space between values.
271 /// Any component can be missing (e.g. ,40). blankComponentFunc is invoked to replace the blank with a suitable value
272 /// Also, if the blank component is at the end, then the comma can be missed off entirely (e.g. 40)
273 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue
274 /// Other than that, component values must be numeric.
275 /// </param>
276 /// <param name='blankComponentFunc'>
277 /// Behaviour if component is blank. If null then conversion fails on a blank component.
278 /// </param>
279 /// <param name='vector'></param>
280 /// <returns></returns>
281 public static bool TryParseConsole2DVector(
282 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector2 vector)
283 {
284 // We don't use Vector2.TryParse() for now because for some reason it expects an input with 3 components
285 // rather than 2.
286 string cookedVector = CookVector(rawConsoleVector, 2, blankComponentFunc);
287
288 if (cookedVector == null)
264 { 289 {
265 vector = Vector3.Zero;
266 return false; 290 return false;
267 } 291 }
292 else
293 {
294 string[] cookedComponents = cookedVector.Split(VectorSeparatorChars);
295
296 vector = new Vector2(float.Parse(cookedComponents[0]), float.Parse(cookedComponents[1]));
297
298 return true;
299 }
300
301 //return Vector2.TryParse(CookVector(rawConsoleVector, 2, blankComponentFunc), out vector);
302 }
303
304 /// <summary>
305 /// Convert a raw console vector into a vector that can be be parsed by the relevant OpenMetaverse.TryParse()
306 /// </summary>
307 /// <param name='rawConsoleVector'></param>
308 /// <param name='dimensions'></param>
309 /// <param name='blankComponentFunc'></param>
310 /// <returns>null if conversion was not possible</returns>
311 private static string CookVector(
312 string rawConsoleVector, int dimensions, Func<string, string> blankComponentFunc)
313 {
314 List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList();
268 315
269 for (int i = components.Count; i < 3; i++) 316 if (components.Count < 1 || components.Count > dimensions)
270 components.Add(""); 317 return null;
271 318
272 List<string> semiDigestedComponents 319 if (components.Count < dimensions)
320 {
321 if (blankComponentFunc == null)
322 return null;
323 else
324 for (int i = components.Count; i < dimensions; i++)
325 components.Add("");
326 }
327
328 List<string> cookedComponents
273 = components.ConvertAll<string>( 329 = components.ConvertAll<string>(
274 c => 330 c =>
275 { 331 {
@@ -283,11 +339,7 @@ namespace OpenSim.Framework.Console
283 return c; 339 return c;
284 }); 340 });
285 341
286 string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray()); 342 return string.Join(VectorSeparator, cookedComponents.ToArray());
287
288 // m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector);
289
290 return Vector3.TryParse(semiDigestedConsoleVector, out vector);
291 } 343 }
292 } 344 }
293} \ No newline at end of file 345} \ No newline at end of file