use of dfEditor.CustomNode in project darkFunction-Editor by darkFunction.
the class AnimationSetReader method getAnimations.
public ArrayList<Animation> getAnimations(SpriteTree aSpriteTree, BufferedImage aImage) throws Exception {
ArrayList animations = new ArrayList<Animation>();
NodeList animNodeList = doc.getElementsByTagName("anim");
for (int i = 0; i < animNodeList.getLength(); ++i) {
Node animNode = animNodeList.item(i);
Animation animation = new Animation(((Element) animNode).getAttribute("name"));
String loopsStr = ((Element) animNode).getAttribute("loops");
if (loopsStr != null && loopsStr.length() != 0) {
int loops = Integer.parseInt(loopsStr);
animation.setLoops(loops);
}
NodeList cellNodeList = animNode.getChildNodes();
for (int j = 0; j < cellNodeList.getLength(); ++j) {
Node cellNode = cellNodeList.item(j);
if (cellNode.getNodeType() != Node.ELEMENT_NODE)
continue;
AnimationCell cell = new AnimationCell();
cell.setDelay(Integer.parseInt(((Element) cellNode).getAttribute("delay")));
NodeList spriteNodeList = cellNode.getChildNodes();
for (int k = 0; k < spriteNodeList.getLength(); ++k) {
Node spriteNode = spriteNodeList.item(k);
if (spriteNode.getNodeType() != Node.ELEMENT_NODE)
continue;
CustomNode treeNode = aSpriteTree.getNodeForPath(((Element) spriteNode).getAttribute("name"));
if (treeNode != null && treeNode.isLeaf()) {
GraphicObject spriteArea = (GraphicObject) treeNode.getCustomObject();
// boolean centreAnchor = false;
// String anchorString = ((Element)spriteNode).getAttribute("anchor");
// if (anchorString != null && anchorString.length() != 0)
// {
// if (anchorString.equals("centre"))
// centreAnchor = true;
// }
int x = 0;
int y = 0;
int z = 0;
try {
x = Integer.parseInt(((Element) spriteNode).getAttribute("x"));
y = Integer.parseInt(((Element) spriteNode).getAttribute("y"));
z = Integer.parseInt(((Element) spriteNode).getAttribute("z"));
} catch (NumberFormatException e) {
}
Rectangle r = spriteArea.getRect();
if (version >= 1.2) {
x -= r.width / 2;
y -= r.height / 2;
}
SpriteGraphic graphic = new SpriteGraphic(aImage, new Point(x, y), r);
float angle = 0;
String angleString = ((Element) spriteNode).getAttribute("angle");
if (angleString != null && angleString.length() != 0)
angle = Float.parseFloat(angleString);
graphic.setAngle(angle);
graphic.saveAngle();
boolean flipH = false;
boolean flipV = false;
String flipHString = ((Element) spriteNode).getAttribute("flipH");
String flipVString = ((Element) spriteNode).getAttribute("flipV");
if (flipHString != null && flipHString.length() > 0)
flipH = 0 != Integer.parseInt(flipHString);
if (flipVString != null && flipVString.length() > 0)
flipV = 0 != Integer.parseInt(flipVString);
if (flipV)
graphic.flip(false);
if (flipH)
graphic.flip(true);
cell.addSprite(treeNode, graphic);
cell.setZOrder(graphic, z);
}
}
animation.addCell(cell);
}
animations.add(animation);
}
return animations;
}
use of dfEditor.CustomNode in project darkFunction-Editor by darkFunction.
the class SpritesheetReader method createTreeModelFromDOM.
private DefaultTreeModel createTreeModelFromDOM(Element aRootNode) {
CustomNode rootNode = createCustomNodeFromDOMNode(aRootNode);
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode, true);
return treeModel;
}
use of dfEditor.CustomNode in project darkFunction-Editor by darkFunction.
the class SpritesheetReader method createCustomNodeFromDOMNode.
public CustomNode createCustomNodeFromDOMNode(Element aDOMNode) {
boolean bDir = false;
if (aDOMNode.getTagName().equals("dir"))
bDir = true;
CustomNode node = new CustomNode(aDOMNode.getAttribute("name"), bDir);
if (node.isLeaf() && aDOMNode.getTagName().equals("spr")) {
node.setCustomObject(new SelectionBox(new Rectangle(Integer.parseInt(aDOMNode.getAttribute("x")), Integer.parseInt(aDOMNode.getAttribute("y")), Integer.parseInt(aDOMNode.getAttribute("w")), Integer.parseInt(aDOMNode.getAttribute("h"))), node.getColour()));
} else {
for (int i = 0; i < aDOMNode.getChildNodes().getLength(); ++i) {
Node childNode = aDOMNode.getChildNodes().item(i);
Element element = null;
if (childNode.getNodeType() == Node.ELEMENT_NODE)
element = (Element) childNode;
if (element != null) {
CustomNode customNode = createCustomNodeFromDOMNode(element);
node.add(customNode);
}
}
}
return node;
}
use of dfEditor.CustomNode in project darkFunction-Editor by darkFunction.
the class RemoveDirCommand method remove.
private void remove(CustomNode aNode) {
while (aNode.getChildCount() > 0) {
CustomNode childNode = (CustomNode) aNode.getLastChild();
UndoableCommand command;
if (childNode.isLeaf()) {
command = new RemoveGraphicCommand(tree, panel, childNode);
} else {
remove(childNode);
command = new RemoveNodeCommand(tree, childNode);
}
commandStack.push(command);
command.execute();
}
}
Aggregations