1
0
mirror of https://github.com/aNNiMON/HotaruFX.git synced 2024-09-19 14:14:21 +03:00

Add nodes bundle

This commit is contained in:
Victor 2017-08-30 17:07:01 +03:00
parent 722ebc6107
commit cff8de94da
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package com.annimon.hotarufx.bundles;
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NodeValue;
import com.annimon.hotarufx.lib.Validator;
import com.annimon.hotarufx.visual.objects.CircleNode;
import com.annimon.hotarufx.visual.objects.ObjectNode;
import java.util.function.Supplier;
import lombok.val;
public class NodesBundle implements Bundle {
@Override
public void load(Context context) {
context.functions().put("circle", node(CircleNode::new));
}
private Function node(Supplier<? extends ObjectNode> supplier) {
return args -> {
val map = Validator.with(args).requireMapAt(0);
val node = new NodeValue(supplier.get());
node.fill(map);
return node;
};
}
}

View File

@ -0,0 +1,47 @@
package com.annimon.hotarufx.bundles;
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.MapValue;
import com.annimon.hotarufx.lib.NodeValue;
import com.annimon.hotarufx.lib.NumberValue;
import com.annimon.hotarufx.lib.StringValue;
import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.visual.objects.CircleNode;
import java.util.Arrays;
import java.util.HashMap;
import javafx.scene.paint.Color;
import lombok.val;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
class NodesBundleTest {
@Test
void testBundle() {
val context = new Context();
BundleLoader.load(context, Arrays.asList(
CompositionBundle.class,
NodesBundle.class
));
assertThat(context.functions(), hasKey("circle"));
val map = new HashMap<String, Value>();
map.put("cx", NumberValue.of(-10));
map.put("radius", NumberValue.of(50));
map.put("fill", new StringValue("#00AA00"));
val value = context.functions().get("circle").execute(new MapValue(map));
assertThat(value, instanceOf(NodeValue.class));
val nodeValue = (NodeValue) value;
assertThat(nodeValue.getNode(), notNullValue());
assertThat(nodeValue.getNode(), instanceOf(CircleNode.class));
val circle = (CircleNode) nodeValue.getNode();
assertThat(circle.circle.getCenterX(), closeTo(-10, 0.001));
assertThat(circle.circle.getRadius(), closeTo(50, 0.001));
assertThat(circle.circle.getFill(), is(Color.web("#00AA00")));
}
}