Skip to content

Commit

Permalink
feat(#5): add equals to texture and cachedtexture
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMountainborn authored Jun 1, 2024
1 parent f27fbf0 commit edd8002
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion ZenKit/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public interface ITexture : ICacheable<ITexture>
[Serializable]
public struct CachedTexture : ITexture
{
internal UIntPtr Handle;
public TextureFormat Format { get; set; }
public int Width { get; set; }
public int Height { get; set; }
Expand Down Expand Up @@ -87,6 +88,20 @@ public int GetHeight(int level)
{
return Height >> level;
}

public override bool Equals(object other)
{
if (other == null || !(other is CachedTexture))
{
return false;
}
return ((CachedTexture)other).Handle == Handle;
}

public override int GetHashCode()
{
return (int)Handle;
}
}

public class Texture : ITexture
Expand Down Expand Up @@ -185,7 +200,8 @@ public ITexture Cache()
AverageColor = AverageColor,
Palette = Palette,
AllMipmapsRgba = AllMipmapsRgba,
AllMipmapsRaw = AllMipmapsRaw
AllMipmapsRaw = AllMipmapsRaw,
Handle = Handle
};
}

Expand Down Expand Up @@ -220,6 +236,20 @@ public int GetHeight(int level)
{
if (_delete) Native.ZkTexture_del(Handle);
}

public override bool Equals(object other)
{
if (other == null || !(other is Texture))
{
return false;
}
return ((Texture)other).Handle == Handle;
}

public override int GetHashCode()
{
return (int)Handle;
}
}

public class TextureBuilder
Expand Down

0 comments on commit edd8002

Please sign in to comment.