Skip to content

Commit 01b7ed2

Browse files
committed
filter node creation list + bugfix in draggable value + added id to node types to be used in the serialized json + win nodes have an .update function to inform the node when it's props have changed
1 parent 0b50800 commit 01b7ed2

File tree

10 files changed

+103
-20
lines changed

10 files changed

+103
-20
lines changed

src/EditorNodes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ type Constructor<T extends WinNode> = new (...args: any[]) => T;
1010
export type NodeGroupType = {
1111
group:string
1212
color:string
13-
nodes:{ TypeClass:Constructor<WinNode>, name:string }[]
13+
nodes:{ TypeClass:Constructor<WinNode>, name:string, id:string }[]
1414
}
1515

1616
export const NodeTypes : NodeGroupType[] = [
1717
{
1818
group:"Attribute",
1919
color:Theme.config.groupAttribute as string,
2020
nodes:[
21-
{ TypeClass:UVNode, name:"UV" }
21+
{ TypeClass:UVNode, name:"UV", id:"uv" }
2222
]
2323
},
2424
{
2525
group:"Shader",
2626
color:Theme.config.groupShader as string,
2727
nodes:[
28-
{ TypeClass:MeshStandardNode, name:"Mesh Standard"}
28+
{ TypeClass:MeshStandardNode, name:"Mesh Standard", id:"mesh-standard-shader"}
2929
]
3030
},
3131
{
3232
group:"Texture",
3333
color:Theme.config.groupTexture as string,
3434
nodes:[
35-
{ TypeClass:ImageTextureNode, name:"Image Texture"}
35+
{ TypeClass:ImageTextureNode, name:"Image Texture", id:"image-texture"}
3636
]
3737
}
3838
]

src/components/DraggableValue.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export class DraggableValue extends InteractiveLayoutElement {
3434
}
3535
set value( v:number ) {
3636

37+
const oldValue = this._value;
3738
this._value = clamp( v , 0, 1);
39+
if( oldValue!=this._value )
40+
this.onChange?.( this._value, this.min + Math.floor(((this.max-this.min)*this._value)/this.step)*this.step );
3841

3942
}
4043

@@ -66,13 +69,9 @@ export class DraggableValue extends InteractiveLayoutElement {
6669

6770
override onMouseMove(deltaX: number, deltaY: number): void {
6871
this.dragOriginX += deltaX;
69-
70-
const oldValue = this._value;
71-
72+
7273
this.value = this.dragOriginX / this.hitArea.w ;
73-
74-
if( oldValue!=this._value )
75-
this.onChange?.( this._value, this.min + Math.floor(((this.max-this.min)*this._value)/this.step)*this.step );
74+
7675

7776
}
7877
override onMouseDown(cursorX: number, cursorY: number): void {

src/core/CanvasElement.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,12 @@ export class CanvasElement {
7070
ctx.shadowColor = 'rgba(0, 0, 0, 0.5)'; // Color of the shadow (semi-transparent black)
7171
}
7272
}
73-
73+
74+
serialize():Record<string, any> {
75+
return {}
76+
}
77+
78+
unserialize( data:Record<string, any> ) {
79+
80+
}
7481
}

src/nodes/WinNode.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@ export class WinNode extends Node {
2020
direction:"column"
2121
}));
2222
}
23+
24+
/**
25+
* Call this when the node had something changed or needs to be udated
26+
*/
27+
update() {
28+
console.log("UPDATE NODE")
29+
//... update and...
30+
this.somethingChanged();
31+
}
2332
}

src/nodes/preview/ScenePreview.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@ import { WinNode } from "../WinNode";
66
import { ThreeScene } from "../../ThreeScene";
77

