Skip to content

Commit

Permalink
Added support for Logo and Intro storyboards;
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejoslaw committed Apr 11, 2021
1 parent 8f39bc2 commit 1dcfb82
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Negum.Core/Loaders/IDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public async Task<IData> LoadAsync(IEngine engine)
var motifFightFullPath = this.FindFile(motifFile.Directory, motifFightPath);
data.FightManager = await this.ReadManagerAsync<IFightManager>(motifFightFullPath);

var motifLogoPath = data.MotifManager.Files.LogoStoryboardDefinition;

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

var motifIntroPath = data.MotifManager.Files.IntroStoryboardDefinition;

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

return data;
}

Expand Down
45 changes: 45 additions & 0 deletions Negum.Core/Managers/Types/IStoryboardManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using Negum.Core.Managers.Entries;

namespace Negum.Core.Managers.Types
{
/// <summary>
/// Manager which handles Storyboard configuration.
///
/// NOTE:
/// Similar to ICharacterStoryboardSceneManager but for different purposes.
/// </summary>
///
/// <author>
/// https://github.com/TheNegumProject/Negum.Core
/// </author>
public interface IStoryboardManager : IManager
{
IStoryboardSceneDef SceneDef => this.GetSection<IStoryboardSceneDef>("SceneDef");
IEnumerable<IStoryboardScene> Scenes => this.GetSubsections<IStoryboardScene>("SceneDef");
}

public interface IStoryboardSceneDef : IManagerSection
{
string SpriteFile => this.GetValue<string>("spr");

/// <summary>
/// Stating scene number (for debugging).
/// </summary>
int StartScene => this.GetValue<int>("startscene");
}

public interface IStoryboardScene : IManagerSection
{
ITimeEntry FadeInTime => this.GetValue<ITimeEntry>("fadein.time");
IVectorEntry FadeInColor => this.GetValue<IVectorEntry>("fadein.col");
ITimeEntry FadeOutTime => this.GetValue<ITimeEntry>("fadeout.time");
IVectorEntry FadeOutColor => this.GetValue<IVectorEntry>("fadeout.col");
IVectorEntry ClearColor => this.GetValue<IVectorEntry>("clearcolor");
IVectorEntry LayerAllPosition => this.GetValue<IVectorEntry>("layerall.pos");
IImageEntry Layer0 => this.GetValue<IImageEntry>("layer0");
IImageEntry Layer1 => this.GetValue<IImageEntry>("layer1");
IAudioEntry BackgroundMusic => this.GetValue<IAudioEntry>("bgm");
ITimeEntry TotalTime => this.GetValue<ITimeEntry>("end.time");
}
}
27 changes: 27 additions & 0 deletions Negum.Core/Managers/Types/StoryboardManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Negum.Core.Configurations;

namespace Negum.Core.Managers.Types
{
/// <summary>
/// </summary>
///
/// <author>
/// https://github.com/TheNegumProject/Negum.Core
/// </author>
public class StoryboardManager : Manager, IStoryboardManager
{
protected override IManagerSection GetNewManagerSection(string sectionName, IConfigurationSection configSection) =>
new StoryboardManagerSection(sectionName, configSection);
}

public class StoryboardManagerSection :
ManagerSection,
IStoryboardSceneDef,
IStoryboardScene
{
public StoryboardManagerSection(string name, IConfigurationSection section) :
base(name, section)
{
}
}
}
14 changes: 13 additions & 1 deletion Negum.Core/Models/Data/IData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,21 @@ public interface IData
/// Manager which wraps selection definition.
/// </summary>
ISelectionManager SelectionManager { get; }

/// <summary>
/// Manager which wraps fight definition.
/// </summary>
IFightManager FightManager { get; }

/// <summary>
/// Manager which wraps logo definition.
/// </summary>
IStoryboardManager LogoManager { get; }

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

/// <summary>
Expand All @@ -58,5 +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 IStoryboardManager IntroManager { get; internal set; }
}
}
35 changes: 35 additions & 0 deletions Tests/Negum.Core.Tests/Managers/StoryboardManagerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Linq;
using System.Threading.Tasks;
using Negum.Core.Containers;
using Negum.Core.Managers.Types;
using Xunit;

namespace Negum.Core.Tests.Managers
{
/// <summary>
/// </summary>
///
/// <author>
/// https://github.com/TheNegumProject/Negum.Core
/// </author>
public class StoryboardManagerTests : TestBase
{
[Theory]
[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();

var config = await this.ParseWithSubsections(path);
var manager = (IStoryboardManager) NegumContainer.Resolve<IStoryboardManager>().UseConfiguration(config);
var scenes = manager.Scenes;

Assert.True(scenes.Count() == 3);

var time = scenes.FirstOrDefault().FadeInTime;
var timeDetails = time.GetTimeSpan().Ticks;

Assert.True(timeDetails == 35);
}
}
}

0 comments on commit 1dcfb82

Please sign in to comment.