All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.spair.byond.dmi.DmiSprite Maven / Gradle / Ivy

There is a newer version: 2.1
Show newest version
package io.github.spair.byond.dmi;

import lombok.AllArgsConstructor;
import lombok.Data;

import javax.annotation.Nonnull;
import java.awt.image.BufferedImage;
import java.util.Objects;

@Data
@AllArgsConstructor
@SuppressWarnings("WeakerAccess")
public class DmiSprite {

    @Nonnull private BufferedImage sprite;
    @Nonnull private SpriteDir dir;
    private int frameNum;

    @Override
    public String toString() {
        return "DmiSprite{"
                + "sprite=binary-image"
                + ", dir=" + dir
                + ", frameNum=" + frameNum
                + '}';
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DmiSprite sprite1 = (DmiSprite) o;
        return frameNum == sprite1.frameNum
                && dir == sprite1.dir
                && isEqualSprite(sprite1.sprite);
    }

    @Override
    public int hashCode() {
        return Objects.hash(sprite, dir, frameNum);
    }

    private boolean isEqualSprite(final BufferedImage spriteToCompare) {
        if (sprite == spriteToCompare) {
            return true;
        }

        if (sprite.getHeight() != spriteToCompare.getHeight() || sprite.getWidth() != spriteToCompare.getWidth()) {
            return false;
        }

        for (int x = 0; x < sprite.getWidth(); x++) {
            for (int y = 0; y < sprite.getHeight(); y++) {
                if (sprite.getRGB(x, y) != spriteToCompare.getRGB(x, y)) {
                    return false;
                }
            }
        }

        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy