コード例 #1
0
ファイル: Suffixed.cs プロジェクト: stephengeorgewest/KOS-1
        public override void Execute(SharedObjects shared)
        {
            AssertArgBottomAndConsume(shared); // no args

            // ReSharper disable SuggestUseVarKeywordEvident
            ListValue <WaypointValue> returnList = new ListValue <WaypointValue>();
            // ReSharper enable SuggestUseVarKeywordEvident

            WaypointManager wpm = WaypointManager.Instance();

            if (wpm == null)
            {
                ReturnValue = returnList; // When no waypoints exist, there isn't even a waypoint manager at all.
                return;
            }

            List <Waypoint> points = wpm.Waypoints;

            // If the code below gets used in more places it may be worth moving into a factory method
            // akin to how PartValueFactory makes a ListValue<PartValue> from a List<Part>.
            // But for now, this is the only place it's done:

            foreach (Waypoint point in points)
            {
                WaypointValue wp = WaypointValue.CreateWaypointValueWithCheck(point, shared, true);
                if (wp != null)
                {
                    returnList.Add(wp);
                }
            }
            ReturnValue = returnList;
        }
コード例 #2
0
ファイル: Suffixed.cs プロジェクト: stephengeorgewest/KOS-1
        public override void Execute(SharedObjects shared)
        {
            string pointName = PopValueAssert(shared).ToString();

            AssertArgBottomAndConsume(shared);

            WaypointManager wpm = WaypointManager.Instance();

            // If no contracts have been generated with waypoints in them,
            // then sometimes the stock game's waypoint manager doesn't even
            // exist yet either.  (The base game seems not to instance one until the
            // first time a contract with a waypoint is created).
            if (wpm == null)
            {
                throw new KOSInvalidArgumentException("waypoint", "\"" + pointName + "\"", "no waypoints exist");
            }

            // If this name has a greek letter in it's spelling like "alpha", "beta", etc, then it
            // is probably part of a waypoint cluster.
            // Waypoint clusters are actually 1 waypoint with an array of "children" by index number.
            // where the waypoint's name is just the base part with the "alpha", "beta", etc suffix removed.
            string baseName;
            int    index;
            bool   hasGreek = WaypointValue.GreekToInteger(pointName, out index, out baseName);

            Waypoint point = null;

            if (hasGreek) // Attempt to find it as part of a waypoint cluster.
            {
                point = wpm.Waypoints.FirstOrDefault(
                    p => string.Equals(p.name, baseName, StringComparison.CurrentCultureIgnoreCase) && (!hasGreek || p.index == index));
                if (point != null) // Will be null if this name is not really a waypoint cluster.
                {
                    pointName = baseName;
                }
            }
            if (point == null) // Either it had no greek letter, or it did but wasn't a waypoint cluster.  Try it as a vanilla waypoint:
            {
                point = wpm.Waypoints.FirstOrDefault(
                    p => string.Equals(p.name, pointName, StringComparison.CurrentCultureIgnoreCase) && (!hasGreek || p.index == index));
            }

            // If it's still null at this point then give up - we can't find such a waypoint name:
            if (point == null)
            {
                throw new KOSInvalidArgumentException("waypoint", "\"" + pointName + "\"", "no such waypoint");
            }

            ReturnValue = WaypointValue.CreateWaypointValueWithCheck(point, shared, false);
        }