private static IEnumerable <LevelNumbers> ParagraphsToConsiderWhenCounting(
            XDocument numbering, XDocument styles, XElement paragraph, int levelNumber)
        {
            ListItemInfo listItemInfo = GetListItemInfo(numbering, styles, paragraph);
            int?         lvlRestart   = (int?)listItemInfo.Lvl.Elements(W.lvlRestart)
                                        .Attributes(W.val).FirstOrDefault();
            int paragraphLevel = (int)listItemInfo.Lvl.Attribute(W.ilvl);
            IEnumerable <XElement> paragraphsBeforeSelf = paragraph
                                                          .ElementsBeforeSelfReverseDocumentOrder().Where(e => e.Name == W.p);

            foreach (var p in paragraphsBeforeSelf)
            {
                ListItemInfo pListItemInfo = GetListItemInfo(numbering, styles, p);
                if (!pListItemInfo.IsListItem ||
                    pListItemInfo.AbstractNumId != listItemInfo.AbstractNumId)
                {
                    continue;
                }
                LevelNumbers pLevelNumbers = p.Annotation <LevelNumbers>();
                int          pLevel        = (int)pListItemInfo.Lvl.Attribute(W.ilvl);
                if (pLevel > levelNumber)
                {
                    yield return(pLevelNumbers);
                }
                if (lvlRestart == null)
                {
                    if (pLevel < levelNumber)
                    {
                        yield break;
                    }
                }
                else
                {
                    if (pLevel < levelNumber && pLevel > lvlRestart - 1)
                    {
                        continue;
                    }
                    else if (pLevel < levelNumber)
                    {
                        yield break;
                    }
                }
                yield return(pLevelNumbers);
            }
        }
Beispiel #2
0
    public void gameWon(LevelNumbers level)
    {
        if (!beatenLevels.Contains(level))
        {
            beatenLevels.Add(level);
        }

        if ((level == LevelNumbers.A3 ||
             level == LevelNumbers.B3 ||
             level == LevelNumbers.C3) &&
            (beatenLevels.Contains(LevelNumbers.A3) &&
             beatenLevels.Contains(LevelNumbers.B3) &&
             beatenLevels.Contains(LevelNumbers.C3))
            )
        {
            this.changeLevel("Creditos");
        }
        else
        {
            this.changeLevel("LevelSelectionScreen");
        }
    }
