Skip to content

Commit

Permalink
Simplified Storyboard reading;
Browse files Browse the repository at this point in the history
  • Loading branch information
kdobrzynski committed Apr 16, 2021
1 parent 4227870 commit fa9d6e2
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 182 deletions.
19 changes: 19 additions & 0 deletions Negum.Core/Loaders/AbstractLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Negum.Core.Containers;
using Negum.Core.Engines;
using Negum.Core.Managers;
using Negum.Core.Managers.Types;
using Negum.Core.Models.Data;
using Negum.Core.Models.Sounds;
using Negum.Core.Models.Sprites;
using Negum.Core.Readers;
Expand All @@ -21,6 +23,23 @@ namespace Negum.Core.Loaders
/// </author>
public abstract class AbstractLoader
{
protected virtual async Task<IStoryboard> ReadStoryboardAsync(string dirName, string fileName)
{
if (string.IsNullOrWhiteSpace(fileName))
{
return null;
}

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 virtual async Task<ISound> GetSoundAsync(string dirName, string soundPath)
{
var file = this.FindFile(dirName, soundPath);
Expand Down
36 changes: 16 additions & 20 deletions Negum.Core/Loaders/ICharacterLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected virtual async Task<ICharacter> GetCharacterAsync(DirectoryInfo dir)

if (characterDefFile == null)
{
throw new ArgumentException($"Missing DEF file in: \"{dir.FullName}\" with name: \"{ dir.Name }.def\"");
throw new ArgumentException($"Missing DEF file in: \"{dir.FullName}\" with name: \"{dir.Name}.def\"");
}

var character = new Character
Expand All @@ -68,30 +68,26 @@ protected virtual async Task<ICharacter> GetCharacterAsync(DirectoryInfo dir)
character.Sprite = await this.GetSpriteAsync(characterDefFile.DirectoryName, character.CharacterManager.Files.SpriteFiles);
character.AnimationManager = await this.FindManagerAsync<IAnimationManager>(characterDefFile.DirectoryName, character.CharacterManager.Files.AnimationFile);
character.Sound = await this.GetSoundAsync(characterDefFile.DirectoryName, character.CharacterManager.Files.SoundFile);
character.AiHints = this.ReadAiHints(characterDefFile.DirectoryName, character.CharacterManager.Files.AiHintsDataFile);
character.Intro = await this.ReadStoryboardAsync(characterDefFile.FullName, character.CharacterManager.Arcade.IntroStoryboardFile);
character.Ending = await this.ReadStoryboardAsync(characterDefFile.FullName, character.CharacterManager.Arcade.EndingStoryboardFile);

return character;
}

if (character.CharacterManager.Files.AiHintsDataFile != null)
protected virtual ICharacterAiHints ReadAiHints(string dirName, string dataFile)
{
if (string.IsNullOrWhiteSpace(dataFile))
{
character.AiHints = new CharacterAiHints
{
File = new FileInfo(Path.Combine(characterDefFile.DirectoryName, character.CharacterManager.Files.AiHintsDataFile))
};
return null;
}

var introStoryboardFile = character.CharacterManager.Arcade.IntroStoryboardFile;
if (!string.IsNullOrWhiteSpace(introStoryboardFile))

var aiHints = new CharacterAiHints
{
character.IntroManager = await this.ReadManagerAsync<ICharacterStoryboardSceneManager>(characterDefFile, introStoryboardFile);
character.IntroSprite = await this.GetSpriteAsync(characterDefFile.DirectoryName, character.IntroManager.SceneDef.SpriteFile);
}
File = new FileInfo(Path.Combine(dirName, dataFile))
};

var endingStoryboardFile = character.CharacterManager.Arcade.EndingStoryboardFile;
if (!string.IsNullOrWhiteSpace(endingStoryboardFile))
{
character.EndingManager = await this.ReadManagerAsync<ICharacterStoryboardSceneManager>(characterDefFile, endingStoryboardFile);
character.EndingSprite = await this.GetSpriteAsync(characterDefFile.DirectoryName, character.EndingManager.SceneDef.SpriteFile);
}

return character;
return aiHints;
}

protected virtual async Task<ICharacterConstantsManager> ReadCommonStatesAsync(FileInfo characterDefFile, string path)
Expand Down
43 changes: 13 additions & 30 deletions Negum.Core/Loaders/IDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Negum.Core.Engines;
using Negum.Core.Managers.Types;
using Negum.Core.Models.Data;
using Negum.Core.Readers;

namespace Negum.Core.Loaders
{
Expand Down Expand Up @@ -35,50 +34,34 @@ public async Task<IData> LoadAsync(IEngine engine)

data.ConfigManager = await this.FindManagerAsync<IConfigurationManager>(dir, configFileName);

var motifFile = this.FindFile(dir, data.ConfigManager.Options.MotifFile);

data.MotifManager = await this.FindManagerAsync<IMotifManager>(dir, data.ConfigManager.Options.MotifFile);
data.MotifSprite = await this.GetSpriteAsync(motifFile.Directory.FullName, data.MotifManager.Files.SpriteFile);
data.MotifSound = await this.GetSoundAsync(motifFile.Directory.FullName, data.MotifManager.Files.SoundFile);
data.SelectionManager = await this.FindManagerAsync<ISelectionManager>(motifFile.Directory.FullName, data.MotifManager.Files.SelectionFile);
data.FightManager = await this.FindManagerAsync<IFightManager>(motifFile.Directory.FullName, data.MotifManager.Files.FightFile);

var motifLogoPath = data.MotifManager.Files.LogoStoryboardDefinition;
var motifFileName = data.ConfigManager.Options.MotifFile;
var motifFile = this.FindFile(dir, motifFileName);

if (!string.IsNullOrWhiteSpace(motifLogoPath))
if (motifFile == null)
{
data.Logo = await this.ReadStoryboardAsync(motifFile.Directory.FullName, motifLogoPath);
throw new FileNotFoundException($"Cannot find motif file: {motifFileName}");
}

var motifIntroPath = data.MotifManager.Files.IntroStoryboardDefinition;
var motifDirFullName = motifFile.Directory.FullName;

if (!string.IsNullOrWhiteSpace(motifIntroPath))
{
data.Intro = await this.ReadStoryboardAsync(motifFile.Directory.FullName, motifIntroPath);
}
data.MotifManager = await this.FindManagerAsync<IMotifManager>(dir, data.ConfigManager.Options.MotifFile);
data.MotifSprite = await this.GetSpriteAsync(motifDirFullName, data.MotifManager.Files.SpriteFile);
data.MotifSound = await this.GetSoundAsync(motifDirFullName, data.MotifManager.Files.SoundFile);
data.SelectionManager = await this.FindManagerAsync<ISelectionManager>(motifDirFullName, data.MotifManager.Files.SelectionFile);
data.FightManager = await this.FindManagerAsync<IFightManager>(motifDirFullName, data.MotifManager.Files.FightFile);
data.Logo = await this.ReadStoryboardAsync(motifDirFullName, data.MotifManager.Files.LogoStoryboardDefinition);
data.Intro = await this.ReadStoryboardAsync(motifDirFullName, data.MotifManager.Files.IntroStoryboardDefinition);

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/"))
{
fileName = fileName.Replace("data/", "");
}

return base.FindFile(dirName, fileName);
}
}
Expand Down
28 changes: 0 additions & 28 deletions Negum.Core/Managers/Types/CharacterStoryboardSceneManager.cs

