AbstractVectorEffect.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2009-2026 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. package com.jme3.vectoreffect;
  33. import com.jme3.app.state.AppStateManager;
  34. import java.util.ArrayList;
  35. /**
  36. * @author yaRnMcDonuts
  37. */
  38. public abstract class AbstractVectorEffect implements VectorEffect {
  39. protected VectorGroup vectorsToModify;
  40. private final ArrayList<Runnable> onFinishedCallbacks = new ArrayList<>();
  41. protected boolean isFinished = false;
  42. public AbstractVectorEffect(){
  43. }
  44. public AbstractVectorEffect(VectorGroup vectorsToModify) {
  45. this.vectorsToModify = vectorsToModify;
  46. }
  47. @Override
  48. public void setIsFinished(boolean isFinished) {
  49. this.isFinished = isFinished;
  50. if (isFinished) {
  51. for(Runnable r : onFinishedCallbacks) {
  52. r.run();
  53. }
  54. onFinishedCallbacks.clear();
  55. }
  56. }
  57. @Override
  58. public VectorGroup getVectorsToModify(){
  59. return vectorsToModify;
  60. }
  61. @Override
  62. public boolean isFinished() {
  63. return isFinished;
  64. }
  65. @Override
  66. public void reset() {
  67. isFinished = false;
  68. }
  69. public void registerRunnableOnFinish(Runnable runnable) {
  70. onFinishedCallbacks.add(runnable);
  71. }
  72. @Override
  73. public void update(float tpf){
  74. }
  75. // convenience registration method so users can avoid repeatedly writing this AppState fetching code
  76. public void convenienceRegister(AppStateManager stateManager) {
  77. if(stateManager != null){
  78. VectorEffectManagerState vectorEffectManagerState = stateManager.getState(VectorEffectManagerState.class);
  79. if(vectorEffectManagerState != null){
  80. vectorEffectManagerState.registerVectorEffect(this);
  81. }
  82. }
  83. }
  84. }