mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 12:15:11 +00:00
Animation GUI Move to similar style menu. [Sub Gui not implemented yet]
This commit is contained in:
1 parent
7713970f77
commit
f6e8370ba3
10 files changed
+790
-552
No files matched your search
@@ -4,15 +4,18 @@ import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.handler.IAnimationHandler;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
import noppes.npcs.api.handler.data.IFaction;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.Faction;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class AnimationController implements IAnimationHandler {
|
||||
public HashMap<String, Animation> animations;
|
||||
public HashMap<Integer, Animation> animations;
|
||||
public static AnimationController Instance;
|
||||
private int lastUsedID = 0;
|
||||
|
||||
public AnimationController() {
|
||||
Instance = this;
|
||||
@@ -44,7 +47,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
Animation animation = new Animation();
|
||||
animation.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
animation.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
animations.put(animation.name,animation);
|
||||
animations.put(animation.id, animation);
|
||||
} catch(Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
@@ -56,9 +59,35 @@ public class AnimationController implements IAnimationHandler {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "animations");
|
||||
}
|
||||
|
||||
public IAnimation saveAnimation(IAnimation animation){
|
||||
animations.put(animation.getName(), (Animation) animation);
|
||||
public int getUnusedId(){
|
||||
if(lastUsedID == 0){
|
||||
for(int catid : animations.keySet()){
|
||||
if(catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
|
||||
}
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
|
||||
public IAnimation saveAnimation(IAnimation animation){
|
||||
if(animation.getID() < 0){
|
||||
animation.setID(getUnusedId());
|
||||
while(hasName(animation.getName()))
|
||||
animation.setName(animation.getName() + "_");
|
||||
}
|
||||
else{
|
||||
Animation existing = animations.get(animation.getID());
|
||||
if(existing != null && !existing.name.equals(animation.getName()))
|
||||
while(hasName(animation.getName()))
|
||||
animation.setName(animation.getName() + "_");
|
||||
}
|
||||
|
||||
animations.remove(animation.getID());
|
||||
animations.put(animation.getID(), (Animation) animation);
|
||||
|
||||
// Save Animation File
|
||||
File dir = this.getDir();
|
||||
if(!dir.exists())
|
||||
dir.mkdirs();
|
||||
@@ -74,30 +103,64 @@ public class AnimationController implements IAnimationHandler {
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
return animations.get(animation.getName());
|
||||
return animations.get(animation.getID());
|
||||
}
|
||||
|
||||
public boolean hasName(String newName) {
|
||||
if(newName.trim().isEmpty())
|
||||
return true;
|
||||
for(Animation animation : animations.values())
|
||||
if(animation.name.equals(newName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void delete(String name) {
|
||||
if(!this.animations.containsKey(name))
|
||||
return;
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(name+".json")) {
|
||||
file.delete();
|
||||
break;
|
||||
Animation delete = getAnimationFromName(name);
|
||||
if(delete != null){
|
||||
Animation foundAnimation = this.animations.remove(delete.getID());
|
||||
if(foundAnimation != null && foundAnimation.name != null){
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundAnimation.name+".json")) {
|
||||
file.delete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
if(!this.animations.containsKey(id))
|
||||
return;
|
||||
|
||||
Animation foundAnimation = this.animations.remove(id);
|
||||
if(foundAnimation != null && foundAnimation.name != null){
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundAnimation.name+".json")) {
|
||||
file.delete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.animations.remove(name);
|
||||
}
|
||||
|
||||
public boolean has(String name) {
|
||||
return this.animations.containsKey(name);
|
||||
return getAnimationFromName(name) != null;
|
||||
}
|
||||
|
||||
public IAnimation get(String name) {
|
||||
return this.animations.get(name);
|
||||
return getAnimationFromName(name);
|
||||
}
|
||||
|
||||
public IAnimation get(int id) {
|
||||
return this.animations.get(id);
|
||||
}
|
||||
|
||||
public IAnimation[] getAnimations() {
|
||||
@@ -106,7 +169,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
}
|
||||
|
||||
public Animation getAnimationFromName(String animation){
|
||||
for (Map.Entry<String,Animation> entryAnimation : AnimationController.getInstance().animations.entrySet()){
|
||||
for (Map.Entry<Integer,Animation> entryAnimation : AnimationController.getInstance().animations.entrySet()){
|
||||
if (entryAnimation.getValue().name.equalsIgnoreCase(animation)){
|
||||
return entryAnimation.getValue();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user