Ejemplo n.º 1
0
        bool WeavePointHasLooseEnd(IWeavePoint weavePoint)
        {
            // No content, must be a loose end.
            if (weavePoint.content == null)
            {
                return(true);
            }

            // If a weave point is diverted from, it doesn't have a loose end.
            // Detect a divert object within a weavePoint's main content
            // Work backwards since we're really interested in the end,
            // although it doesn't actually make a difference!
            // (content after a divert will simply be inaccessible)
            for (int i = weavePoint.content.Count - 1; i >= 0; --i)
            {
                var innerDivert = weavePoint.content [i] as Divert;
                if (innerDivert)
                {
                    bool willReturn = innerDivert.isThread || innerDivert.isTunnel || innerDivert.isFunctionCall;
                    if (!willReturn)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        // While analysing final loose ends, we look to see whether there
        // are any diverts etc which choices etc divert from
        IEnumerable <Parsed.Object> ContentThatFollowsWeavePoint(IWeavePoint weavePoint)
        {
            var obj = (Parsed.Object)weavePoint;

            // Inner content first (e.g. for a choice)
            if (obj.content != null)
            {
                foreach (var contentObj in obj.content)
                {
                    // Global VARs and CONSTs are treated as "outside of the flow"
                    if (IsGlobalDeclaration(contentObj))
                    {
                        continue;
                    }

                    yield return(contentObj);
                }
            }


            var parentWeave = obj.parent as Weave;

            if (parentWeave == null)
            {
                throw new System.Exception("Expected weave point parent to be weave?");
            }

            var weavePointIdx = parentWeave.content.IndexOf(obj);

            for (int i = weavePointIdx + 1; i < parentWeave.content.Count; i++)
            {
                var laterObj = parentWeave.content [i];

                // Global VARs and CONSTs are treated as "outside of the flow"
                if (IsGlobalDeclaration(laterObj))
                {
                    continue;
                }

                // End of the current flow
                if (laterObj is IWeavePoint)
                {
                    break;
                }

                // Other weaves will be have their own loose ends
                if (laterObj is Weave)
                {
                    break;
                }

                yield return(laterObj);
            }
        }
Ejemplo n.º 3
0
        public IWeavePoint WeavePointNamed(string name)
        {
            if (_namedWeavePoints == null)
            {
                return(null);
            }

            IWeavePoint weavePointResult = null;

            if (_namedWeavePoints.TryGetValue(name, out weavePointResult))
            {
                return(weavePointResult);
            }

            return(null);
        }
Ejemplo n.º 4
0
        void AddRuntimeForWeavePoint(IWeavePoint weavePoint)
        {
            // Current level Gather
            if (weavePoint is Gather)
            {
                AddRuntimeForGather((Gather)weavePoint);
            }

            // Current level choice
            else if (weavePoint is Choice)
            {
                // Gathers that contain choices are no longer loose ends
                // (same as when weave points get nested content)
                if (previousWeavePoint is Gather)
                {
                    looseEnds.Remove(previousWeavePoint);
                }

                // Add choice point content
                var choice = (Choice)weavePoint;
                currentContainer.AddContent(choice.runtimeObject);

                // Add choice's inner content to self
                choice.innerContentContainer.name = "c-" + _choiceCount;
                currentContainer.AddToNamedContentOnly(choice.innerContentContainer);
                _choiceCount++;

                hasSeenChoiceInSection = true;
            }

            // Keep track of loose ends
            addContentToPreviousWeavePoint = false; // default
            if (WeavePointHasLooseEnd(weavePoint))
            {
                looseEnds.Add(weavePoint);


                var looseChoice = weavePoint as Choice;
                if (looseChoice)
                {
                    addContentToPreviousWeavePoint = true;
                }
            }
            previousWeavePoint = weavePoint;
        }
Ejemplo n.º 5
0
        bool WeavePointHasLooseEnd(IWeavePoint weavePoint)
        {
            // Simple choice with explicit divert
            // definitely doesn't have a loose end
            if (weavePoint is Choice)
            {
                var choice = (Choice)weavePoint;

                // However, explicit gather point is definitely a loose end
                if (choice.hasExplicitGather)
                {
                    return(true);
                }

                if (choice.hasTerminatingDivert)
                {
                    return(false);
                }
            }

            // No content, and no simple divert above, must be a loose end.
            // (content list on Choices gets created on demand, hence how
            // it could be null)
            if (weavePoint.content == null)
            {
                return(true);
            }

            // Detect a divert object within a weavePoint's main content
            // Work backwards since we're really interested in the end,
            // although it doesn't actually make a difference!
            else
            {
                for (int i = weavePoint.content.Count - 1; i >= 0; --i)
                {
                    var innerDivert = weavePoint.content [i] as Divert;
                    if (innerDivert && !innerDivert.isToGather)
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
Ejemplo n.º 6
0
        void AddRuntimeForWeavePoint(IWeavePoint weavePoint)
        {
            // Current level Gather
            if (weavePoint is Gather)
            {
                AddRuntimeForGather((Gather)weavePoint);
            }

            // Current level choice
            else if (weavePoint is Choice)
            {
                // Gathers that contain choices are no longer loose ends
                // (same as when weave points get nested content)
                if (previousWeavePoint is Gather)
                {
                    looseEnds.Remove((Parsed.Object)previousWeavePoint);
                }

                currentContainer.AddContent(((Choice)weavePoint).runtimeObject);
                hasSeenChoiceInSection = true;
            }

            // Keep track of loose ends
            addContentToPreviousWeavePoint = false; // default
            if (WeavePointHasLooseEnd(weavePoint))
            {
                looseEnds.Add((Parsed.Object)weavePoint);

                // If choice has an explicit gather divert ("->") then it doesn't need content added to it
                var looseChoice = weavePoint as Choice;
                if (looseChoice && !looseChoice.hasExplicitGather)
                {
                    addContentToPreviousWeavePoint = true;
                }
            }
            previousWeavePoint = weavePoint;
        }
Ejemplo n.º 7
0
 void ReceiveLooseEnd(IWeavePoint childWeaveLooseEnd)
 {
     looseEnds.Add(childWeaveLooseEnd);
 }
Ejemplo n.º 8
0
Archivo: Weave.cs Proyecto: tomkail/ink
        bool WeavePointHasLooseEnd(IWeavePoint weavePoint)
        {
            // Simple choice with explicit divert
            // definitely doesn't have a loose end
            if (weavePoint is Choice) {
                var choice = (Choice)weavePoint;

                // However, explicit gather point is definitely a loose end
                if (choice.hasExplicitGather) {
                    return true;
                }

                if (choice.hasTerminatingDivert) {
                    return false;
                }
            }

            // No content, and no simple divert above, must be a loose end.
            // (content list on Choices gets created on demand, hence how
            // it could be null)
            if (weavePoint.content == null) {
                return true;
            }

            // Detect a divert object within a weavePoint's main content
            // Work backwards since we're really interested in the end,
            // although it doesn't actually make a difference!
            else {
                for (int i = weavePoint.content.Count - 1; i >= 0; --i) {
                    var innerDivert = weavePoint.content [i] as Divert;
                    if (innerDivert && !innerDivert.isToGather) {
                        return false;
                    }
                }

                return true;
            }
        }
Ejemplo n.º 9
0
Archivo: Weave.cs Proyecto: tomkail/ink
        void AddRuntimeForWeavePoint(IWeavePoint weavePoint)
        {
            // Current level Gather
            if (weavePoint is Gather) {
                AddRuntimeForGather ((Gather)weavePoint);
            }

            // Current level choice
            else if (weavePoint is Choice) {

                // Gathers that contain choices are no longer loose ends
                // (same as when weave points get nested content)
                if (previousWeavePoint is Gather) {
                    looseEnds.Remove ((Parsed.Object)previousWeavePoint);
                }

                currentContainer.AddContent (((Choice)weavePoint).runtimeObject);
                hasSeenChoiceInSection = true;
            }

            // Keep track of loose ends
            addContentToPreviousWeavePoint = false; // default
            if (WeavePointHasLooseEnd (weavePoint)) {
                looseEnds.Add ((Parsed.Object)weavePoint);

                // If choice has an explicit gather divert ("->") then it doesn't need content added to it
                var looseChoice = weavePoint as Choice;
                if (looseChoice && !looseChoice.hasExplicitGather) {
                    addContentToPreviousWeavePoint = true;
                }
            }
            previousWeavePoint = weavePoint;
        }