<commit_before>package de.gurkenlabs.litiengine.graphics.animation;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import de.gurkenlabs.core.ILaunchable;
import de.gurkenlabs.litiengine.Game;
import de.gurkenlabs.litiengine.IGameLoop;
import de.gurkenlabs.litiengine.IUpdateable;
import de.gurkenlabs.litiengine.graphics.Spritesheet;

public class Animation implements IUpdateable, ILaunchable {
  private final int DEFAULT_FRAME_DURATION = 120;
  private final String name;
  private final Spritesheet spritesheet;
  private final List<KeyFrame> keyframes;
  private final boolean loop;

  private int frameDuration = this.DEFAULT_FRAME_DURATION;
  private boolean playing;
  private KeyFrame currentFrame;
  private KeyFrame firstFrame;
  private long elapsedTicks;
  private boolean paused;

  public Animation(final String name, final Spritesheet spritesheet, final boolean loop, final boolean randomizeStart, final int... keyFrameDurations) {
    this(name, spritesheet, loop, keyFrameDurations);

    if (randomizeStart && this.keyframes.size() > 0) {
      this.firstFrame = this.getKeyframes().get(new Random().nextInt(this.getKeyframes().size()));
    }
  }

  public Animation(final String name, final Spritesheet spritesheet, final boolean loop, final int... keyFrameDurations) {
    this.name = name;
    this.spritesheet = spritesheet;
    this.loop = loop;
    this.keyframes = new ArrayList<>();
    this.initKeyFrames(keyFrameDurations);
    if (this.getKeyframes().size() == 0) {
      System.out.println("No keyframes defined for animation " + this.getName() + " (spitesheet: " + spritesheet.getPath() + ")");
    }

    Game.getLoop().registerForUpdate(this);
  }

  public KeyFrame getCurrentKeyFrame() {
    return this.currentFrame;
  }

  public int getFrameDuration() {
    return this.frameDuration;
  }

  public List<KeyFrame> getKeyframes() {
    return this.keyframes;
  }

  public String getName() {
    return this.name;
  }

  public Spritesheet getSpritesheet() {
    return this.spritesheet;
  }

  private void initKeyFrames(final int[] keyFrames) {

    // if no keyframes are specified, the animation takes in the whole
    // spritesheet as animation and uses the DEFAULT_FRAME_DURATION for each
    // keyframe
    if (keyFrames.length == 0) {
      for (int i = 0; i < this.getSpritesheet().getTotalNumberOfSprites(); i++) {
        this.keyframes.add(i, new KeyFrame(this.getFrameDuration(), i));
      }
    } else {
      for (int i = 0; i < keyFrames.length; i++) {
        this.keyframes.add(i, new KeyFrame(keyFrames[i], i));
      }
    }

    if (this.keyframes.size() != 0) {
      this.firstFrame = this.getKeyframes().get(0);
    }
  }

  private boolean isLastKeyFrame() {
    return this.getKeyframes().indexOf(this.currentFrame) == this.getKeyframes().size() - 1;
  }

  public boolean isLoop() {
    return this.loop;
  }

  public boolean isPaused() {
    return this.paused;
  }

  public boolean isPlaying() {
    return !this.paused && this.keyframes.size() > 0 && this.playing;
  }

  public void pause() {
    this.paused = true;
  }

  public void setFrameDuration(final int frameDuration) {
    this.frameDuration = frameDuration;

    // TODO: update frame durations
  }

  @Override
  public void start() {
    this.elapsedTicks = 0;
    this.playing = true;
    if (this.getKeyframes().size() == 0) {
      return;
    }

    this.currentFrame = this.firstFrame;
  }

  @Override
  public void terminate() {
    this.elapsedTicks = 0;
    this.playing = false;
    if (this.getKeyframes().size() == 0) {
      return;
    }

    this.currentFrame = this.getKeyframes().get(0);
  }

  public void unpause() {
    this.paused = false;
  }

  @Override
  public void update(final IGameLoop loop) {
    // do nothing if the animation is not playing of the current keyframe is not
    // finished
    if (!this.isPlaying() || loop.convertToMs(++this.elapsedTicks) < this.currentFrame.getDuration()) {
      return;
    }

    // if we are not looping and the last keyframe is finished, we terminate the
    // animation
    if (!this.isLoop() && this.isLastKeyFrame()) {
      this.terminate();
      return;
    }

    // make sure, we stay inside the keyframe list
    final int newFrameIndex = (this.getKeyframes().indexOf(this.currentFrame) + 1) % this.getKeyframes().size();
    this.currentFrame = this.getKeyframes().get(newFrameIndex);
    this.elapsedTicks = 0;
  }
}
<commit_msg>Added a wheelchair zombie.<commit_after>package de.gurkenlabs.litiengine.graphics.animation;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import de.gurkenlabs.core.ILaunchable;
import de.gurkenlabs.litiengine.Game;
import de.gurkenlabs.litiengine.IGameLoop;
import de.gurkenlabs.litiengine.IUpdateable;
import de.gurkenlabs.litiengine.graphics.Spritesheet;