Beispiel #3
0
        private static void InitializeListItemRetrieverForStory(XDocument numXDoc, XDocument stylesXDoc, XElement rootNode)
        {
            var paragraphs = rootNode
                             .DescendantsTrimmed(W.txbxContent)
                             .Where(p => p.Name == W.p);

            foreach (var paragraph in paragraphs)
            {
                InitListItemInfo(numXDoc, stylesXDoc, paragraph);
            }

            var abstractNumIds = paragraphs
                                 .Select(paragraph =>
            {
                ListItemInfo listItemInfo = paragraph.Annotation <ListItemInfo>();
                if (!listItemInfo.IsListItem)
                {
                    return((int?)null);
                }
                return(listItemInfo.AbstractNumId);
            })
                                 .Where(a => a != null)
                                 .Distinct()
                                 .ToList();

            // when debugging, it is sometimes useful to cause processing of a specific abstractNumId first.
            // the following code enables this.
            //int? abstractIdToProcessFirst = null;
            //if (abstractIdToProcessFirst != null)
            //{
            //    abstractNumIds = (new[] { abstractIdToProcessFirst })
            //        .Concat(abstractNumIds.Where(ani => ani != abstractIdToProcessFirst))
            //        .ToList();
            //}

            foreach (var abstractNumId in abstractNumIds)
            {
                var listItems = paragraphs
                                .Where(paragraph =>
                {
                    var listItemInfo = paragraph.Annotation <ListItemInfo>();
                    if (!listItemInfo.IsListItem)
                    {
                        return(false);
                    }
                    return(listItemInfo.AbstractNumId == abstractNumId);
                })
                                .ToList();

                // annotate paragraphs with previous paragraphs so that we can look backwards with good perf
                XElement prevParagraph = null;
                foreach (var paragraph in listItems)
                {
                    ReverseAxis reverse = new ReverseAxis()
                    {
                        PreviousParagraph = prevParagraph,
                    };
                    paragraph.AddAnnotation(reverse);
                    prevParagraph = paragraph;
                }

                var            startOverrideAlreadyUsed = new List <int>();
                List <int>     previous = null;
                ListItemInfo[] listItemInfoInEffectForStartOverride = new ListItemInfo[] {
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                };
                foreach (var paragraph in listItems)
                {
                    var listItemInfo = paragraph.Annotation <ListItemInfo>();
                    var ilvl         = GetParagraphLevel(paragraph);
                    listItemInfoInEffectForStartOverride[ilvl] = listItemInfo;
                    ListItemInfo listItemInfoInEffect = null;
                    if (ilvl > 0)
                    {
                        listItemInfoInEffect = listItemInfoInEffectForStartOverride[ilvl - 1];
                    }
                    var levelNumbers = new List <int>();

                    for (int level = 0; level <= ilvl; level++)
                    {
                        var numId                 = listItemInfo.NumId;
                        var startOverride         = listItemInfo.StartOverride(level);
                        int?inEffectStartOverride = null;
                        if (listItemInfoInEffect != null)
                        {
                            inEffectStartOverride = listItemInfoInEffect.StartOverride(level);
                        }

                        if (level == ilvl)
                        {
                            var lvl        = listItemInfo.Lvl(ilvl);
                            var lvlRestart = (int?)lvl.Elements(W.lvlRestart).Attributes(W.val).FirstOrDefault();
                            if (lvlRestart != null)
                            {
                                var previousPara = PreviousParagraphsForLvlRestart(paragraph, (int)lvlRestart)
                                                   .FirstOrDefault(p =>
                                {
                                    var plvl = GetParagraphLevel(p);
                                    return(plvl == ilvl);
                                });
                                if (previousPara != null)
                                {
                                    previous = previousPara.Annotation <LevelNumbers>().LevelNumbersArray.ToList();
                                }
                            }
                        }

                        if (previous == null ||
                            level >= previous.Count() ||
                            (level == ilvl && startOverride != null && !startOverrideAlreadyUsed.Contains(numId)))
                        {
                            if (previous == null || level >= previous.Count())
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null && !startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        start = (int)startOverride;
                                    }
                                    else
                                    {
                                        if (startOverride != null)
                                        {
                                            start = (int)startOverride;
                                        }
                                        if (inEffectStartOverride != null && inEffectStartOverride > start)
                                        {
                                            start = (int)inEffectStartOverride;
                                        }
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                            else
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null)
                                    {
                                        if (!startOverrideAlreadyUsed.Contains(numId))
                                        {
                                            startOverrideAlreadyUsed.Add(numId);
                                            start = (int)startOverride;
                                        }
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                        }
                        else
                        {
                            int?thisNumber = null;
                            if (level == ilvl)
                            {
                                if (startOverride != null)
                                {
                                    if (!startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        thisNumber = (int)startOverride;
                                    }
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                                else
                                {
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                            }
                            else
                            {
                                thisNumber = previous.ElementAt(level);
                            }
                            levelNumbers.Add((int)thisNumber);
                        }
                    }
                    var levelNumbersAnno = new LevelNumbers()
                    {
                        LevelNumbersArray = levelNumbers.ToArray()
                    };
                    paragraph.AddAnnotation(levelNumbersAnno);
                    previous = levelNumbers;
                }
            }
        }
        private static int[] GetLevelNumbers(XDocument numbering, XDocument styles,
                                             XElement paragraph)
        {
            IEnumerable <XElement> paragraphsBeforeSelf = paragraph
                                                          .ElementsBeforeSelfReverseDocumentOrder().Where(e => e.Name == W.p);
            int          level;
            ListItemInfo listItemInfo = GetListItemInfo(numbering, styles, paragraph);

            level = (int)listItemInfo.Lvl.Attribute(W.ilvl);
            List <int> levelNumbers = new List <int>();

            for (int indentationLevel = 0; indentationLevel <= level; ++indentationLevel)
            {
                XElement currentIndentLvl = GetRelatedLevel(listItemInfo.Lvl,
                                                            indentationLevel);
                int?start = (int?)currentIndentLvl.Elements(W.start).Attributes(W.val)
                            .FirstOrDefault();
                if (start == null)
                {
                    start = 1;
                }
                XElement paragraphWithSameAbstractNumId = paragraphsBeforeSelf
                                                          .FirstOrDefault(p =>
                {
                    ListItemInfo pListItemInfo = GetListItemInfo(numbering, styles, p);
                    return(pListItemInfo.IsListItem &&
                           pListItemInfo.AbstractNumId == listItemInfo.AbstractNumId);
                });
                if (paragraphWithSameAbstractNumId != null)
                {
                    LevelNumbers pLevelNumbers = paragraphWithSameAbstractNumId
                                                 .Annotation <LevelNumbers>();
                    if (pLevelNumbers.LevelNumbersArray.Length > indentationLevel)
                    {
                        if (indentationLevel == level)
                        {
                            levelNumbers.Add(
                                pLevelNumbers.LevelNumbersArray[indentationLevel] + 1);
                        }
                        else
                        {
                            levelNumbers.Add(pLevelNumbers
                                             .LevelNumbersArray[indentationLevel]);
                        }
                        continue;
                    }
                }

                if (level == indentationLevel)
                {
                    int c1 = GetLevelNumberForLevel(numbering, styles, paragraph,
                                                    indentationLevel);
                    int?start2 = listItemInfo.Start;
                    if (start2 == null)
                    {
                        start2 = 1;
                    }
                    levelNumbers.Add(c1 + (int)start2);
                    continue;
                }
                levelNumbers.Add((int)start);
            }
            return(levelNumbers.ToArray());
        }
        private static void InitializeListItemRetrieverForStory(XDocument numXDoc, XDocument stylesXDoc, XElement rootNode)
        {
            var paragraphs = rootNode
                .DescendantsTrimmed(W.txbxContent)
                .Where(p => p.Name == W.p);

            foreach (var paragraph in paragraphs)
                InitListItemInfo(numXDoc, stylesXDoc, paragraph);

            var abstractNumIds = paragraphs
                .Select(paragraph =>
                {
                    ListItemInfo listItemInfo = paragraph.Annotation<ListItemInfo>();
                    if (!listItemInfo.IsListItem)
                        return (int?)null;
                    return listItemInfo.AbstractNumId;
                })
                .Where(a => a != null)
                .Distinct()
                .ToList();

            // when debugging, it is sometimes useful to cause processing of a specific abstractNumId first.
            // the following code enables this.
            //int? abstractIdToProcessFirst = null;
            //if (abstractIdToProcessFirst != null)
            //{
            //    abstractNumIds = (new[] { abstractIdToProcessFirst })
            //        .Concat(abstractNumIds.Where(ani => ani != abstractIdToProcessFirst))
            //        .ToList();
            //}

            foreach (var abstractNumId in abstractNumIds)
            {
                var listItems = paragraphs
                    .Where(paragraph =>
                    {
                        var listItemInfo = paragraph.Annotation<ListItemInfo>();
                        if (!listItemInfo.IsListItem)
                            return false;
                        return listItemInfo.AbstractNumId == abstractNumId;
                    })
                    .ToList();

                // annotate paragraphs with previous paragraphs so that we can look backwards with good perf
                XElement prevParagraph = null;
                foreach (var paragraph in listItems)
                {
                    ReverseAxis reverse = new ReverseAxis()
                    {
                        PreviousParagraph = prevParagraph,
                    };
                    paragraph.AddAnnotation(reverse);
                    prevParagraph = paragraph;
                }

                var startOverrideAlreadyUsed = new List<int>();
                List<int> previous = null;
                ListItemInfo[] listItemInfoInEffectForStartOverride = new ListItemInfo[] {
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                };
                foreach (var paragraph in listItems)
                {
                    var listItemInfo = paragraph.Annotation<ListItemInfo>();
                    var ilvl = GetParagraphLevel(paragraph);
                    listItemInfoInEffectForStartOverride[ilvl] = listItemInfo;
                    ListItemInfo listItemInfoInEffect = null;
                    if (ilvl > 0)
                        listItemInfoInEffect = listItemInfoInEffectForStartOverride[ilvl - 1];
                    var levelNumbers = new List<int>();

                    for (int level = 0; level <= ilvl; level++)
                    {
                        var numId = listItemInfo.NumId;
                        var startOverride = listItemInfo.StartOverride(level);
                        int? inEffectStartOverride = null;
                        if (listItemInfoInEffect != null)
                            inEffectStartOverride = listItemInfoInEffect.StartOverride(level);

                        if (level == ilvl)
                        {
                            var lvl = listItemInfo.Lvl(ilvl);
                            var lvlRestart = (int?)lvl.Elements(W.lvlRestart).Attributes(W.val).FirstOrDefault();
                            if (lvlRestart != null)
                            {
                                var previousPara = PreviousParagraphsForLvlRestart(paragraph, (int)lvlRestart)
                                    .FirstOrDefault(p =>
                                    {
                                        var plvl = GetParagraphLevel(p);
                                        return plvl == ilvl;
                                    });
                                if (previousPara != null)
                                    previous = previousPara.Annotation<LevelNumbers>().LevelNumbersArray.ToList();
                            }
                        }

                        if (previous == null ||
                            level >= previous.Count() ||
                            (level == ilvl && startOverride != null && !startOverrideAlreadyUsed.Contains(numId)))
                        {
                            if (previous == null || level >= previous.Count())
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null && !startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        start = (int)startOverride;
                                    }
                                    else
                                    {
                                        if (startOverride != null)
                                            start = (int)startOverride;
                                        if (inEffectStartOverride != null && inEffectStartOverride > start)
                                            start = (int)inEffectStartOverride;
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                            else
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null)
                                    {
                                        if (!startOverrideAlreadyUsed.Contains(numId))
                                        {
                                            startOverrideAlreadyUsed.Add(numId);
                                            start = (int)startOverride;
                                        }
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                        }
                        else
                        {
                            int? thisNumber = null;
                            if (level == ilvl)
                            {
                                if (startOverride != null)
                                {
                                    if (!startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        thisNumber = (int)startOverride;
                                    }
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                                else
                                {
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                            }
                            else
                            {
                                thisNumber = previous.ElementAt(level);
                            }
                            levelNumbers.Add((int)thisNumber);
                        }
                    }
                    var levelNumbersAnno = new LevelNumbers()
                    {
                        LevelNumbersArray = levelNumbers.ToArray()
                    };
                    paragraph.AddAnnotation(levelNumbersAnno);
                    previous = levelNumbers;
                }
            }
        }