diff --git a/app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java b/app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java new file mode 100644 index 0000000..c647371 --- /dev/null +++ b/app/src/main/java/com/annimon/hotarufx/lib/NodeValue.java @@ -0,0 +1,74 @@ +package com.annimon.hotarufx.lib; + +import com.annimon.hotarufx.exceptions.TypeException; +import com.annimon.hotarufx.visual.Property; +import com.annimon.hotarufx.visual.PropertyBindings; +import com.annimon.hotarufx.visual.PropertyTimeline; +import com.annimon.hotarufx.visual.objects.ObjectNode; +import javafx.scene.paint.Paint; +import lombok.val; + +public class NodeValue implements Value { + + private final ObjectNode node; + private final PropertyBindings bindings; + + public NodeValue(ObjectNode node) { + this.node = node; + bindings = node.propertyBindings(); + } + + @Override + public int type() { + return Types.NODE; + } + + public ObjectNode getNode() { + return node; + } + + @Override + public Object raw() { + return node; + } + + @SuppressWarnings("unchecked") + public void fill(MapValue map) { + map.getMap().forEach((key, value) -> { + if (!bindings.containsKey(key)) return; + final Property property = bindings.get(key); + val timeline = property.getProperty().get(); + val type = property.getType(); + switch (type) { + case NUMBER: + ((PropertyTimeline) timeline).getProperty().setValue( + type.getFromHFX().apply(value)); + break; + case PAINT: + ((PropertyTimeline) timeline).getProperty().setValue( + type.getFromHFX().apply(value)); + break; + } + }); + } + + @Override + public int asInt() { + throw new TypeException("Cannot cast node to integer"); + } + + @Override + public double asNumber() { + throw new TypeException("Cannot cast node to number"); + } + + @Override + public String asString() { + throw new TypeException("Cannot cast node to string"); + } + + @Override + public int compareTo(Value o) { + return 0; + } +} diff --git a/app/src/main/java/com/annimon/hotarufx/lib/Types.java b/app/src/main/java/com/annimon/hotarufx/lib/Types.java index 0e87a1c..043a5a3 100644 --- a/app/src/main/java/com/annimon/hotarufx/lib/Types.java +++ b/app/src/main/java/com/annimon/hotarufx/lib/Types.java @@ -7,5 +7,6 @@ public class Types { NUMBER = 1, STRING = 2, MAP = 3, - FUNCTION = 4; + NODE = 4, + FUNCTION = 5; }