Skip to content

Commit e8f7541

Browse files
committed
refactor clock hand code to shorten detection logic
1 parent 9e18ed1 commit e8f7541

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

Source/RunActivity/Viewer3D/Scenery.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
using System.Diagnostics;
5252
using System.IO;
5353
using System.Linq;
54+
using System.Text.RegularExpressions;
5455

5556
namespace Orts.Viewer3D
5657
{
@@ -327,7 +328,6 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible)
327328

328329
var shadowCaster = (worldObject.StaticFlags & (uint)StaticFlag.AnyShadow) != 0 || viewer.Settings.ShadowAllShapes;
329330
var animated = (worldObject.StaticFlags & (uint)StaticFlag.Animate) != 0;
330-
var isAnimatedClock = false; //Declare and preset shape is not an animated clock
331331
var global = (worldObject is TrackObj) || (worldObject is HazardObj) || (worldObject.StaticFlags & (uint)StaticFlag.Global) != 0;
332332

333333
// 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)
480480
}
481481
else if (worldObject.GetType() == typeof(StaticObj))
482482
{
483-
isAnimatedClock = false; //Preset
484483
// preTestShape for lookup if it is an animated clock shape with subobjects named as clock hands
485484
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));
504487
if (isAnimatedClock)
505488
{
506489
sceneryObjects.Add(new AnalogClockShape(viewer, shapeFilePath, worldMatrix, shadowCaster ? ShapeFlags.ShadowCaster : ShapeFlags.None));

0 commit comments

Comments
 (0)