|
51 | 51 | using System.Diagnostics; |
52 | 52 | using System.IO; |
53 | 53 | using System.Linq; |
| 54 | +using System.Text.RegularExpressions; |
54 | 55 |
|
55 | 56 | namespace Orts.Viewer3D |
56 | 57 | { |
@@ -327,7 +328,6 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible) |
327 | 328 |
|
328 | 329 | var shadowCaster = (worldObject.StaticFlags & (uint)StaticFlag.AnyShadow) != 0 || viewer.Settings.ShadowAllShapes; |
329 | 330 | var animated = (worldObject.StaticFlags & (uint)StaticFlag.Animate) != 0; |
330 | | - var isAnimatedClock = false; //Declare and preset shape is not an animated clock |
331 | 331 | var global = (worldObject is TrackObj) || (worldObject is HazardObj) || (worldObject.StaticFlags & (uint)StaticFlag.Global) != 0; |
332 | 332 |
|
333 | 333 | // TransferObj have a FileName but it is not a shape, so we need to avoid sanity-checking it as if it was. |
@@ -480,27 +480,10 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible) |
480 | 480 | } |
481 | 481 | else if (worldObject.GetType() == typeof(StaticObj)) |
482 | 482 | { |
483 | | - isAnimatedClock = false; //Preset |
484 | 483 | // preTestShape for lookup if it is an animated clock shape with subobjects named as clock hands |
485 | 484 | StaticShape preTestShape = (new StaticShape(viewer, shapeFilePath, worldMatrix, shadowCaster ? ShapeFlags.ShadowCaster : ShapeFlags.None)); |
486 | | - if (preTestShape.SharedShape.Animations != null) // shape has an Animation at all |
487 | | - { |
488 | | - if (preTestShape.SharedShape.Animations[0].anim_nodes.Count > 1) // shape has more than 1 anim node |
489 | | - { |
490 | | - //lookup in all anim nodes of the shape for subobjects named as clock hands |
491 | | - foreach (var animNodes in preTestShape.SharedShape.Animations[0].anim_nodes) |
492 | | - { |
493 | | - if (animNodes.Name.ToLowerInvariant().IndexOf("hand_clock") == 6) //Shape anim node name contains "hand_clock" |
494 | | - { |
495 | | - if (animNodes.Name.ToLowerInvariant().IndexOf("orts_") == 0) //Shape anim node name begins with "ORTS_" |
496 | | - { |
497 | | - isAnimatedClock = true; //Shape is animated clock |
498 | | - break; //Exit because of find a clock hand subobject |
499 | | - } |
500 | | - } |
501 | | - } |
502 | | - } |
503 | | - } |
| 485 | + var animNodes = preTestShape.SharedShape.Animations?[0]?.anim_nodes ?? new List<anim_node>(); |
| 486 | + var isAnimatedClock = animNodes.Exists(node => Regex.IsMatch(node.Name, @"^orts_[hmsc]hand_clock", RegexOptions.IgnoreCase)); |
504 | 487 | if (isAnimatedClock) |
505 | 488 | { |
506 | 489 | sceneryObjects.Add(new AnalogClockShape(viewer, shapeFilePath, worldMatrix, shadowCaster ? ShapeFlags.ShadowCaster : ShapeFlags.None)); |
|
0 commit comments