Remove _ctor pattern from Node & Group (#248)

Convert to initializers
This commit is contained in:
filtered
2024-11-02 14:12:03 +11:00
committed by GitHub
parent 94f1ca4279
commit c0217dbb7e
2 changed files with 20 additions and 53 deletions

View File

@@ -15,31 +15,20 @@ export class LGraphGroup {
color: string
title: string
font?: string
font_size: number
_bounding: Float32Array
_pos: Point
_size: Size
_nodes: LGraphNode[]
graph?: LGraph
flags: IGraphGroupFlags
font_size: number = LiteGraph.DEFAULT_GROUP_FONT || 24
_bounding: Float32Array = new Float32Array([10, 10, 140, 80])
_pos: Point = this._bounding.subarray(0, 2)
_size: Size = this._bounding.subarray(2, 4)
_nodes: LGraphNode[] = []
graph: LGraph | null = null
flags: IGraphGroupFlags = {}
selected?: boolean
constructor(title?: string) {
this._ctor(title)
}
_ctor(title?: string): void {
this.title = title || "Group"
this.font_size = LiteGraph.DEFAULT_GROUP_FONT || 24
this.color = LGraphCanvas.node_colors.pale_blue
? LGraphCanvas.node_colors.pale_blue.groupcolor
: "#AAA"
this._bounding = new Float32Array([10, 10, 140, 80])
this._pos = this._bounding.subarray(0, 2)
this._size = this._bounding.subarray(2, 4)
this._nodes = []
this.graph = null
this.flags = {}
}
/** Position of the group, as x,y co-ordinates in graph space */

View File

@@ -121,17 +121,17 @@ export class LGraphNode {
static filter?: string
static skip_list?: boolean
title?: string
graph: LGraph
title: string
graph: LGraph | null = null
id?: NodeId
type?: string
inputs: INodeInputSlot[]
outputs: INodeOutputSlot[]
type: string | null = null
inputs: INodeInputSlot[] = []
outputs: INodeOutputSlot[] = []
// Not used
connections: unknown[]
properties: INodeProperties
properties_info: INodePropertyInfo[]
flags: INodeFlags
connections: unknown[] = []
properties: INodeProperties = {}
properties_info: INodePropertyInfo[] = []
flags: INodeFlags = {}
widgets?: IWidget[]
size: Size
@@ -153,8 +153,8 @@ export class LGraphNode {
widgets_start_y?: number
lostFocusAt?: number
gotFocusAt?: number
badges: (LGraphBadge | (() => LGraphBadge))[]
badgePosition: BadgePosition
badges: (LGraphBadge | (() => LGraphBadge))[] = []
badgePosition: BadgePosition = BadgePosition.TopLeft
onOutputRemoved?(this: LGraphNode, slot: number): void
onInputRemoved?(this: LGraphNode, slot: number, input: INodeInputSlot): void
_collapsed_width: number
@@ -182,7 +182,7 @@ export class LGraphNode {
block_delete?: boolean
showAdvanced?: boolean
_pos: Point
_pos: Point = new Float32Array([10, 10])
public get pos() {
return this._pos
}
@@ -288,31 +288,9 @@ export class LGraphNode {
isValidWidgetLink?(slot_index: number, node: LGraphNode, overWidget: IWidget): boolean | undefined
constructor(title: string) {
this._ctor(title)
}
_ctor(title: string): void {
this.id = LiteGraph.use_uuids ? LiteGraph.uuidv4() : -1
this.title = title || "Unnamed"
this.size = [LiteGraph.NODE_WIDTH, 60]
this.graph = null
// Initialize _pos with a Float32Array of length 2, default value [10, 10]
this._pos = new Float32Array([10, 10])
this.id = LiteGraph.use_uuids ? LiteGraph.uuidv4() : -1
this.type = null
//inputs available: array of inputs
this.inputs = []
this.outputs = []
this.connections = []
this.badges = []
this.badgePosition = BadgePosition.TopLeft
//local data
this.properties = {} //for the values
this.properties_info = [] //for the info
this.flags = {}
}
/**