Skip to content

Commit

Permalink
adjusted sprite entry reading logic
Browse files Browse the repository at this point in the history
the builder will now only read and replace sprite entry data when processing spr_ textures. This had to be done because of the new texture replacement system completely negating sprite entry changes
  • Loading branch information
Secre-C committed Nov 21, 2023
1 parent f16de8e commit a98a9c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
19 changes: 7 additions & 12 deletions Emulator/SPD.File.Emulator/Spd/SpdBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ public override unsafe MultiStream Build(IntPtr handle, string filepath, Logger?
_textureData = GetTextureDataFromFile(spdFileSlice);
spdStream.Dispose();

// Write custom sprite entries from '.spdspr' files to sprite dictionary
foreach (var file in CustomSprFiles.Values)
{
using var stream = new FileSliceStreamW32(file);
stream.TryRead(out int spriteId, out _);
stream.Seek(0, SeekOrigin.Begin);

_newSpriteEntries[spriteId] = stream.Read<SpdSpriteEntry>();
}

// Get highest id texture entry
int nextId = _textureEntries.Select(x => x.Key).Max() + 1;

Expand All @@ -77,8 +67,13 @@ public override unsafe MultiStream Build(IntPtr handle, string filepath, Logger?
{
string spriteEntryPath = Path.Combine(Path.GetDirectoryName(key), $"spr_{id}{Constants.SpdSpriteExtension}");

// Use original sprite entry if no accompanying sprite entry file is found
if (!CustomSprFiles.ContainsKey(spriteEntryPath))
// Get accompanying sprite entry if it exists. if not, use original sprite entry data
if (CustomSprFiles.TryGetValue(spriteEntryPath, out var customSprFile))
{
using var stream = new FileSliceStreamW32(customSprFile);
_newSpriteEntries[id] = stream.Read<SpdSpriteEntry>();
}
else
{
if (_spriteEntries.TryGetValue(id, out var value))
{
Expand Down
37 changes: 21 additions & 16 deletions Emulator/SPD.File.Emulator/Spr/SprBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ public override MultiStream Build(nint handle, string filepath, Logger? logger =
sprStream.Dispose();

// Write custom sprite entries from '.sprt' files to sprite dictionary
foreach (var file in CustomSprFiles.Values)
{
using var stream = new FileSliceStreamW32(file);

var fileName = Path.GetFileNameWithoutExtension(file.FilePath.AsSpan());

if (!fileName.StartsWith("spr_", StringComparison.OrdinalIgnoreCase))
continue;

if (int.TryParse(fileName[4..], out int index))
{
_newSpriteEntries[index] = stream.Read<SprSpriteEntry>();
}
}
//foreach (var file in CustomSprFiles.Values)
//{
// using var stream = new FileSliceStreamW32(file);
//
// var fileName = Path.GetFileNameWithoutExtension(file.FilePath.AsSpan());
//
// if (!fileName.StartsWith("spr_", StringComparison.OrdinalIgnoreCase))
// continue;
//
// if (int.TryParse(fileName[4..], out int index))
// {
// _newSpriteEntries[index] = stream.Read<SprSpriteEntry>();
// }
//}

int nextId = _textureData.Count;

Expand All @@ -77,8 +77,13 @@ public override MultiStream Build(nint handle, string filepath, Logger? logger =
{
string spriteEntryPath = Path.Combine(Path.GetDirectoryName(key), $"spr_{id}{Constants.SprSpriteExtension}");

// Use original sprite entry if no accompanying sprite entry file is found
if (!CustomSprFiles.ContainsKey(spriteEntryPath))
// Get accompanying sprite entry if it exists. if not, use original sprite entry data
if (CustomSprFiles.TryGetValue(spriteEntryPath, out var customSprFile))
{
using var stream = new FileSliceStreamW32(customSprFile);
_newSpriteEntries[id] = stream.Read<SprSpriteEntry>();
}
else
{
if (id < _spriteEntries.Count)
{
Expand Down

0 comments on commit a98a9c0

Please sign in to comment.