示例#1
0
        public void NextCase(IWorkshopTree value)
        {
            // If the state is on a case and the action count was changed, create new skip that will skip to the end of the switch.
            if (AutoBreak && State == SwitchBuilderState.OnCase && actionSet.ActionCount != LastCaseStart)
            {
                // Create the skip and add it to the actionset.
                SkipStartMarker skipToEnd = new SkipStartMarker(actionSet);
                actionSet.AddAction(skipToEnd);

                // Add it to the list of skips that need to skip to the end.
                SkipToEnd.Add(skipToEnd);
            }

            // Update the state.
            State = SwitchBuilderState.OnCase;

            // Mark the start of the case.
            SkipEndMarker startCase = new SkipEndMarker();

            actionSet.AddAction(startCase);

            // Add the skip length to the start of the case to the skipCounts.
            skipCounts.Add(Skipper.GetSkipCount(startCase));

            // Add the skip value.
            skipValues.Add(value);

            // Update the number of actions.
            LastCaseStart = actionSet.ActionCount;
        }
示例#2
0
        public void AddDefault()
        {
            if (defaultAdded)
            {
                throw new Exception("Default already added.");
            }
            defaultAdded = true;

            // Mark the start of the case.
            SkipEndMarker startCase = new SkipEndMarker();

            actionSet.AddAction(startCase);
            skipCounts.Insert(0, Skipper.GetSkipCount(startCase));
            State = SwitchBuilderState.OnCase;
        }
示例#3
0
        public void Finish(Element switchValue)
        {
            // Set state to finished.
            State = SwitchBuilderState.Finished;

            // Mark the end of the switch.
            SkipEndMarker switchEnd = new SkipEndMarker();

            actionSet.AddAction(switchEnd);

            // Update switch skips to skip to the end of the switch.
            foreach (SkipStartMarker skipToEnd in SkipToEnd)
            {
                skipToEnd.SetEndMarker(switchEnd);
            }

            // Default insert.
            // TODO: Default case
            if (!defaultAdded)
            {
                skipCounts.Insert(0, Skipper.GetSkipCount(switchEnd));
            }

            // Skip to the case.
            Skipper.SetSkipCount(
                // Create an array of all skip counts.
                Element.CreateArray(skipCounts.ToArray())[
                    // Get the case with the value that matches.
                    // IndexOfArrayValue will return -1 if the case is not found,
                    // Add 1 and skip to the default case.
                    Element.IndexOfArrayValue(
                        Element.CreateArray(skipValues.ToArray()),
                        switchValue
                        ) + 1
                ]
                );
        }