public class Animation implements IUpdateable, ILaunchable {
  private final int DEFAULT_FRAME_DURATION = 120;
  private final String name;
  private final Spritesheet spritesheet;
  private final List<KeyFrame> keyframes;
  private final boolean loop;

  private int frameDuration = this.DEFAULT_FRAME_DURATION;
  private boolean playing;
  private KeyFrame currentFrame;
  private KeyFrame firstFrame;
  private long elapsedTicks;
  private boolean paused;

  public Animation(final String name, final Spritesheet spritesheet, final boolean loop, final boolean randomizeStart, final int... keyFrameDurations) {
    this(name, spritesheet, loop, keyFrameDurations);

    if (randomizeStart && this.keyframes.size() > 0) {
      this.firstFrame = this.getKeyframes().get(new Random().nextInt(this.getKeyframes().size()));
    }
  }

  public Animation(final String name, final Spritesheet spritesheet, final boolean loop, final int... keyFrameDurations) {

    
    this.name = name;
    this.spritesheet = spritesheet;
    this.loop = loop;
    this.keyframes = new ArrayList<>();
    if(spritesheet == null){
      System.out.println("no spritesheet defined for animation " + name);
      return;
    }
    
    this.initKeyFrames(keyFrameDurations);
    if (this.getKeyframes().size() == 0) {
      System.out.println("No keyframes defined for animation " + this.getName() + " (spitesheet: " + spritesheet.getPath() + ")");
    }

    Game.getLoop().registerForUpdate(this);
  }

  public KeyFrame getCurrentKeyFrame() {
    return this.currentFrame;
  }

  public int getFrameDuration() {
    return this.frameDuration;
  }

  public List<KeyFrame> getKeyframes() {
    return this.keyframes;
  }

  public String getName() {
    return this.name;
  }

  public Spritesheet getSpritesheet() {
    return this.spritesheet;
  }

  private void initKeyFrames(final int[] keyFrames) {

    if(this.getSpritesheet() == null){
      return;
    }
    
    // if no keyframes are specified, the animation takes in the whole
    // spritesheet as animation and uses the DEFAULT_FRAME_DURATION for each
    // keyframe
    if (keyFrames.length == 0) {
      for (int i = 0; i < this.getSpritesheet().getTotalNumberOfSprites(); i++) {
        this.keyframes.add(i, new KeyFrame(this.getFrameDuration(), i));
      }
    } else {
      for (int i = 0; i < keyFrames.length; i++) {
        this.keyframes.add(i, new KeyFrame(keyFrames[i], i));
      }
    }

    if (this.keyframes.size() != 0) {
      this.firstFrame = this.getKeyframes().get(0);
    }
  }

  private boolean isLastKeyFrame() {
    return this.getKeyframes().indexOf(this.currentFrame) == this.getKeyframes().size() - 1;
  }

  public boolean isLoop() {
    return this.loop;
  }

  public boolean isPaused() {
    return this.paused;
  }

  public boolean isPlaying() {
    return !this.paused && this.keyframes.size() > 0 && this.playing;
  }

  public void pause() {
    this.paused = true;
  }

  public void setFrameDuration(final int frameDuration) {
    this.frameDuration = frameDuration;

    // TODO: update frame durations
  }

  @Override
  public void start() {
    this.elapsedTicks = 0;
    this.playing = true;
    if (this.getKeyframes().size() == 0) {
      return;
    }

    this.currentFrame = this.firstFrame;
  }

  @Override
  public void terminate() {
    this.elapsedTicks = 0;
    this.playing = false;
    if (this.getKeyframes().size() == 0) {
      return;
    }

    this.currentFrame = this.getKeyframes().get(0);
  }

  public void unpause() {
    this.paused = false;
  }

  @Override
  public void update(final IGameLoop loop) {
    // do nothing if the animation is not playing of the current keyframe is not
    // finished
    if (!this.isPlaying() || loop.convertToMs(++this.elapsedTicks) < this.currentFrame.getDuration()) {
      return;
    }

    // if we are not looping and the last keyframe is finished, we terminate the
    // animation
    if (!this.isLoop() && this.isLastKeyFrame()) {
      this.terminate();
      return;
    }

    // make sure, we stay inside the keyframe list
    final int newFrameIndex = (this.getKeyframes().indexOf(this.currentFrame) + 1) % this.getKeyframes().size();
    this.currentFrame = this.getKeyframes().get(newFrameIndex);
    this.elapsedTicks = 0;
  }
}

{'fraction_non_alphanumeric': 0.11298127498422049, 'fraction_numerical': 0.003997475278771302, 'mean_word_length': 2.8381106176826805, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '7588836', 'n_tokens_mistral': 3076, 'n_tokens_neox': 2859, 'n_words': 707}