This file was deleted.

44 changes: 0 additions & 44 deletions Negum.Core/Managers/Types/ICharacterStoryboardSceneManager.cs

This file was deleted.

43 changes: 16 additions & 27 deletions Negum.Core/Models/Characters/ICharacter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using Negum.Core.Managers.Types;
using Negum.Core.Models.Data;
using Negum.Core.Models.Sounds;
using Negum.Core.Models.Sprites;

Expand All @@ -18,71 +19,61 @@ public interface ICharacter : IFileReadable
/// Directory from which the current character was loaded.
/// </summary>
DirectoryInfo Directory { get; }

/// <summary>
/// Manager which wraps main DEF file.
/// </summary>
ICharacterManager CharacterManager { get; }

/// <summary>
/// Manager which wraps character's commands.
/// </summary>
ICharacterCommandsManager CommandsManager { get; }

/// <summary>
/// Manager which wraps character's constants.
/// </summary>
ICharacterConstantsManager ConstantsManager { get; }

/// <summary>
/// Manager which wraps character's states.
/// </summary>
ICharacterConstantsManager StatesManager { get; }

/// <summary>
/// Manager which wraps common states.
/// </summary>
ICharacterConstantsManager CommonStatesManager { get; }

/// <summary>
/// Character's sprite.
/// </summary>
ISprite Sprite { get; }

/// <summary>
/// Manager which wraps character's animations.
/// </summary>
IAnimationManager AnimationManager { get; }

/// <summary>
/// Character's sound.
/// </summary>
ISound Sound { get; }

/// <summary>
/// Character's AI hints.
/// </summary>
ICharacterAiHints AiHints { get; }

/// <summary>
/// Manager which wraps character's storyboard intro.
/// </summary>
ICharacterStoryboardSceneManager IntroManager { get; }

/// <summary>
/// Character's storyboard intro sprite.
/// </summary>
ISprite IntroSprite { get; }

IStoryboard Intro { get; }

/// <summary>
/// Manager which wraps character's storyboard ending.
/// </summary>
ICharacterStoryboardSceneManager EndingManager { get; }

/// <summary>
/// Character's storyboard ending sprite.
/// </summary>
ISprite EndingSprite { get; }
IStoryboard Ending { get; }
}

/// <summary>
Expand All @@ -103,9 +94,7 @@ public class Character : FileReadable, ICharacter
public IAnimationManager AnimationManager { get; internal set; }
public ISound Sound { get; internal set; }
public ICharacterAiHints AiHints { get; internal set; }
public ICharacterStoryboardSceneManager IntroManager { get; internal set; }
public ISprite IntroSprite { get; internal set; }
public ICharacterStoryboardSceneManager EndingManager { get; internal set; }
public ISprite EndingSprite { get; internal set; }
public IStoryboard Intro { get; internal set; }
public IStoryboard Ending { get; internal set; }
}
}

This file was deleted.

Loading

0 comments on commit fa9d6e2

Please sign in to comment.