private static void onIdChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { Storyboard sb = obj as Storyboard; if (sb == null) { return; } string key = e.NewValue as string; if (key == null) { return; } if (storyboards.ContainsKey(key)) { return; } sb.Completed += delegate(object sender, EventArgs args) { StoryboardInfo info = storyboards[key]; if (info.Callback != null) { info.Callback(); } }; storyboards[key] = new StoryboardInfo() { Storyboard = sb, Callback = null }; }
private static void AnalyseSB(Storyboard storyboard) { if (storyboard != null) { var mapDir = Path.GetDirectoryName(storyboard.FilePath); var storyboardInfo = new StoryboardInfo(storyboard); var t = storyboardInfo.GenerateSpriteData(); List <IAnalyser> Analysers = new List <IAnalyser>() { new ConflictAnalyser(), new ProlongedActivityAnalyser(), new FadeOutAnalyser(), new IllogicalAnalyser(), new RedundancyAnalyser(), new CommandCountAnalyser(), }; var osbAnalyser = new OsbAnalyser.StoryboardAnalyser(Analysers); var analysedSb = osbAnalyser.Analyse(storyboard); List <string> output = new List <string>(); analysedSb.AnalysedElements.ToList().ForEach(e => { string elementInfo = $"Element {e.VisualElement.RelativePath} at line {e.VisualElement.Line} with {e.StoryboardWarnings.Count()} warnings:"; string warnings = String.Join(Environment.NewLine, e.StoryboardWarnings.Where(w => w != null) .OrderByDescending(w => w.WarningLevel) .Select(w => $" Warning Level {(int)w.WarningLevel}: {w.GetType().Name}: {w.ToString()}")); if (!string.IsNullOrWhiteSpace(warnings)) { output.Add(elementInfo); output.Add(warnings); output.Add(Environment.NewLine); } } ); string targetPath = Path.Combine(mapDir, "StoryboardWarnings.txt"); if (File.Exists(targetPath)) { File.Delete(targetPath); } File.AppendAllLines(targetPath, output); t.Wait(); StoryboardInfoDrawer drawer = new StoryboardInfoDrawer(storyboardInfo); drawer.DrawSpriteGraph().Save(Path.Combine(mapDir, "spritegraph.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); drawer.DrawCommandGraph().Save(Path.Combine(mapDir, "commandgraph.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); } else { Console.WriteLine("No storyboard found."); } }
public static bool PlayStoryboard(string id) { if (!storyboards.ContainsKey(id)) { return(false); } StoryboardInfo sb = storyboards[id]; sb.Storyboard.Dispatcher.BeginInvoke(new Action(sb.Storyboard.Begin)); return(true); }
public static void Delete(string id) { if (!storyboards.ContainsKey(id)) { return; } StoryboardInfo info = storyboards[id]; info.Storyboard.SetValue(IdProperty, null); storyboards.Remove(id); }
public static bool PlayStoryboard(string id, ParamCallback callback, object state) { if (!storyboards.ContainsKey(id)) { return(false); } StoryboardInfo sb = storyboards[id]; sb.Callback = () => callback(state); sb.Storyboard.Dispatcher.BeginInvoke(new Action(sb.Storyboard.Begin)); return(true); }
static void OnIDChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { Storyboard sb = obj as Storyboard; if (sb == null) { return; } string key = e.NewValue as string; if (_storyboards.ContainsKey(key)) { // very strange, WPF currently making another instance of the storyboard here // but we've already started a different instance, so ignore return; } sb.Completed += delegate(object sender, EventArgs args) { _storyboards[key].Callback(); }; _storyboards[key] = new StoryboardInfo() { Storyboard = sb, Callback = null }; }
public StoryboardInfoDrawer(StoryboardInfo storyboardInfo) { StoryboardInfo = storyboardInfo; }