package gameplay.frames; import java.util.ArrayList; /** * This will handle the next frames to be played by each entity. * @author Victor Azra */ public class nextFrameBuffer { private Frame current; private nextFrameBuffer next; /** * creates a new framebuffer, empty for now */ public nextFrameBuffer() { this.current = null; this.next = null; } public void setCurrentFrame(Frame f) { this.current = f; } public void clone(nextFrameBuffer f) { try{ Frame cf = new Frame(); cf.clone(f.current); this.current = cf; } catch (NullPointerException n) { this.current = null; this.next = null; } nextFrameBuffer nfb = new nextFrameBuffer(); try { nfb.clone(f.next); } catch (NullPointerException n) {} this.next = nfb; } public void setNext(nextFrameBuffer f) { this.next.clone(f); } public void emptyQueue() { this.next = null; } public void empty() { this.current = null; this.next = null; } public void goToNext() { //try { nextFrameBuffer nfb = new nextFrameBuffer(); nfb.clone(this.next); this.clone(nfb); /*} catch (NullPointerException n) { this.setCurrentFrame(null); this.setNext(new nextFrameBuffer()); }*/ } public Frame getCurrentFrame() { return this.current; } public Frame getNextframe() { try { return this.next.current; } catch(NullPointerException e) {return null;} } /** * Adds a frame at the end of the buffer * @param f the frame to add at the end */ public void addFrameToQueue(Frame f) { if(this.current == null) { this.current = f; } else if(this.next == null){ nextFrameBuffer fb = new nextFrameBuffer(); fb.current = f; this.next = fb; } else { this.next.addFrameToQueue(f); } } /** * Copies the same amount of frames from f in this, as the amount originally present, but keepsoriginal move data * @param f frames array to copy */ public void changeFramesExceptForMove(ArrayList f) { int i = 0; boolean goOn = true; nextFrameBuffer fb = new nextFrameBuffer(); fb.clone(this); this.emptyQueue(); try{fb.goToNext();} catch(NullPointerException e) {goOn = false;} while(goOn && i < f.size()) { try{ fb.current.cloneWithoutMovement(f.get(i)); this.addFrameToQueue(fb.current); fb.goToNext(); i++; } catch(NullPointerException e) { goOn = false;} } } }