Skip to content

Commit

Permalink
Improved Storyboard parsing;
Browse files Browse the repository at this point in the history
  • Loading branch information
kdobrzynski committed Apr 15, 2021
1 parent c916cda commit 4227870
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 26 deletions.
20 changes: 14 additions & 6 deletions Negum.Core/Loaders/IDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,31 @@ public async Task<IData> LoadAsync(IEngine engine)

if (!string.IsNullOrWhiteSpace(motifLogoPath))
{
var motifLogoFullPath = this.FindFile(motifFile.Directory.FullName, motifLogoPath);
data.LogoManager = await this.ReadManagerAsync<IStoryboardManager>(motifLogoFullPath);
data.LogoAnimationManager = await this.ReadManagerAsync<IAnimationManager, IAnimationReader>(motifLogoFullPath);
data.Logo = await this.ReadStoryboardAsync(motifFile.Directory.FullName, motifLogoPath);
}

var motifIntroPath = data.MotifManager.Files.IntroStoryboardDefinition;

if (!string.IsNullOrWhiteSpace(motifIntroPath))
{
var motifIntroFullPath = this.FindFile(motifFile.Directory.FullName, motifIntroPath);
data.IntroManager = await this.ReadManagerAsync<IStoryboardManager>(motifIntroFullPath);
data.IntroAnimationManager = await this.ReadManagerAsync<IAnimationManager, IAnimationReader>(motifIntroFullPath);
data.Intro = await this.ReadStoryboardAsync(motifFile.Directory.FullName, motifIntroPath);
}

return data;
}

protected virtual async Task<IStoryboard> ReadStoryboardAsync(string dirName, string fileName)
{
var defFilePath = this.FindFile(dirName, fileName);
var storyboard = new Storyboard();

storyboard.Manager = await this.ReadManagerAsync<IStoryboardManager>(defFilePath);
storyboard.Animation = await this.ReadManagerAsync<IAnimationManager, IAnimationReader>(defFilePath);
storyboard.Sprite = await this.GetSpriteAsync(dirName, storyboard.Manager.SceneDef.SpriteFile);

return storyboard;
}

protected override FileInfo FindFile(string dirName, string fileName)
{
if (fileName.StartsWith("data/"))
Expand Down
3 changes: 3 additions & 0 deletions Negum.Core/Managers/Types/IStoryboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface IStoryboardManager : IManager

public interface IStoryboardSceneDef : IManagerSection
{
/// <summary>
/// Path to the sprite file.
/// </summary>
string SpriteFile => this.GetValue<string>("spr");

/// <summary>
Expand Down
24 changes: 6 additions & 18 deletions Negum.Core/Models/Data/IData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,14 @@ public interface IData
IFightManager FightManager { get; }

/// <summary>
/// Manager which wraps logo definition.
/// Defines Logo-related information.
/// </summary>
IStoryboardManager LogoManager { get; }
IStoryboard Logo { get; }

/// <summary>
/// Manager which wraps logo animation.
/// Defines Intro-related information.
/// </summary>
IAnimationManager LogoAnimationManager { get; }

/// <summary>
/// Manager which wraps intro definition.
/// </summary>
IStoryboardManager IntroManager { get; }

/// <summary>
/// Manager which wraps intro animation.
/// </summary>
IAnimationManager IntroAnimationManager { get; }
IStoryboard Intro { get; }
}

/// <summary>
Expand All @@ -78,9 +68,7 @@ public class NegumData : IData
public ISound MotifSound { get; internal set; }
public ISelectionManager SelectionManager { get; internal set; }
public IFightManager FightManager { get; internal set; }
public IStoryboardManager LogoManager { get; internal set; }
public IAnimationManager LogoAnimationManager { get; internal set; }
public IStoryboardManager IntroManager { get; internal set; }
public IAnimationManager IntroAnimationManager { get; internal set; }
public IStoryboard Logo { get; internal set; }
public IStoryboard Intro { get; internal set; }
}
}
43 changes: 43 additions & 0 deletions Negum.Core/Models/Data/IStoryboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Negum.Core.Managers.Types;
using Negum.Core.Models.Sprites;

namespace Negum.Core.Models.Data
{
/// <summary>
/// Represents Storyboard data read from directory.
/// </summary>
///
/// <author>
/// https://github.com/TheNegumProject/Negum.Core
/// </author>
public interface IStoryboard
{
/// <summary>
/// Main manager which contains information about current Storyboard.
/// </summary>
IStoryboardManager Manager { get; }

/// <summary>
/// Manager which contains information about Animations in this Storyboard.
/// </summary>
IAnimationManager Animation { get; }

/// <summary>
/// Sprites used by this storyboard.
/// </summary>
ISprite Sprite { get; }
}

/// <summary>
/// </summary>
///
/// <author>
/// https://github.com/TheNegumProject/Negum.Core
/// </author>
public class Storyboard : IStoryboard
{
public IStoryboardManager Manager { get; internal set; }
public IAnimationManager Animation { get; internal set; }
public ISprite Sprite { get; internal set; }
}
}
3 changes: 1 addition & 2 deletions Tests/Negum.Core.Tests/Managers/StoryboardManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ namespace Negum.Core.Tests.Managers
public class StoryboardManagerTests : TestBase
{
[Theory]
[InlineData(
"https://raw.githubusercontent.com/TheNegumProject/DragonBallMugenEdition2009/main/data/Backup/intro.def")]
[InlineData("https://raw.githubusercontent.com/TheNegumProject/DragonBallMugenEdition2009/main/data/Backup/intro.def")]
public async Task Should_Count_Number_Of_Scenes_And_Print_Details(string path)
{
this.InitializeContainer();
Expand Down

0 comments on commit 4227870

Please sign in to comment.