Skip to content

Commit

Permalink
Spr block type #124
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed Feb 28, 2024
1 parent 62013ec commit cc5d3c7
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 13 deletions.
1 change: 1 addition & 0 deletions FreeMote.Psb/FreeMote.Psb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="Textures\TextureCombiner.cs" />
<Compile Include="Textures\TexturePacker.cs" />
<Compile Include="Textures\TextureSpliter.cs" />
<Compile Include="Types\SprBlockType.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FreeMote\FreeMote.csproj">
Expand Down
3 changes: 2 additions & 1 deletion FreeMote.Psb/IPsbType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IPsbType
/// <param name="psb"></param>
/// <param name="deDuplication"></param>
/// <returns></returns>
List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T: IResourceMetadata;
List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T: class, IResourceMetadata;

/// <summary>
/// Link
Expand Down Expand Up @@ -84,6 +84,7 @@ public partial class PSB
{PsbType.SoundArchive, new SoundArchiveType()},
{PsbType.BmpFont, new FontType()},
{PsbType.Map, new MapType()},
{PsbType.SprBlock, new SprBlockType()},
{PsbType.PSB, new MotionType()}, //assume as motion type by default, must put this after Motion
};

Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/PsbResHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static byte[] TryToWave(this IArchData archData, AudioMetadata metadata,
/// <param name="psb"></param>
/// <param name="deDuplication">if true, we focus on raw Resource itself, not for PSB structure</param>
/// <returns></returns>
public static List<T> CollectResources<T>(this PSB psb, bool deDuplication = true) where T : IResourceMetadata
public static List<T> CollectResources<T>(this PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
List<T> resourceList;
if (psb.TypeHandler != null)
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/ArchiveType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public bool IsThisType(PSB psb)
return psb.TypeId == "archive" || (psb.TypeId == "scenario" && psb.Objects.ContainsKey("file_info")); //&& psb.Objects.ContainsKey("file_info")
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
return new List<T>();
}
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/FontType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public bool IsThisType(PSB psb)
return psb.TypeId == "font"; //&& psb.Objects.ContainsKey("code");
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
//List<T> resourceList = psb.Resources == null
// ? new List<T>()
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/ImageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override Dictionary<string, string> OutputResources(PSB psb, FreeMountCon
return base.OutputResources(psb, context, name, dirPath, extractOption);
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
List<T> resourceList = psb.Resources == null
? new List<T>()
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/MapType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public bool IsThisType(PSB psb)
return psb.TypeId == "map";
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
var resourceList = FindTileResources(psb, deDuplication).Cast<T>().ToList();

Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/MmoType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public bool IsThisType(PSB psb)
return psb.Objects.ContainsKey("objectChildren") && psb.Objects.ContainsKey("sourceChildren");
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
List<T> resourceList = psb.Resources == null
? new List<T>()
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/MotionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public bool IsThisType(PSB psb)
return psb.TypeId == "motion";
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
List<T> resourceList = psb.Resources == null
? new List<T>()
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/PimgType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public bool IsThisType(PSB psb)
return false;
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
List<T> resourceList = psb.Resources == null
? new List<T>()
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/ScnType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public bool IsThisType(PSB psb)
return false;
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
List<T> resourceList = psb.Resources == null
? new List<T>()
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Psb/Types/SoundArchiveType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public bool IsThisType(PSB psb)
return psb.TypeId == "sound_archive";
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : IResourceMetadata
public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
List<T> resourceList = psb.Resources == null
? new List<T>()
Expand Down
34 changes: 34 additions & 0 deletions FreeMote.Psb/Types/SprBlockType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;

namespace FreeMote.Psb.Types
{
class SprBlockType : BaseImageType, IPsbType
{
public PsbType PsbType => PsbType.SprBlock;
public bool IsThisType(PSB psb)
{
return psb.Objects != null && psb.Objects.Count == 3 && psb.Objects.ContainsKey("w") && psb.Objects.ContainsKey("h") && psb.Objects.ContainsKey("image");
}

public List<T> CollectResources<T>(PSB psb, bool deDuplication = true) where T : class, IResourceMetadata
{
//8bit (1 byte 1 pixel)
if (psb.Objects["image"] is PsbResource res)
{
ImageMetadata md = new ImageMetadata()
{
PsbType = PsbType,
Resource = res,
Width = psb.Objects["w"].GetInt(),
Height = psb.Objects["h"].GetInt(),
Spec = PsbSpec.none,
TypeString = PsbPixelFormat.A8.ToStringForPsb().ToPsbString()
};
return [md as T];
}

return new List<T>();
}
}
}
11 changes: 11 additions & 0 deletions FreeMote.Tests/PsBuildTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,17 @@ public void TestPackArchive()
PsbDecompiler.ExtractArchive("patch_info.psb.m", "523aad2de7132", FreeMountContext.CreateForArchive(), null, false, false, true);
}

[TestMethod]
public void TestSpr()
{
FreeMount.Init();
var resPath = Path.Combine(Environment.CurrentDirectory, @"..\..\Res");
var path = Path.Combine(resPath, "Spr", "1P000.psb");

var psb = new PSB(path);
PsbDecompiler.DecompileToFile(path, extractFormat: PsbImageFormat.png, extractOption: PsbExtractOption.Extract);
}

public static bool CompareValue(IPsbValue p1, IPsbValue p2)
{
//if (p1.Type != p2.Type && !(p1 is PsbString))
Expand Down
8 changes: 6 additions & 2 deletions FreeMote/PsbEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public enum PsbType
/// Tile Map
/// </summary>
Map = 9,
/// <summary>
/// Sprite Block
/// </summary>
SprBlock = 10,
}

/// <summary>
Expand Down Expand Up @@ -193,11 +197,11 @@ public enum PsbPixelFormat
/// </summary>
A8L8,
/// <summary>
/// L8
/// L8 (L = Lightness)
/// </summary>
L8,
/// <summary>
/// A8
/// A8 (A = Alpha)
/// </summary>
A8,

Expand Down

0 comments on commit cc5d3c7

Please sign in to comment.