Skip to content

Commit

Permalink
Add character sprite items (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Feb 2, 2023
1 parent b5aa5b1 commit 77cdf59
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
29 changes: 25 additions & 4 deletions src/SerialLoops.Lib/Items/CharacterSpriteItem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
using System;
using HaruhiChokuretsuLib.Archive.Data;
using SkiaSharp;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Items
{
internal class CharacterSpriteItem
public class CharacterSpriteItem : Item
{
public CharacterSprite Sprite { get; set; }

public CharacterSpriteItem(CharacterSprite sprite) : base($"SPR_{sprite.Character}_{sprite.MouthAnimationIndex}_{sprite.EyeAnimationIndex}", ItemType.Character_Sprite)
{
Sprite = sprite;
}

public override void Refresh(Project project)
{
}

public List<(SKBitmap frame, int timing)> GetClosedMouthAnimation(Project project)
{
MessageInfoFile messageInfo = project.Dat.Files.First(f => f.Name == "MESSINFOS").CastTo<MessageInfoFile>();
return Sprite.GetClosedMouthAnimation(project.Grp, messageInfo);
}

public List<(SKBitmap frame, int timing)> GetLipFlapAnimation(Project project)
{
MessageInfoFile messageInfo = project.Dat.Files.First(f => f.Name == "MESSINFOS").CastTo<MessageInfoFile>();
return Sprite.GetLipFlapAnimation(project.Grp, messageInfo);
}
}
}
3 changes: 3 additions & 0 deletions src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public void LoadArchives(ILogger log)
Items.Add(new BackgroundItem(name, i, entry, Evt, Grp));
}
}
Items.AddRange(Dat.Files.First(d => d.Name == "CHRDATAS").CastTo<CharacterDataFile>()
.Sprites.Where(s => (int)s.Character > 0)
.Select(s => new CharacterSpriteItem(s)));
Items.AddRange(Dat.Files.First(d => d.Name == "CHIBIS").CastTo<ChibiFile>()
.Chibis.Select(c => new ChibiItem(c, this)));
Items.AddRange(Evt.Files
Expand Down
2 changes: 2 additions & 0 deletions src/SerialLoops/Controls/EditorTabsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ internal static DocumentPage CreateTab(ItemDescription item, Project project, IL
{
case ItemDescription.ItemType.Background:
return new BackgroundEditor((BackgroundItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Character_Sprite:
return new CharacterSpriteEditor((CharacterSpriteItem)project.Items.First(i => i.Name == item.Name), project, log);
case ItemDescription.ItemType.Chibi:
return new ChibiEditor((ChibiItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Map:
Expand Down
33 changes: 33 additions & 0 deletions src/SerialLoops/Editors/CharacterSpriteEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using SerialLoops.Utility;

namespace SerialLoops.Editors
{
public class CharacterSpriteEditor : Editor
{
private CharacterSpriteItem _sprite;
private AnimatedImage _animatedImage;

public CharacterSpriteEditor(CharacterSpriteItem item, Project project, ILogger log) : base(item, log, project)
{
}

public override Panel GetEditorPanel()
{
_sprite = (CharacterSpriteItem)Description;
_animatedImage = new AnimatedImage(_sprite.GetLipFlapAnimation(_project));
_animatedImage.Play();

return new StackLayout
{
Items =
{
_animatedImage
},
};
}
}
}
7 changes: 5 additions & 2 deletions src/SerialLoops/Editors/Editor.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Controls;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using System;

namespace SerialLoops.Editors
{
public abstract class Editor : DocumentPage
{
private ILogger _log;
protected ILogger _log;
protected Project _project;
public ItemDescription Description { get; private set; }

public Editor(ItemDescription description, ILogger log)
public Editor(ItemDescription description, ILogger log, Project project = null)
{
Description = description;
_project = project;
_log = log;
InitializeComponent();
}
Expand Down

0 comments on commit 77cdf59

Please sign in to comment.