Skip to content

Commit

Permalink
Created abstractions for data classes
Browse files Browse the repository at this point in the history
  • Loading branch information
notscuffed committed Jan 14, 2020
1 parent f6f3bda commit e143374
Show file tree
Hide file tree
Showing 45 changed files with 186 additions and 78 deletions.
2 changes: 1 addition & 1 deletion RePKG.Application/Texture/TexFrameInfoContainerReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RePKG.Application.Texture
{
public class TexFrameInfoContainerReader : ITexFrameInfoContainerReader
{
public TexFrameInfoContainer ReadFrom(BinaryReader reader)
public ITexFrameInfoContainer ReadFrom(BinaryReader reader)
{
if (reader == null) throw new ArgumentNullException(nameof(reader));

Expand Down
2 changes: 1 addition & 1 deletion RePKG.Application/Texture/TexHeaderReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RePKG.Application.Texture
{
public class TexHeaderReader : ITexHeaderReader
{
public TexHeader ReadFrom(BinaryReader reader)
public ITexHeader ReadFrom(BinaryReader reader)
{
if (reader == null) throw new ArgumentNullException(nameof(reader));

Expand Down
2 changes: 1 addition & 1 deletion RePKG.Application/Texture/TexImageContainerReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public TexImageContainerReader(ITexImageReader texImageReader)
_texImageReader = texImageReader;
}

public TexImageContainer ReadFrom(BinaryReader reader, TexFormat texFormat)
public ITexImageContainer ReadFrom(BinaryReader reader, TexFormat texFormat)
{
if (reader == null) throw new ArgumentNullException(nameof(reader));

Expand Down
4 changes: 2 additions & 2 deletions RePKG.Application/Texture/TexImageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public TexImageReader(ITexMipmapDecompressor texMipmapDecompressor)
_texMipmapDecompressor = texMipmapDecompressor;
}

public TexImage ReadFrom(
public ITexImage ReadFrom(
BinaryReader reader,
TexImageContainer container,
ITexImageContainer container,
TexFormat texFormat)
{
if (reader == null) throw new ArgumentNullException(nameof(reader));
Expand Down
2 changes: 1 addition & 1 deletion RePKG.Application/Texture/TexJsonInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RePKG.Application.Texture
{
public class TexJsonInfoGenerator : ITexJsonInfoGenerator
{
public string GenerateInfo(Tex tex)
public string GenerateInfo(ITex tex)
{
if (tex == null) throw new ArgumentNullException(nameof(tex));

Expand Down
2 changes: 1 addition & 1 deletion RePKG.Application/Texture/TexMipmapDecompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RePKG.Application.Texture
{
public class TexMipmapDecompressor : ITexMipmapDecompressor
{
public void DecompressMipmap(TexMipmap mipmap)
public void DecompressMipmap(ITexMipmap mipmap)
{
if (mipmap == null) throw new ArgumentNullException(nameof(mipmap));

Expand Down
18 changes: 16 additions & 2 deletions RePKG.Application/Texture/TexReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,24 @@ public TexReader(
_texFrameInfoContainerReader = texFrameInfoContainerReader;
}

public Tex ReadFrom(BinaryReader reader)
public static TexReader Default
{
get
{
var headerReader = new TexHeaderReader();
var mipmapDecompressor = new TexMipmapDecompressor();
var mipmapReader = new TexImageReader(mipmapDecompressor);
var containerReader = new TexImageContainerReader(mipmapReader);
var frameInfoReader = new TexFrameInfoContainerReader();

return new TexReader(headerReader, containerReader, frameInfoReader);
}
}

public ITex ReadFrom(BinaryReader reader)
{
if (reader == null) throw new ArgumentNullException(nameof(reader));

var tex = new Tex {Magic1 = reader.ReadNString(maxLength: 16)};

if (tex.Magic1 != "TEXV0005")
Expand Down
6 changes: 3 additions & 3 deletions RePKG.Application/Texture/TexToImageConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace RePKG.Application.Texture
{
public class TexToImageConverter
{
public ImageResult ConvertToImage(Tex tex)
public ImageResult ConvertToImage(ITex tex)
{
if (tex == null) throw new ArgumentNullException(nameof(tex));

Expand Down Expand Up @@ -52,7 +52,7 @@ public ImageResult ConvertToImage(Tex tex)
};
}

public MipmapFormat GetConvertedFormat(Tex tex)
public MipmapFormat GetConvertedFormat(ITex tex)
{
if (tex == null) throw new ArgumentNullException(nameof(tex));

Expand All @@ -67,7 +67,7 @@ public MipmapFormat GetConvertedFormat(Tex tex)
return format.IsRawFormat() ? MipmapFormat.ImagePNG : format;
}

private static ImageResult ConvertToGif(Tex tex)
private static ImageResult ConvertToGif(ITex tex)
{
var frameFormat = tex.FirstImage.FirstMipmap.Format;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RePKG.Application.Texture
{
public class TexFrameInfoContainerWriter : ITexFrameInfoContainerWriter
{
public void WriteTo(BinaryWriter writer, TexFrameInfoContainer frameInfoContainer)
public void WriteTo(BinaryWriter writer, ITexFrameInfoContainer frameInfoContainer)
{
if (writer == null) throw new ArgumentNullException(nameof(writer));
if (frameInfoContainer == null) throw new ArgumentNullException(nameof(frameInfoContainer));
Expand All @@ -30,20 +30,20 @@ public void WriteTo(BinaryWriter writer, TexFrameInfoContainer frameInfoContaine
}
}

private static void WriteV2(TexFrameInfoContainer container, BinaryWriter writer)
private static void WriteV2(ITexFrameInfoContainer container, BinaryWriter writer)
{
WriteFrames(container, writer);
}

private static void WriteV3(TexFrameInfoContainer container, BinaryWriter writer)
private static void WriteV3(ITexFrameInfoContainer container, BinaryWriter writer)
{
writer.Write(container.GifWidth);
writer.Write(container.GifHeight);

WriteFrames(container, writer);
}

private static void WriteFrames(TexFrameInfoContainer container, BinaryWriter writer)
private static void WriteFrames(ITexFrameInfoContainer container, BinaryWriter writer)
{
foreach (var frame in container.Frames)
{
Expand Down
2 changes: 1 addition & 1 deletion RePKG.Application/Texture/Writer/TexHeaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace RePKG.Application.Texture
{
public class TexHeaderWriter : ITexHeaderWriter
{
public void WriteTo(BinaryWriter writer, TexHeader header)
public void WriteTo(BinaryWriter writer, ITexHeader header)
{
if (writer == null) throw new ArgumentNullException(nameof(writer));
if (header == null) throw new ArgumentNullException(nameof(header));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public TexImageContainerWriter(ITexImageWriter texImageWriter)
_texImageWriter = texImageWriter;
}

public void WriteTo(BinaryWriter writer, TexImageContainer imageContainer)
public void WriteTo(BinaryWriter writer, ITexImageContainer imageContainer)
{
if (writer == null) throw new ArgumentNullException(nameof(writer));
if (imageContainer == null) throw new ArgumentNullException(nameof(imageContainer));
Expand Down
24 changes: 16 additions & 8 deletions RePKG.Application/Texture/Writer/TexImageWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace RePKG.Application.Texture
{
public class TexImageWriter : ITexImageWriter
{
public void WriteTo(BinaryWriter writer, TexImageContainerVersion containerVersion, TexImage image)
public void WriteTo(BinaryWriter writer, TexImageContainerVersion containerVersion, ITexImage image)
{
if (writer == null) throw new ArgumentNullException(nameof(writer));
if (image == null) throw new ArgumentNullException(nameof(image));
Expand All @@ -21,29 +21,37 @@ public void WriteTo(BinaryWriter writer, TexImageContainerVersion containerVersi
}
}

private static void WriteMipmapV1(BinaryWriter writer, TexMipmap mipmap)
private static void WriteMipmapV1(BinaryWriter writer, ITexMipmap mipmap)
{
if (mipmap.IsLZ4Compressed)
throw new InvalidOperationException(
$"Cannot write lz4 compressed mipmap when using tex container version: {TexImageContainerVersion.Version1}");

writer.Write(mipmap.Width);
writer.Write(mipmap.Height);
writer.Write(mipmap.Bytes.Length);
writer.Write(mipmap.Bytes);

using (var stream = mipmap.GetBytesStream())
{
writer.Write(stream.Length);
stream.CopyTo(stream);
}
}

private static void WriteMipmapV2And3(BinaryWriter writer, TexMipmap mipmap)
private static void WriteMipmapV2And3(BinaryWriter writer, ITexMipmap mipmap)
{
writer.Write(mipmap.Width);
writer.Write(mipmap.Height);
writer.Write(mipmap.IsLZ4Compressed ? 1 : 0);
writer.Write(mipmap.DecompressedBytesCount);
writer.Write(mipmap.Bytes.Length);
writer.Write(mipmap.Bytes);

using (var stream = mipmap.GetBytesStream())
{
writer.Write(stream.Length);
stream.CopyTo(stream);
}
}

private static Action<BinaryWriter, TexMipmap> PickMipmapWriter(TexImageContainerVersion containerVersion)
private static Action<BinaryWriter, ITexMipmap> PickMipmapWriter(TexImageContainerVersion containerVersion)
{
switch (containerVersion)
{
Expand Down
4 changes: 2 additions & 2 deletions RePKG.Application/Texture/Writer/TexMipmapCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RePKG.Application.Texture
public class TexMipmapCompressor : ITexMipmapCompressor
{
public void CompressMipmap(
TexMipmap mipmap,
ITexMipmap mipmap,
MipmapFormat targetCompressFormat,
bool lz4Compress)
{
Expand All @@ -20,7 +20,7 @@ public void CompressMipmap(
if (lz4Compress) LZ4Compress(mipmap);
}

private static void LZ4Compress(TexMipmap mipmap)
private static void LZ4Compress(ITexMipmap mipmap)
{
var bytes = mipmap.Bytes;
var maximumSize = LZ4Codec.MaximumOutputSize(bytes.Length);
Expand Down
2 changes: 1 addition & 1 deletion RePKG.Application/Texture/Writer/TexWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TexWriter(
_texFrameInfoContainerWriter = texFrameInfoContainerWriter;
}

public void WriteTo(BinaryWriter writer, Tex tex)
public void WriteTo(BinaryWriter writer, ITex tex)
{
if (writer == null) throw new ArgumentNullException(nameof(writer));
if (tex == null) throw new ArgumentNullException(nameof(tex));
Expand Down
1 change: 1 addition & 0 deletions RePKG.Core/RePKG.Core.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=texture_005Cenums/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=texture_005Chelpers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=texture_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=texture_005Cinterfaces_005Cdata/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=texture_005Cinterfaces_005Cwriter/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
16 changes: 16 additions & 0 deletions RePKG.Core/Texture/Interfaces/Data/ITex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace RePKG.Core.Texture
{
public interface ITex
{
string Magic1 { get; set; }
string Magic2 { get; set; }
ITexHeader Header { get; set; }
ITexImageContainer ImagesContainer { get; set; }
ITexFrameInfoContainer FrameInfoContainer { get; set; }

bool IsGif { get; }
ITexImage FirstImage { get; }

bool HasFlag(TexFlags flag);
}
}
14 changes: 14 additions & 0 deletions RePKG.Core/Texture/Interfaces/Data/ITexFrameInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace RePKG.Core.Texture
{
public interface ITexFrameInfo
{
int ImageId { get; set; }
float Frametime { get; set; }
float X { get; set; }
float Y { get; set; }
float Width { get; set; }
float Unk0 { get; set; }
float Unk1 { get; set; }
float Height { get; set; }
}
}
12 changes: 12 additions & 0 deletions RePKG.Core/Texture/Interfaces/Data/ITexFrameInfoContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace RePKG.Core.Texture
{
public interface ITexFrameInfoContainer
{
string Magic { get; set; }
IList<ITexFrameInfo> Frames { get; }
int GifWidth { get; set; }
int GifHeight { get; set; }
}
}
13 changes: 13 additions & 0 deletions RePKG.Core/Texture/Interfaces/Data/ITexHeader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace RePKG.Core.Texture
{
public interface ITexHeader
{
TexFormat Format { get; set; }
TexFlags Flags { get; set; }
int TextureWidth { get; set; }
int TextureHeight { get; set; }
int ImageWidth { get; set; }
int ImageHeight { get; set; }
uint UnkInt0 { get; set; }
}
}
10 changes: 10 additions & 0 deletions RePKG.Core/Texture/Interfaces/Data/ITexImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace RePKG.Core.Texture
{
public interface ITexImage
{
IList<ITexMipmap> Mipmaps { get; }
ITexMipmap FirstMipmap { get; }
};
}
12 changes: 12 additions & 0 deletions RePKG.Core/Texture/Interfaces/Data/ITexImageContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace RePKG.Core.Texture
{
public interface ITexImageContainer
{
string Magic { get; set; }
FreeImageFormat ImageFormat { get; set; }
IList<ITexImage> Images { get; }
TexImageContainerVersion ImageContainerVersion { get; set; }
}
}
16 changes: 16 additions & 0 deletions RePKG.Core/Texture/Interfaces/Data/ITexMipmap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.IO;

namespace RePKG.Core.Texture
{
public interface ITexMipmap
{
byte[] Bytes { get; set; }
int Width { get; set; }
int Height { get; set; }
int DecompressedBytesCount { get; set; }
bool IsLZ4Compressed { get; set; }
MipmapFormat Format { get; set; }

Stream GetBytesStream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace RePKG.Core.Texture
{
public interface ITexFrameInfoContainerReader
{
TexFrameInfoContainer ReadFrom(BinaryReader reader);
ITexFrameInfoContainer ReadFrom(BinaryReader reader);
}
}
2 changes: 1 addition & 1 deletion RePKG.Core/Texture/Interfaces/ITexHeaderReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace RePKG.Core.Texture
{
public interface ITexHeaderReader
{
TexHeader ReadFrom(BinaryReader reader);
ITexHeader ReadFrom(BinaryReader reader);
}
}
2 changes: 1 addition & 1 deletion RePKG.Core/Texture/Interfaces/ITexImageContainerReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace RePKG.Core.Texture
{
public interface ITexImageContainerReader
{
TexImageContainer ReadFrom(BinaryReader reader, TexFormat texFormat);
ITexImageContainer ReadFrom(BinaryReader reader, TexFormat texFormat);
}
}
4 changes: 2 additions & 2 deletions RePKG.Core/Texture/Interfaces/ITexImageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace RePKG.Core.Texture
{
public interface ITexImageReader
{
TexImage ReadFrom(
ITexImage ReadFrom(
BinaryReader reader,
TexImageContainer container,
ITexImageContainer container,
TexFormat texFormat);
}
}
Loading

0 comments on commit e143374

Please sign in to comment.