public AnimationPage()
        {
            this.InitializeComponent();
            var link   = this.Intent()["link"];
            var tamdoc = TamUtils.getXMLAsset(this.Intent()["link"]);

            alltams = TamUtils.tamList(tamdoc).Where(t => t.attr("display") != "none");
            animtot = alltams.Count();
            animnum = int.Parse(this.Intent()["anim"]);
            Callouts.SetLevel(link);
            setAnimation();
            Callouts.AnimationFinished = () => {
                PlayPath.Fill  = new SolidColorBrush(Colors.Black);
                PausePath.Fill = new SolidColorBrush(Colors.Transparent);
                playing        = false;
            };
            ManipulationMode       = ManipulationModes.TranslateX;
            ManipulationStarted   += (x, e) => x1 = (int)e.Position.X;
            ManipulationCompleted += (x, e) =>
            {
                x2 = (int)e.Position.X;
                if (x1 - x2 > animationView.ActualWidth / 2 && animnum + 1 < animtot)
                {
                    // swipe left
                    animnum++;
                    setAnimation();
                }
                else if (x2 - x1 > animationView.ActualWidth / 2 && animnum > 0)
                {
                    // swipe right
                    animnum--;
                    setAnimation();
                }
            };
        }
Example #2
0
        bool matchXMLcall(string calltext, bool fuzzy = false)
        {
            var found   = false;
            var matches = false;
            var ctx0    = this;
            var ctx     = this;

            //  If there are precursors, run them first so the result
            //  will be used to match formations
            //  Needed for calls like "Explode And ..."
            if (callstack.Count > 0)
            {
                ctx           = new CallContext(this);
                ctx.callstack = callstack;
                ctx.performCall();
            }

            //  If actives != dancers, create another call context with just the actives
            if (ctx.dancers.Count != ctx.actives.Count)
            {
                ctx = new CallContext(ctx.actives);
            }
            //  Try to find a match in the xml animations
            var callquery = "^" + TamUtils.callnameQuery(calltext) + "$";
            var callfiles = TamUtils.calllistdata.Where(x => Regex.Match(x.text, callquery).Success);
            //  Found xml file with call, now look through each animation
            //  First read and extract all the animations to a list
            var tams = callfiles.SelectMany(d => TamUtils.getXMLAsset(d.link).SelectNodes("/tamination/tam")).ToList();

            found = tams.Count > 0;
            //  Now find the animations that match the name and formation
            tams.Where(tam => Regex.Match(tam.attr("title").ToLower().ReplaceAll("\\W", ""), callquery).Success)
            .Any(tam => {
                var f = tam.hasAttr("formation")
                    ? TamUtils.getFormation(tam.attr("formation"))
                    : tam.SelectNodes("formation").First();
                var ctx2 = new CallContext(f);
                var sexy = tam.hasAttr("gender-specific");
                //  Try to match the formation to the current dancer positions
                var mm = matchFormations(ctx, ctx2, sexy, fuzzy);
                if (mm != null)
                {
                    matches = true;
                    // add XMLCall object to the call stack
                    ctx0.callstack.Add(new XMLCall(tam, mm, ctx2));
                    ctx0.callname = callname + tam.attr("title") + " ";
                }
                return(matches);
            });
            if (found && !matches)
            {
                //  Found the call but formations did not match
                throw new FormationNotFoundError(calltext);
            }
            return(matches);
        }
        public void reset(string level)
        {
            LevelData   d       = LevelData.find(level);
            var         isIndex = d.dir == "all";
            XmlDocument calldoc = TamUtils.getXMLAsset(isIndex ? "src\\callindex.xml" : "src\\calls.xml");

            Callouts.SetTitle(d.name);
            calls = calldoc.SelectNodes(isIndex ? "/calls/call" : $"/calls/call[@{d.selector}]");
            searchCallList("");
        }
