<commit_before>package pl.shockah.godwit.gl;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import lombok.experimental.Delegate;
import pl.shockah.godwit.Godwit;
import pl.shockah.godwit.fx.Animatable;
import pl.shockah.godwit.fx.Animatables;
import pl.shockah.godwit.geom.IVec2;
import pl.shockah.godwit.geom.MutableVec2;
import pl.shockah.godwit.geom.Vec2;

public class GfxSprite implements Renderable, Animatable<GfxSprite> {
	private interface DelegateExclusions {
		float getRotation();
		void setRotation(float rotation);
		void rotate(float degrees);
		void setFlip(boolean x, boolean y);
		boolean isFlipY();
		void setRegion(Texture texture);
		void setRegion(TextureRegion region);
		void setRegion(int x, int y, int width, int height);
		void setRegion(float u, float v, float u2, float v2);
		void setRegion(TextureRegion region, int x, int y, int width, int height);
	}

	@Delegate(excludes = DelegateExclusions.class)
	@Nonnull public final Sprite sprite;

	@Nonnull public MutableVec2 offset = new MutableVec2();

	@Nullable private Animatables.Properties<GfxSprite> animatableProperties;

	public GfxSprite(@Nonnull Sprite sprite) {
		this.sprite = sprite;
		fixFlip();
	}

	private void fixFlip() {
		if (Godwit.getInstance().yPointingDown)
			sprite.setFlip(sprite.isFlipX(), !sprite.isFlipY());
	}

	@Override
	public void render(@Nonnull Gfx gfx, @Nonnull IVec2 v) {
		if (!gfx.getBoundingBox().collides(v.x() - offset.x, v.y() - offset.y, getWidth() * sprite.getScaleX(), getHeight() * sprite.getScaleY()))
			return;

		float oldX = sprite.getX();
		float oldY = sprite.getY();

		sprite.translate(v.x() - offset.x, v.y() - offset.y);
		gfx.prepareSprites();
		sprite.draw(gfx.getSpriteBatch());

		sprite.setPosition(oldX, oldY);
	}

	public final void center() {
		setOriginCenter();
		offset = (getSize() * 0.5f).getMutableCopy();
	}

	public @Nonnull IVec2 getOrigin() {
		return new Vec2(sprite.getOriginX(), sprite.getOriginY());<commit_msg>Revert "Revert "Only translating GfxSprite if needed""<commit_after>package pl.shockah.godwit.gl;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import lombok.experimental.Delegate;
import pl.shockah.godwit.Godwit;
import pl.shockah.godwit.fx.Animatable;
import pl.shockah.godwit.fx.Animatables;
import pl.shockah.godwit.geom.IVec2;
import pl.shockah.godwit.geom.MutableVec2;
import pl.shockah.godwit.geom.Vec2;

public class GfxSprite implements Renderable, Animatable<GfxSprite> {
	private interface DelegateExclusions {
		float getRotation();
		void setRotation(float rotation);
		void rotate(float degrees);
		void setFlip(boolean x, boolean y);
		boolean isFlipY();
		void setRegion(Texture texture);
		void setRegion(TextureRegion region);
		void setRegion(int x, int y, int width, int height);
		void setRegion(float u, float v, float u2, float v2);
		void setRegion(TextureRegion region, int x, int y, int width, int height);
	}

	@Delegate(excludes = DelegateExclusions.class)
	@Nonnull public final Sprite sprite;

	@Nonnull public MutableVec2 offset = new MutableVec2();

	@Nullable private Animatables.Properties<GfxSprite> animatableProperties;

	public GfxSprite(@Nonnull Sprite sprite) {
		this.sprite = sprite;
		fixFlip();
	}

	private void fixFlip() {
		if (Godwit.getInstance().yPointingDown)
			sprite.setFlip(sprite.isFlipX(), !sprite.isFlipY());
	}

	@Override
	public void render(@Nonnull Gfx gfx, @Nonnull IVec2 v) {
		if (!gfx.getBoundingBox().collides(v.x() - offset.x, v.y() - offset.y, getWidth() * sprite.getScaleX(), getHeight() * sprite.getScaleY()))
			return;

		if (Vec2.zero.equals(v) && Vec2.zero.equals(offset)) {
			gfx.prepareSprites();
			sprite.draw(gfx.getSpriteBatch());
		} else {
			float oldX = sprite.getX();
			float oldY = sprite.getY();

			sprite.translate(v.x() - offset.x, v.y() - offset.y);
			gfx.prepareSprites();
			sprite.draw(gfx.getSpriteBatch());

			sprite.setPosition(oldX, oldY);
		}
	}

	public final void center() {
		setOriginCenter();
		offset = (getSize() * 0.5f).getMutableCopy();
	}

	public @Nonnull IVec2 getOrigin() {
		return new Vec2(sprite.getOriginX(), sprite.getOriginY());
{'fraction_non_alphanumeric': 0.13067926225820964, 'fraction_numerical': 0.006747638326585695, 'mean_word_length': 4.9372496662216285, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2550425', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1574, 'n_words': 341}