1 /* 2 * Copyright (c) 2009-2010 jMonkeyEngine 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package jme3test.input.combomoves; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 public class ComboMove { 39 40 public static class ComboMoveState { 41 42 private String[] pressedMappings; 43 private String[] unpressedMappings; 44 private float timeElapsed; 45 ComboMoveState(String[] pressedMappings, String[] unpressedMappings, float timeElapsed)46 public ComboMoveState(String[] pressedMappings, String[] unpressedMappings, float timeElapsed) { 47 this.pressedMappings = pressedMappings; 48 this.unpressedMappings = unpressedMappings; 49 this.timeElapsed = timeElapsed; 50 } 51 getUnpressedMappings()52 public String[] getUnpressedMappings() { 53 return unpressedMappings; 54 } 55 getPressedMappings()56 public String[] getPressedMappings() { 57 return pressedMappings; 58 } 59 getTimeElapsed()60 public float getTimeElapsed() { 61 return timeElapsed; 62 } 63 64 } 65 66 private String moveName; 67 private List<ComboMoveState> states = new ArrayList<ComboMoveState>(); 68 private boolean useFinalState = true; 69 private float priority = 1; 70 private float castTime = 0.8f; 71 72 private transient String[] pressed, unpressed; 73 private transient float timeElapsed; 74 ComboMove(String moveName)75 public ComboMove(String moveName){ 76 this.moveName = moveName; 77 } 78 getPriority()79 public float getPriority() { 80 return priority; 81 } 82 setPriority(float priority)83 public void setPriority(float priority) { 84 this.priority = priority; 85 } 86 getCastTime()87 public float getCastTime() { 88 return castTime; 89 } 90 setCastTime(float castTime)91 public void setCastTime(float castTime) { 92 this.castTime = castTime; 93 } 94 useFinalState()95 public boolean useFinalState() { 96 return useFinalState; 97 } 98 setUseFinalState(boolean useFinalState)99 public void setUseFinalState(boolean useFinalState) { 100 this.useFinalState = useFinalState; 101 } 102 press(String .... pressedMappings)103 public ComboMove press(String ... pressedMappings){ 104 this.pressed = pressedMappings; 105 return this; 106 } 107 notPress(String .... unpressedMappings)108 public ComboMove notPress(String ... unpressedMappings){ 109 this.unpressed = unpressedMappings; 110 return this; 111 } 112 timeElapsed(float time)113 public ComboMove timeElapsed(float time){ 114 this.timeElapsed = time; 115 return this; 116 } 117 done()118 public void done(){ 119 if (pressed == null) 120 pressed = new String[0]; 121 122 if (unpressed == null) 123 unpressed = new String[0]; 124 125 states.add(new ComboMoveState(pressed, unpressed, timeElapsed)); 126 pressed = null; 127 unpressed = null; 128 timeElapsed = -1; 129 } 130 getState(int num)131 public ComboMoveState getState(int num){ 132 return states.get(num); 133 } 134 getNumStates()135 public int getNumStates(){ 136 return states.size(); 137 } 138 getMoveName()139 public String getMoveName() { 140 return moveName; 141 } 142 143 } 144