use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class EnchantmentStorageMetaParser method parse.
@Override
public EnchantmentStorageMeta parse(Node root, ItemStack itemStack, EnchantmentStorageMeta itemMeta) throws ParserException {
Node node = root.firstChild("enchanted-book");
if (node != null) {
for (Node enchantment : node.children("enchantment")) {
ItemEnchantment value = this.enchantmentParser.parse(enchantment).orFail();
itemMeta.addStoredEnchant(value.getType(), value.getLevel(), true);
}
}
return itemMeta;
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class MapMetaParser method parse.
@Override
public MapMeta parse(Node root, ItemStack itemStack, MapMeta itemMeta) throws ParserException {
Node node = root.firstChild("map");
if (node != null) {
Property scaling = node.property("scaling");
if (scaling != null) {
itemMeta.setScaling(this.scalingParser.parse(scaling).orFail());
}
Property locationName = node.property("location-name");
if (locationName != null) {
itemMeta.setLocationName(this.locationNameParser.parse(locationName).orFail());
}
Property color = node.property("color");
if (color != null) {
itemMeta.setColor(this.colorParser.parse(color).orFail());
}
}
return itemMeta;
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class KitParser method parseTree.
@Override
protected ParserResult<Kit.Config> parseTree(Node node, String name) throws ParserException {
String id = this.parseRequiredId(node);
List<KitContent.Config<?, ?>> contents = new ArrayList<>();
for (Node contentNode : node.children()) {
contents.add(this.contentParser.parse(contentNode).orFail());
}
if (ParserUtils.ensureNotEmpty(contents)) {
throw this.fail(node, name, null, "No kit contents defined");
}
Set<String> inherit = new LinkedHashSet<>();
String inheritValue = node.propertyValue("inherit", "parent", "parents");
if (inheritValue != null) {
inherit.addAll(ParserUtils.array(inheritValue));
}
return ParserResult.fine(node, name, new Kit.Config() {
public String id() {
return id;
}
public List<KitContent.Config<?, ?>> contents() {
return contents;
}
public Set<String> inherit() {
return inherit;
}
});
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class ImportStage method invokeNode.
@Override
public void invokeNode(Node node) throws PreprocessException {
if (!node.hasParent()) {
throw new PreprocessException(node, "Node must have its parent");
}
Node parent = node.getParent();
String targetPath = node.getValue();
if (targetPath == null) {
throw new PreprocessException(node, "Target document path not specified");
}
Document target;
try {
Path directory = this.document.getPath().getParent();
target = readDocument(this.engines, node, directory.resolve(targetPath).toUri());
} catch (InvalidPathException ex) {
throw new PreprocessException(node, "Invalid document path: " + ex.getReason(), ex);
}
if (!target.hasPath()) {
throw new PreprocessException(target, "Cannot resolve target document path");
} else if (!target.hasRoot()) {
throw new PreprocessException(target, "Target document is empty");
}
Path path = target.getPath();
if (stack.search(path) != -1) {
throw new PreprocessException(target, "Import loop detected");
}
stack.push(path);
// Preprocess the target document.
this.preprocessor.preprocess(target);
// Remove the old <import> node.
Node.detach(node);
// We don't support root node properties.
parent.add(target.getRoot().children());
}
use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.
the class Include method invokeNode.
@Override
public void invokeNode(Node node) throws PreprocessException {
if (!node.hasParent()) {
throw new PreprocessException(node, "Node must have its parent");
}
Node parent = node.getParent();
String targetPath = node.getValue();
if (targetPath == null) {
throw new PreprocessException(node, "Target document path not specified");
}
Document target;
try {
target = ImportStage.readDocument(this.engines, node, this.repository.resolve(targetPath).toUri());
} catch (InvalidPathException ex) {
throw new PreprocessException(node, "Invalid document path: " + ex.getReason(), ex);
}
if (!target.hasPath()) {
throw new PreprocessException(target, "Cannot resolve target document path");
} else if (!target.hasRoot()) {
throw new PreprocessException(target, "Target document is empty");
}
// Preprocess the target document.
this.preprocessor.preprocess(target);
// Remove the old <include> node.
Node.detach(node);
// We don't support root node properties.
parent.add(target.getRoot().children());
}
Aggregations