コード例 #1
0
 public void ReadFile(string path, Storyboard result)
 {
     using (var streamreader = new StreamReader(osuElements.FileReaderFunc(path))) {
         EventBase           currentEvent     = null;
         TransformationEvent currentTransform = null;
         var line = streamreader.ReadLine();
         while (line != null)
         {
             if (line == "")
             {
                 line = streamreader.ReadLine();
                 continue;
             }
             if (line.StartsWith("//"))
             {
                 line = streamreader.ReadLine();
                 continue;
             }
             if (line.StartsWith(" "))
             {
                 if (line.StartsWith("  "))
                 {
                     TransformationEvent tt;
                     if (TransformationEvent.TryParse(line, out tt) && currentTransform != null)
                     {
                         //if (currentTransform.Transformtype == TransformTypes.L) {
                         //    var loopEvent = currentTransform as LoopEvent;
                         //    loopEvent?.AddTransformation(tt);
                         //}
                         //else if (currentTransform.Transformtype == TransformTypes.T) {
                         //    var triggerEvent = currentTransform as TriggerEvent;
                         //    triggerEvent?.AddTransformation(tt);
                         //}
                     }
                 }
                 else
                 {
                     if (TransformationEvent.TryParse(line, out currentTransform))
                     {
                         (currentEvent as SpriteEvent)?.AddTransformation(currentTransform);
                     }
                 }
             }
             else
             {
                 if (EventBase.TryParse(line, out currentEvent))
                 {
                     result.AddEvent(currentEvent);
                 }
             }
             line = streamreader.ReadLine();
         }
     }
 }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: wwwMADwww/osuElements
 private static void Optimization2(ICollection <TransformationEvent> passed, TransformationEvent transform)
 {
     foreach (var pass in passed.Where(pass => MathHelper.Between(transform.StartTime, pass.StartTime, pass.EndTime)))
     {
         if (MathHelper.Between(transform.EndTime, pass.StartTime, pass.EndTime))
         {
             return; //event is completely useless
         }
         //we can only interpolate without easing, otherwise not desired effect (might look into this further)
         if (transform.Tweening && transform.Easing != None)
         {
             continue;
         }
         transform.StartValues = transform.ValuesAt(pass.EndTime);
         transform.StartTime   = pass.EndTime; //move the starttime and interpolate values
     }
     passed.Add(transform);
 }
コード例 #3
0
ファイル: Extensions.cs プロジェクト: wwwMADwww/osuElements
        public static void OptimizeTransformations(this ITransformable transformable)
        {
            var transforms = transformable.Transformations.OrderBy(t => t.StartTime).GroupBy(t => t.Transformtype)
                             .ToDictionary(t => t.Key, t => t.ToList());
            var globalstart = transformable.Transformations.Min(t => t.StartTime);
            var globalend   = transformable.Transformations.Max(t => t.EndTime);

            //splits all M transforms in separate MX and MY, otherwise they will not work
            //only when there are other MX or MY events, M is fine otherwise
            if (transforms[M].Any() && (transforms[MX].Any() || transforms[MY].Any()))
            {
                foreach (var m in transforms[M])
                {
                    var mx = new TransformationEvent(MX, m.Easing, m.StartTime, m.EndTime, m.StartValues[0].AsArray(),
                                                     m.EndValues[0].AsArray());
                    var my = new TransformationEvent(MY, m.Easing, m.StartTime, m.EndTime, m.StartValues[1].AsArray(),
                                                     m.EndValues[1].AsArray());
                    transformable.AddTransformation(mx);
                    transformable.AddTransformation(my);
                }
                transformable.Transformations.RemoveAll(t => t.Transformtype == M);
                transforms = transformable.Transformations.OrderBy(t => t.StartTime).GroupBy(t => t.Transformtype)
                             .ToDictionary(t => t.Key, t => t.ToList());
                globalstart = transformable.Transformations.Min(t => t.StartTime);
                globalend   = transformable.Transformations.Max(t => t.EndTime);
            }

            //strip off unneeded parts of transformations
            foreach (var transformList in transforms.Values)
            {
                var passed = new List <TransformationEvent>();
                //resulting collection after optimization, might contain less or modifed transforms
                foreach (var transform in transformList)
                {
                    Optimization2(passed, transform);
                }
                //we can now trim down events without tweening
                foreach (var transform in passed)
                {
                    if (transform.EndTime == globalend && transform.StartTime == globalstart)
                    {
                        continue; //might be needed for visibility of the sprite
                    }
                    if (!passed.Any(p => MathHelper.Between(p.StartTime, transform.StartTime, transform.EndTime) ||
                                    MathHelper.Between(p.EndTime, transform.StartTime, transform.EndTime)))
                    {
                        //no other transforms are active
                        transform.EndTime = transform.StartTime;
                    }
                }
                transforms[transformList[0].Transformtype] = passed;
            }

            //TODO disable invisible parts of transformations

            //var fade0 = 0f.AsArray();

            //var fades = transformable.Transformations.Where(t => t.Transformtype == F);
            //if (!fades.Any(t => t.StartValues == fade0 || t.EndValues == fade0)) return; //everything is always visible
            //foreach (var transformType in _normalTransformations) {
            //    var transformables = transformable.Transformations.Where(t => t.Transformtype == transformType);
            //    if (!transformables.Any()) continue;
            //}
        }