Example #4
0
 public override void nextAnimation() {
   if (tutnum >= tutdata.Length)
     tutnum = 0;
   var tamdoc = TamUtils.getXMLAsset("src/tutorial.xml");
   var gender = settings.Values["gender"]?.ToString() == "Girl" ? Gender.GIRL : Gender.BOY;
   var offset = gender == Gender.BOY ? 0 : 1;
   var tamlist = tamdoc.SelectNodes("/tamination/tam");
   var tam = tamlist[tutnum * 2 + offset];
   Callouts.SetTitle(tam.attr("title"));
   page.Animation.setAnimation(tam,(int)gender);
   switch (settings.Values["practicespeed"]?.ToString()) {
     case "Normal": page.Animation.setSpeed("Normal"); break;
     case "Moderate": page.Animation.setSpeed("Moderate"); break;
     default: page.Animation.setSpeed("Slow"); break;
   }
   showInstructions();
 }
        public virtual void nextAnimation()
        {
            var      calldoc  = TamUtils.getXMLAsset("src/calls.xml");
            var      selector = LevelData.find(page.Intent()["level"]).selector;
            var      calls    = calldoc.SelectNodes($"/calls/call[@{selector}]");
            IXmlNode tam      = null;
            var      rand     = new Random();

            while (tam == null)
            {
                var e = calls[rand.Next((int)calls.Length)];
                //  Remember link for definition
                link = e.attr("link");
                var tamdoc = TamUtils.getXMLAsset(link);
                var tams   = tamdoc.SelectNodes("/tamination/tam")
                             //  For now, skip any "difficult" animations
                             .Where((IXmlNode x) => { return(x.attr("difficulty") != "3"); })
                             //  Skip any call with parens in the title - it could be a cross-reference
                             //  to a concept call from a higher level
                             .Where((IXmlNode x) => { return(!x.attr("title").Contains("(")); });
                if (tams.Count() > 0)
                {
                    tam = tams.ElementAt(rand.Next(tams.Count()));
                    var gender = settings.Values["practicegender"]?.ToString() == "Boy"
            ? (int)Gender.BOY : (int)Gender.GIRL;
                    page.Animation.setAnimation(tam, gender);
                    switch (settings.Values["practicespeed"]?.ToString())
                    {
                    case "Normal": page.Animation.setSpeed("Normal"); break;

                    case "Moderate": page.Animation.setSpeed("Moderate"); break;

                    default: page.Animation.setSpeed("Slow"); break;
                    }
                    Callouts.SetTitle(tam.attr("title"));
                }
            }
        }
Example #6
0
        public void reset()
        {
            // Fetch the list of animations and build the table
            var prevtitle = "";
            var prevgroup = "";

            link = this.Intent()["link"];
            Callouts.SetLevel(link);
            XmlDocument tamdoc = TamUtils.getXMLAsset(link);
            var         title  = tamdoc.SelectSingleNode("/tamination").attr("title");

            Callouts.SetTitle(title);
            var tams      = TamUtils.tamList(tamdoc);
            var diffsum   = 0;
            var firstanim = -1;
            var i         = 0;

            foreach (IXmlNode tam in tams)
            {
                if (tam.attr("display") == "none")
                {
                    continue;
                }
                var tamtitle = tam.attr("title");
                var from     = TamUtils.tamXref(tam).attr("from");
                var group    = tam.attr("group");
                var diffstr  = TamUtils.tamXref(tam).attr("difficulty");
                var diff     = diffstr.Length > 0 ? int.Parse(diffstr) : 0;
                diffsum += diff;
                if (group.Length > 0)
                {
                    // Add header for new group as needed
                    if (group != prevgroup)
                    {
                        if (Regex.Match(group, @"^\s+$").Success)
                        {
                            // Blank group, for calls with no common starting phrase
                            // Add a green separator unless it's the first group
                            if (anims.Count > 0)
                            {
                                anims.Add(new AnimListItem()
                                {
                                    celltype = CellType.Separator
                                });
                            }
                        }
                        else
                        {
                            // Named group e.g. "As Couples.."
                            // Add a header with the group name, which starts
                            // each call in the group
                            anims.Add(new AnimListItem()
                            {
                                celltype = CellType.Header,
                                name     = group
                            });
                        }
                    }
                    from = tamtitle.Replace(group, " ").Trim();
                }
                else if (tamtitle != prevtitle)
                {
                    // Not a group but a different call
                    // Put out a header with this call
                    anims.Add(new AnimListItem()
                    {
                        celltype = CellType.Header,
                        name     = tamtitle + " from"
                    });
                }
                //  Build list item for this animation
                prevtitle = tamtitle;
                prevgroup = group;
                //  TODO posanim(av.getCount) = i
                //  Remember where the first real animation is in the list
                if (firstanim < 0)
                {
                    firstanim = anims.Count;
                }
                //  TODO selectanim and weblink
                //  ...
                // Put out a selectable item
                anims.Add(new AnimListItem()
                {
                    celltype   = Regex.Match(group, @"^\s+$").Success ? CellType.Plain : CellType.Indented,
                    title      = tamtitle,
                    name       = from,
                    group      = group.Length > 0 ? group : tamtitle + " from",
                    animnumber = i,
                    difficulty = diff
                });
                i = i + 1;
            }
            if (diffsum <= 0)
            {
                DifficultyLegend.Visibility = Visibility.Collapsed;
            }
            AnimList.ItemsSource = anims;
            if (firstanim >= 0)
            {
                Callouts.FirstAnimationReady(anims[firstanim]);
            }
        }