-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,87 @@ | ||
import ObjectNode from "./ObjectNode.js"; | ||
import ValueNode from "./ValueNode.js"; | ||
|
||
/** | ||
* @typedef {import("./BaseNode.js").BaseNodeDelta} BaseNodeDelta | ||
* @typedef {import("./ValueNode.js").ValueNodeDelta} ValueNodeDelta | ||
* @typedef {import("./ObjectNode.js").ObjectInterface} ObjectInterface | ||
* @typedef {{r: number, g: number, b: number}} ColorValue | ||
* @typedef {BaseNodeDelta & {properties?: {r?: ValueNodeDelta, g?: ValueNodeDelta, b?: ValueNodeDelta}}} ColorDelta | ||
* @typedef {(node: ColorNode) => void} onChangedFunc | ||
*/ | ||
|
||
class ColorNode extends ObjectNode { | ||
static TYPE = "Object.Color"; | ||
|
||
/** @type {onChangedFunc|null} */ | ||
#onChanged | ||
Check warning on line 17 in libraries/objectDefaultFiles/scene/ColorNode.js GitHub Actions / build (18.x)
|
||
|
||
/** | ||
* | ||
* @param {ObjectInterface} listener | ||
* @param {ObjectInterface} value | ||
*/ | ||
constructor(listener) { | ||
super(listener, ColorNode.TYPE); | ||
constructor(value = {r: 0, g: 0, b: 0}) { | ||
super(ColorNode.TYPE); | ||
this.#addValue("r", value.r); | ||
this.#addValue("g", value.g); | ||
this.#addValue("b", value.b); | ||
this.#onChanged = null; | ||
} | ||
|
||
/** | ||
* @param {ColorValue} value | ||
* | ||
Check warning on line 32 in libraries/objectDefaultFiles/scene/ColorNode.js GitHub Actions / build (18.x)
|
||
* @param {string} key | ||
Check warning on line 33 in libraries/objectDefaultFiles/scene/ColorNode.js GitHub Actions / build (18.x)
|
||
* @param {number} value | ||
Check warning on line 34 in libraries/objectDefaultFiles/scene/ColorNode.js GitHub Actions / build (18.x)
|
||
*/ | ||
setValue(value) { | ||
this.get("r").value = value.r; | ||
this.get("g").value = value.g; | ||
this.get("b").value = value.b; | ||
#addValue(key, value) { | ||
const node = new ValueNode(value); | ||
node.onChanged = (_node) => {this.#safeOnChanged();}; | ||
this._set(key, node); | ||
} | ||
|
||
/** | ||
* | ||
Check warning on line 43 in libraries/objectDefaultFiles/scene/ColorNode.js GitHub Actions / build (18.x)
|
||
*/ | ||
#safeOnChanged() { | ||
if (this.#onChanged) { | ||
this.#onChanged(this); | ||
} | ||
} | ||
|
||
/** | ||
* @returns {onChangedFunc} | ||
Check warning on line 52 in libraries/objectDefaultFiles/scene/ColorNode.js GitHub Actions / build (18.x)
|
||
*/ | ||
get onChanged() { | ||
return this.#onChanged; | ||
} | ||
|
||
Check warning on line 57 in libraries/objectDefaultFiles/scene/ColorNode.js GitHub Actions / build (18.x)
|
||
/** | ||
* @param {onChangedFunc} onChanged | ||
*/ | ||
set onChanged(onChanged) { | ||
this.#onChanged = onChanged; | ||
} | ||
|
||
/** | ||
* | ||
* @returns {ColorValue} | ||
*/ | ||
getValue() { | ||
get value() { | ||
return { | ||
"r": this.get("r").value, | ||
"g": this.get("g").value, | ||
"b": this.get("b").value | ||
}; | ||
} | ||
|
||
/** | ||
* @param {ColorValue} value | ||
*/ | ||
set value(value) { | ||
this.get("r").value = value.r; | ||
this.get("g").value = value.g; | ||
this.get("b").value = value.b; | ||
} | ||
} | ||
|
||
export default ColorNode; |