${this.conf.value.toPrecision(3)}
effect
attr
`;
}
graph?: SyncedGraph;
ctx: NamedNode = new NamedNode(showRoot + "/fade");
@property() uri!: NamedNode;
@state() conf?: EffectFader; // compiled from graph
constructor() {
super();
getTopGraph().then((g) => {
this.graph = g;
this.graph.runHandler(this.compile.bind(this, this.graph), `fader config ${this.uri.value}`);
});
}
private compile(graph: SyncedGraph) {
const U = graph.U();
this.conf = undefined;
const conf = new EffectFader(this.uri);
if (!graph.contains(this.uri, U("rdf:type"), U(":Fader"))) {
// not loaded yet, perhaps
return;
}
conf.column = maybeStringValue(graph, this.uri, U(":column")) || "unset";
conf.effect = maybeUriValue(graph, this.uri, U(":effect"));
conf.effectAttr = get2Step(RETURN_URI, graph, this.uri, U(":setting"), U(":effectAttr"));
this.conf = conf;
graph.runHandler(this.compileValue.bind(this, graph, this.conf), `fader config.value ${this.uri.value}`);
}
private compileValue(graph: SyncedGraph, conf: EffectFader) {
// external graph change -> conf.value
const U = graph.U();
conf.value = get2Step(RETURN_FLOAT, graph, this.uri, U(":setting"), U(":value"));
// since conf attrs aren't watched as property:
this.requestUpdate()
}
onSliderInput(ev: CustomEvent) {
// slider user input -> graph
if (this.conf === undefined) return;
this.conf.value = ev.detail.value
this.writeValueToGraph()
}
writeValueToGraph() {
// this.value -> graph
if (this.graph === undefined) {
return;
}
const U = this.graph.U();
if (this.conf === undefined) {
return;
}
if (this.conf.value === undefined) {
log(`value of ${this.uri} is undefined`)
return;
}
log('writeValueToGraph', this.conf.value)
const valueTerm = this.graph.LiteralRoundedFloat(this.conf.value);
const settingNode = this.graph.uriValue(this.uri, U(":setting"));
this.graph.patchObject(settingNode, this.graph.Uri(":value"), valueTerm, this.ctx);
}
onEffectChange(ev: CustomEvent) {
if (this.graph === undefined) {
return;
}
const { newValue } = ev.detail;
this.graph.patchObject(this.uri, this.graph.Uri(":effect"), newValue, this.ctx);
}
onEffectAttrChange(ev: CustomEvent) {
if (this.graph === undefined) {
return;
}
// const { newValue } = ev.detail;
// if (this.setting === undefined) {
// this.setting = this.graph.nextNumberedResource(this.graph.Uri(":fade_set"));
// this.graph.patchObject(this.uri, this.graph.Uri(":setting"), this.setting, this.ctx);
// }
// this.graph.patchObject(this.setting, this.graph.Uri(":effectAttr"), newValue, this.ctx);
}
}