88
export class ScenePreviewNode extends WinNode {
9+
10+
protected materialSlots:MaterialProperty[];
11+
912
constructor( protected scene:ThreeScene ) {
1013

1114
const ambientLightSlider = new DraggableValue("Ambient light", true, 0, 3, 0.1, (_, intensity)=>this.onAmbientLightSlider(intensity) );
1215

13-
super("Scene Preview", Theme.config.groupOutput, [
14-
ambientLightSlider,
15-
new DraggableValue("Rotation speed", true, 0, 2, 0.1),
16+
const materialSlots = [
1617
new MaterialProperty(0),
1718
new MaterialProperty(1),
1819
new MaterialProperty(2),
20+
]
21+
super("Scene Preview", Theme.config.groupOutput, [
22+
ambientLightSlider,
23+
new DraggableValue("Rotation speed", true, 0, 2, 0.1),
24+
...materialSlots
1925
]);
2026

2127
this.canBeDeleted = false;
28+
this.materialSlots = materialSlots;
2229

2330
ambientLightSlider.value = this.scene.ambientLight.intensity;
2431
}
@@ -29,6 +36,6 @@ export class ScenePreviewNode extends WinNode {
2936
}
3037

3138
protected override somethingChanged(): void {
32-
alert("Got it! recompile!!")
39+
3340
}
3441
}

src/properties/OutletProperty.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { FillStyle, Theme } from "../colors/Theme";
22
import { IOutlet, OutletSize } from "../core/IOutlet";
33
import { LayoutElement } from "../layout/LayoutElement";
44
import { Node } from "../nodes/Node";
5+
import { WinNodeProperty } from "./WinNodeProperty";
56

67
/**
78
* A property that renders a tiny colored dot indicating a place to plug a pipe to connect nodes.
89
*/
9-
export class OutletProperty extends LayoutElement implements IOutlet
10+
export class OutletProperty extends WinNodeProperty implements IOutlet
1011
{
1112
private _globalX = 0;
1213
private _globalY = 0;

src/properties/UVChannelProperty.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import { Input } from "./Input";
55

66
export class UVChannelProperty extends Input
77
{
8+
private slider:DraggableValue;
9+
810
constructor() {
911
super( 1 )
1012

13+
this.slider = new DraggableValue("UV Channel", false, 0, 5, 1, ()=>this.node.update());
14+
1115
//"column","space-around","stretch",
1216
this.layout = new Layout([
13-
new DraggableValue("UV Channel", false, 0, 5, 1)
17+
this.slider
1418
], {
1519
direction:"column",
1620
justify:"space-around",

src/properties/WinNodeProperty.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { LayoutElement } from "../layout/LayoutElement";
2+
import { WinNode } from "../nodes/WinNode";
3+
4+
/**
5+
* Every property of a Win Node should extend this, so it was access to the `node` they are in...
6+
*/
7+
export class WinNodeProperty extends LayoutElement {
8+
get node() {
9+
return this.root as WinNode;
10+
}
11+
}

src/ui/NodeSelectionModal.module.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
border-radius: 5px;
1010
}
1111

12+
.groupLabel {
13+
display: none;
14+
margin-right: 10px;
15+
}
16+
17+
.root.term .groupTitle, .root ul .groupTitle {
18+
display: none;
19+
}
20+
.root.term .groupLabel, .root.term ul .groupTitle {
21+
display: inline;
22+
}
23+
1224
.root ul {
1325
margin: 0px;
1426
padding: 0px;
@@ -27,7 +39,7 @@
2739
.groupTitle {
2840
padding: 3px 10px;
2941
font-size: 0.8em;
30-
display: inline-block;
42+
display: inline;
3143
border-radius: 5px;
3244
}
3345

src/ui/NodeSelectionModal.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ class NodeSelector {
2828

2929
this.div.addEventListener("mousedown", ev=>{
3030
ev.stopImmediatePropagation()
31-
})
31+
});
32+
33+
//
34+
// Autocomplete
35+
//
36+
let autocompleteIntrv = 0;
37+
this.input.addEventListener("keyup", ev=>{
38+
clearInterval(autocompleteIntrv);
39+
autocompleteIntrv = setTimeout(()=>this.filterList(),300);
40+
});
3241

3342
// render types!
3443
//#region Node Types
@@ -46,7 +55,17 @@ class NodeSelector {
4655

4756
const li = ul.appendChild( document.createElement("li"));
4857

49-
li.innerText = "→" + node.name;
58+
li.setAttribute("node-id", node.id);
59+
li.setAttribute("node-name", node.name);
60+
61+
const groupLabel = li.appendChild( document.createElement("div") );
62+
const label = li.appendChild( document.createElement("span") );
63+
label.innerText = "→" + node.name;
64+
65+
groupLabel.classList.add(styles.groupTitle)
66+
groupLabel.style.backgroundColor = groupType.color;
67+
groupLabel.innerText = groupType.group;
68+
5069
li.addEventListener("click", ev=>this.addNewNode(new node.TypeClass))
5170

5271
});
@@ -64,6 +83,19 @@ class NodeSelector {
6483
return !this.div.classList.contains(styles.hide)
6584
}
6685

86+
private filterList() {
87+
const term = this.input.value.toLowerCase();
88+
this.div.classList.remove( styles.term );
89+
if( term!=="" ) this.div.classList.add( styles.term );
90+
this.div.querySelectorAll("li").forEach( li => {
91+
const match = term=="" || li.getAttribute("node-name")?.toLowerCase().includes(term);
92+
li.classList.remove(styles.hide);
93+
if(!match){
94+
li.classList.add( styles.hide )
95+
}
96+
})
97+
}
98+
6799
private addNewNode( node:WinNode )
68100
{
69101
this._onCreated?.(node);
@@ -83,6 +115,7 @@ class NodeSelector {
83115

84116
this.input.value="";
85117
this.input.focus()
118+
this.filterList()
86119

87120
this._onCreated = onCreated;
88121
}

0 commit comments

Comments
 (0)