Skip to content

Commit

Permalink
Fix on animation opening for some Sonic Mania animations
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeeynamo committed Sep 3, 2017
1 parent 7df5330 commit db23dd6
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 182 deletions.
12 changes: 6 additions & 6 deletions AnimationEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,27 @@

<TextBlock Grid.Column="0" Grid.Row="1" Text="Left"/>
<xc:NumericUpDown Grid.Column="1" Grid.Row="1"
MinimumValue="0" MaximumValue="255"
MinimumValue="0" MaximumValue="32767"
Value="{Binding SelectedFrameLeft, Mode=TwoWay}"/>
<TextBlock Grid.Column="3" Grid.Row="1" Text="Top"/>
<xc:NumericUpDown Grid.Column="4" Grid.Row="1"
MinimumValue="0" MaximumValue="255"
MinimumValue="0" MaximumValue="32767"
Value="{Binding SelectedFrameTop, Mode=TwoWay}"/>
<TextBlock Grid.Column="0" Grid.Row="3" Text="Width"/>
<xc:NumericUpDown Grid.Column="1" Grid.Row="3"
MinimumValue="0" MaximumValue="255"
MinimumValue="0" MaximumValue="32767"
Value="{Binding SelectedFrameWidth, Mode=TwoWay}"/>
<TextBlock Grid.Column="3" Grid.Row="3" Text="Height"/>
<xc:NumericUpDown Grid.Column="4" Grid.Row="3"
MinimumValue="0" MaximumValue="255"
MinimumValue="0" MaximumValue="32767"
Value="{Binding SelectedFrameHeight, Mode=TwoWay}"/>
<TextBlock Grid.Column="0" Grid.Row="5" Text="PivotX"/>
<xc:NumericUpDown Grid.Column="1" Grid.Row="5"
MinimumValue="-128" MaximumValue="127"
MinimumValue="-32768" MaximumValue="32767"
Value="{Binding SelectedFramePivotX, Mode=TwoWay}"/>
<TextBlock Grid.Column="3" Grid.Row="5" Text="PivotY"/>
<xc:NumericUpDown Grid.Column="4" Grid.Row="5"
MinimumValue="-128" MaximumValue="127"
MinimumValue="-32768" MaximumValue="32767"
Value="{Binding SelectedFramePivotY, Mode=TwoWay}"/>
</Grid>
</StackPanel>
Expand Down
2 changes: 1 addition & 1 deletion AnimationEditor/ViewModels/HitboxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace AnimationEditor.ViewModels
{
public class HitboxViewModel
{
public Hitbox Hitbox { get; set; }
public IHitbox Hitbox { get; set; }

public override string ToString()
{
Expand Down
2 changes: 1 addition & 1 deletion AnimationEditor/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public IAnimation AnimationData

Textures = new ObservableCollection<string>(_animationData.SpriteSheets);
Animations = new ObservableCollection<IAnimationEntry>(_animationData.GetAnimations());
Hitboxes = _animationData.GetHitboxes().Select(x => new HitboxViewModel() { Hitbox = x.Floor }).ToList() ?? new List<HitboxViewModel>();
Hitboxes = _animationData.GetHitboxes()?.Select(x => new HitboxViewModel() { Hitbox = x.Floor }).ToList() ?? new List<HitboxViewModel>();
_animService = new AnimationService(_animationData);
_animService.OnFrameChanged += OnFrameChanged;
_spriteService = new SpriteService(_animationData, basePath);
Expand Down
45 changes: 8 additions & 37 deletions RSDK/IAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,6 @@

namespace RSDK
{
public class Hitbox
{
public int Left { get; set; }

public int Top { get; set; }

public int Right { get; set; }

public int Bottom { get; set; }

public Hitbox() { }

public Hitbox(BinaryReader reader)
{
Left = reader.ReadSByte();
Top = reader.ReadSByte();
Right = reader.ReadSByte();
Bottom = reader.ReadSByte();
}

public void SaveChanges(BinaryWriter writer)
{
writer.Write((sbyte)Left);
writer.Write((sbyte)Top);
writer.Write((sbyte)Right);
writer.Write((sbyte)Bottom);
}
}

public interface IFrame
{
int SpriteSheet { get; set; }
Expand Down Expand Up @@ -94,14 +65,14 @@ public interface IAnimationEntry

public interface IHitboxEntry
{
Hitbox Floor { get; set; }
Hitbox Ceiling { get; set; }
Hitbox WallLeft { get; set; }
Hitbox WallRight { get; set; }
Hitbox Unk04 { get; set; }
Hitbox Unk05 { get; set; }
Hitbox Unk06 { get; set; }
Hitbox Unk07 { get; set; }
IHitbox Floor { get; set; }
IHitbox Ceiling { get; set; }
IHitbox WallLeft { get; set; }
IHitbox WallRight { get; set; }
IHitbox Unk04 { get; set; }
IHitbox Unk05 { get; set; }
IHitbox Unk06 { get; set; }
IHitbox Unk07 { get; set; }
}

public interface IAnimation
Expand Down
17 changes: 17 additions & 0 deletions RSDK/IHitbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.IO;

namespace RSDK
{
public interface IHitbox
{
int Left { get; set; }

int Top { get; set; }

int Right { get; set; }

int Bottom { get; set; }

void SaveChanges(BinaryWriter writer);
}
}
1 change: 1 addition & 0 deletions RSDK/RSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="IAnimation.cs" />
<Compile Include="IHitbox.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringEncoding.cs" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions RSDK/StringEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static string GetString(BinaryReader reader)
public static string GetString(byte[] data)
{
int length = data.Length;
if (length == 0)
return string.Empty;
if (data[length - 1] == '\0')
length--;
return Encoding.UTF8.GetString(data, 0, length);
Expand Down
16 changes: 8 additions & 8 deletions RSDK3/Animation.HitboxEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ namespace RSDK3
{
public class HitboxEntry : IHitboxEntry
{
public Hitbox Floor { get; set; }
public Hitbox Ceiling { get; set; }
public Hitbox WallLeft { get; set; }
public Hitbox WallRight { get; set; }
public Hitbox Unk04 { get; set; }
public Hitbox Unk05 { get; set; }
public Hitbox Unk06 { get; set; }
public Hitbox Unk07 { get; set; }
public IHitbox Floor { get; set; }
public IHitbox Ceiling { get; set; }
public IHitbox WallLeft { get; set; }
public IHitbox WallRight { get; set; }
public IHitbox Unk04 { get; set; }
public IHitbox Unk05 { get; set; }
public IHitbox Unk06 { get; set; }
public IHitbox Unk07 { get; set; }

public HitboxEntry()
{
Expand Down
34 changes: 34 additions & 0 deletions RSDK3/Hitbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using RSDK;
using System.IO;

namespace RSDK3
{
public class Hitbox : IHitbox
{
public int Left { get; set; }

public int Top { get; set; }

public int Right { get; set; }

public int Bottom { get; set; }

public Hitbox() { }

public Hitbox(BinaryReader reader)
{
Left = reader.ReadSByte();
Top = reader.ReadSByte();
Right = reader.ReadSByte();
Bottom = reader.ReadSByte();
}

public void SaveChanges(BinaryWriter writer)
{
writer.Write((sbyte)Left);
writer.Write((sbyte)Top);
writer.Write((sbyte)Right);
writer.Write((sbyte)Bottom);
}
}
}
1 change: 1 addition & 0 deletions RSDK3/RSDK3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Compile Include="Animation.AnimationEntry.cs" />
<Compile Include="Animation.cs" />
<Compile Include="Animation.Frame.cs" />
<Compile Include="Hitbox.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
17 changes: 6 additions & 11 deletions RSDK5/Animation.AnimationEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AnimationEntry()
{
}

public AnimationEntry(BinaryReader reader)
public AnimationEntry(BinaryReader reader, int collisionBoxesCount)
{
Name = StringEncoding.GetString(reader);

Expand All @@ -53,7 +53,7 @@ public AnimationEntry(BinaryReader reader)
Flags = 0;
for (int i = 0; i < framesCount; i++)
{
Frames.Add(new Frame()
var frame = new Frame(collisionBoxesCount)
{
SpriteSheet = reader.ReadByte(),
CollisionBox = 0,
Expand All @@ -65,15 +65,10 @@ public AnimationEntry(BinaryReader reader)
Height = reader.ReadInt16(),
CenterX = reader.ReadInt16(),
CenterY = reader.ReadInt16(),
HitboxLeft = reader.ReadInt16(),
HitboxTop = reader.ReadInt16(),
HitboxRight = reader.ReadInt16(),
HitboxBottom = reader.ReadInt16(),
Hitbox2Left = reader.ReadInt16(),
Hitbox2Top = reader.ReadInt16(),
Hitbox2Right = reader.ReadInt16(),
Hitbox2Bottom = reader.ReadInt16(),
});
};
for (int j = 0; j < collisionBoxesCount; j++)
frame.Hitboxes[j] = new Hitbox(reader);
Frames.Add(frame);
}
}

Expand Down
21 changes: 6 additions & 15 deletions RSDK5/Animation.Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,11 @@ public class Frame : IFrame

public int CenterY { get; set; }

public int HitboxLeft { get; set; }

public int HitboxTop { get; set; }

public int HitboxRight { get; set; }

public int HitboxBottom { get; set; }

public int Hitbox2Left { get; set; }

public int Hitbox2Top { get; set; }

public int Hitbox2Right { get; set; }

public int Hitbox2Bottom { get; set; }
public Hitbox[] Hitboxes { get; set; }

public Frame(int hitboxesCount = 0)
{
Hitboxes = new Hitbox[hitboxesCount];
}
}
}
75 changes: 0 additions & 75 deletions RSDK5/Animation.HitboxEntry.cs

This file was deleted.

Loading

0 comments on commit db23dd6

Please sign in to comment.