diff --git a/src/api b/src/api index b84763a8e..ae73e1b88 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit b84763a8eefdc0be7fb909888ac5ad6d22e3f987 +Subproject commit ae73e1b885415701c1ee20b64c1d0ae9c9089efc diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java index 1a6c907ea..cb27dcd3f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java @@ -2,6 +2,9 @@ package kamkeel.npcs.controllers.data.ability; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; +import noppes.npcs.api.handler.data.IAnimation; +import noppes.npcs.controllers.data.Animation; +import noppes.npcs.util.NBTJsonUtil; import org.apache.commons.io.FileUtils; import java.io.File; @@ -11,7 +14,6 @@ import java.util.HashMap; import static kamkeel.npcs.controllers.data.ability.AbilityPhase.*; public enum AbilityAnimation {; - private final HashMap animations = new HashMap<>(); AbilityAnimation(String idle, String windUp, String active, String recovery) { @@ -40,30 +42,49 @@ public enum AbilityAnimation {; return animations.get(phase); } - public File get(AbilityPhase phase) { + public File getFile(AbilityPhase phase) { if (animations.get(phase).isEmpty() || animations.get(phase).equals("N/A")) return null; - return getFile(animations.get(phase)); + return getFileFromName(animations.get(phase)); } - public File idle() { - return get(IDLE); + public IAnimation getAnimation(AbilityPhase phase) { + try { + File file = getFile(phase); + + if (file == null) { + return null; + } + + Animation animation = new Animation(); + animation.readFromNBT(NBTJsonUtil.LoadFile(file)); + + return animation; + } catch (Exception e) { + LogWriter.except(e); + } + + return null; } - public File windUp() { - return get(WINDUP); + public IAnimation idle() { + return getAnimation(IDLE); } - public File active() { - return get(ACTIVE); + public IAnimation windUp() { + return getAnimation(WINDUP); } - public File recovery() { - return get(RECOVERY); + public IAnimation active() { + return getAnimation(ACTIVE); } - private File getFile(String fileName) { + public IAnimation recovery() { + return getAnimation(RECOVERY); + } + + private File getFileFromName(String fileName) { try (InputStream stream = CustomNpcs.class.getResourceAsStream("/internal/data/animations/" + name() + "/" + fileName + ".json")) { File file = new File("temp"); diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java index be9ce355d..0b88f1a42 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java @@ -47,7 +47,6 @@ public class AbilityController implements IAbilityHandler { public AbilityController() { Instance = this; registerBuiltins(); - new Animations(); } /** @@ -320,67 +319,4 @@ public class AbilityController implements IAbilityHandler { registerType("cnpc:hazard", AbilityHazard::new); registerType("cnpc:trap", AbilityTrap::new); } - - public static class Animations { - public HashMap> animations; - - public static Animations Instance; - - public Animations() { - Instance = this; - animations = new HashMap<>(); - load(); - } - - public void load() { - registerBuiltins(); - } - - private void registerBuiltins() { - animations.clear(); - - try { - for (AbilityPhase phase : AbilityPhase.values()) { - for (AbilityAnimation anim : AbilityAnimation.values()) { - File file = anim.get(phase); - - if (file == null) { -// LogWriter.info("AnimationController: Ability Animations for " + anim.name() + " not found."); - continue; - } - - Animation animation = new Animation(); - animation.readFromNBT(NBTJsonUtil.LoadFile(file)); - - animations - .computeIfAbsent(anim.ordinal(), k -> new EnumMap<>(AbilityPhase.class)) - .put(phase, animation); - } - } - } catch (Exception e) { - LogWriter.except(e); - } - } - - public IAnimation get(AbilityAnimation ability, AbilityPhase phase) { - return get(ability.ordinal(), phase); - } - - public IAnimation get(int id, AbilityPhase phase) { - return animations.get(id).get(phase); - } - - public boolean has(AbilityAnimation ability, AbilityPhase phase) { - return get(ability.ordinal(), phase) != null; - } - - public boolean has(int id, AbilityPhase phase) { - return get(id, phase) != null; - } - - public IAnimation[] getAnimations(AbilityAnimation ability) { - ArrayList animations = new ArrayList<>(this.animations.get(ability.ordinal()).values()); - return animations.toArray(new IAnimation[0]); - } - } }