Files
armorpaint/base/Sources/nodes/FloatNode.ts
T

67 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-01-17 18:53:31 +01:00
class FloatNode extends LogicNode {
value: f32;
2024-02-05 20:57:20 +01:00
image: image_t = null;
2024-01-17 18:53:31 +01:00
constructor(value = 0.0) {
super();
this.value = value;
}
override get = (from: i32, done: (a: any)=>void) => {
if (this.inputs.length > 0) this.inputs[0].get(done);
else done(this.value);
}
2024-02-05 20:57:20 +01:00
override getAsImage = (from: i32, done: (img: image_t)=>void) => {
2024-01-17 18:53:31 +01:00
if (this.inputs.length > 0) { this.inputs[0].getAsImage(done); return; }
2024-02-05 20:57:20 +01:00
if (this.image != null) image_unload(this.image);
2024-01-17 18:53:31 +01:00
let b = new ArrayBuffer(16);
let v = new DataView(b);
v.setFloat32(0, this.value, true);
v.setFloat32(4, this.value, true);
v.setFloat32(8, this.value, true);
v.setFloat32(12, 1.0, true);
2024-02-08 21:05:19 +01:00
this.image = image_from_bytes(b, 1, 1, tex_format_t.RGBA128);
2024-01-17 18:53:31 +01:00
done(this.image);
}
override set = (value: any) => {
if (this.inputs.length > 0) this.inputs[0].set(value);
else this.value = value;
}
2024-02-06 19:32:21 +01:00
static def: zui_node_t = {
2024-01-17 18:53:31 +01:00
id: 0,
name: _tr("Value"),
type: "FloatNode",
x: 0,
y: 0,
color: 0xffb34f5a,
inputs: [
{
id: 0,
node_id: 0,
name: _tr("Value"),
type: "VALUE",
color: 0xffa1a1a1,
default_value: 0.5,
min: 0.0,
max: 10.0
}
],
outputs: [
{
id: 0,
node_id: 0,
name: _tr("Value"),
type: "VALUE",
color: 0xffa1a1a1,
default_value: 0.5
}
],
buttons: []
};
}