mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Avoid using arrays when unnecessary
This commit is contained in:
@@ -21,8 +21,11 @@ export default class IDraggableControlElement extends IDraggableElement {
|
||||
this.windowElement = this.closest("ueb-window")
|
||||
}
|
||||
|
||||
/** @param {Number[]} param0 */
|
||||
setLocation([x, y]) {
|
||||
super.setLocation(this.template.adjustLocation([x, y]))
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
setLocation(x, y) {
|
||||
super.setLocation(...this.template.adjustLocation(x, y))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import Utility from "../Utility"
|
||||
/**
|
||||
* @typedef {import("../entity/IEntity").default} IEntity
|
||||
* @typedef {import("../template/IDraggableTemplate").default} IDraggableTemplate
|
||||
* @typedef {CustomEvent<{
|
||||
* value: [Number, Number]
|
||||
* }>} DragEvent
|
||||
* @typedef {import("lit").PropertyValues} PropertyValues
|
||||
*/
|
||||
|
||||
@@ -58,9 +61,13 @@ export default class IDraggableElement extends IElement {
|
||||
this.computeSizes()
|
||||
}
|
||||
|
||||
/** @param {Number[]} param0 */
|
||||
setLocation([x, y], acknowledge = true) {
|
||||
const d = [x - this.locationX, y - this.locationY]
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
setLocation(x, y, acknowledge = true) {
|
||||
const dx = x - this.locationX
|
||||
const dy = y - this.locationY
|
||||
this.locationX = x
|
||||
this.locationY = y
|
||||
if (this.blueprint && acknowledge) {
|
||||
@@ -68,7 +75,7 @@ export default class IDraggableElement extends IElement {
|
||||
/** @type {typeof IDraggableElement} */(this.constructor).dragEventName,
|
||||
{
|
||||
detail: {
|
||||
value: d,
|
||||
value: [dx, dy],
|
||||
},
|
||||
bubbles: false,
|
||||
cancelable: true,
|
||||
@@ -78,9 +85,12 @@ export default class IDraggableElement extends IElement {
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {Number[]} param0 */
|
||||
addLocation([x, y], acknowledge = true) {
|
||||
this.setLocation([this.locationX + x, this.locationY + y], acknowledge)
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
addLocation(x, y, acknowledge = true) {
|
||||
this.setLocation(this.locationX + x, this.locationY + y, acknowledge)
|
||||
}
|
||||
|
||||
/** @param {Number[]} value */
|
||||
@@ -99,9 +109,9 @@ export default class IDraggableElement extends IElement {
|
||||
}
|
||||
|
||||
snapToGrid() {
|
||||
const snappedLocation = Utility.snapToGrid([this.locationX, this.locationY], Configuration.gridSize)
|
||||
const snappedLocation = Utility.snapToGrid(this.locationX, this.locationY, Configuration.gridSize)
|
||||
if (this.locationX != snappedLocation[0] || this.locationY != snappedLocation[1]) {
|
||||
this.setLocation(snappedLocation)
|
||||
this.setLocation(snappedLocation[0], snappedLocation[1])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,15 +48,21 @@ export default class IFromToPositionedElement extends IElement {
|
||||
this.toY = y
|
||||
}
|
||||
|
||||
/** @param {Number[]} offset */
|
||||
addSourceLocation([offsetX, offsetY]) {
|
||||
this.fromX += offsetX
|
||||
this.fromY += offsetY
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
addSourceLocation(x, y) {
|
||||
this.fromX += x
|
||||
this.fromY += y
|
||||
}
|
||||
|
||||
/** @param {Number[]} offset */
|
||||
addDestinationLocation([offsetX, offsetY]) {
|
||||
this.toX += offsetX
|
||||
this.toY += offsetY
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
addDestinationLocation(x, y) {
|
||||
this.toX += x
|
||||
this.toY += y
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ import Utility from "../Utility"
|
||||
import IDraggableElement from "./IDraggableElement"
|
||||
|
||||
/**
|
||||
* @typedef {import("../template/ISelectableDraggableTemplate").default} ISelectableDraggableTemplate
|
||||
* @typedef {import("../element/IDraggableElement").DragEvent} DragEvent
|
||||
* @typedef {import("../entity/IEntity").default} IEntity
|
||||
* @typedef {import("../template/ISelectableDraggableTemplate").default} ISelectableDraggableTemplate
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -24,7 +25,8 @@ export default class ISelectableDraggableElement extends IDraggableElement {
|
||||
},
|
||||
}
|
||||
|
||||
dragHandler = e => this.addLocation(e.detail.value)
|
||||
/** @param {DragEvent} e */
|
||||
dragHandler = e => this.addLocation(...e.detail.value)
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
@@ -6,6 +6,7 @@ import SVGIcon from "../SVGIcon"
|
||||
import Utility from "../Utility"
|
||||
|
||||
/**
|
||||
* @typedef {import("../element/IDraggableElement").DragEvent} DragEvent
|
||||
* @typedef {import("./PinElement").default} PinElement
|
||||
* @typedef {import("lit").TemplateResult<1>} TemplateResult
|
||||
* @typedef {typeof LinkElement} LinkElementConstructor
|
||||
@@ -67,8 +68,10 @@ export default class LinkElement extends IFromToPositionedElement {
|
||||
}
|
||||
|
||||
#nodeDeleteHandler = () => this.remove()
|
||||
#nodeDragSourceHandler = e => this.addSourceLocation(e.detail.value)
|
||||
#nodeDragDestinatonHandler = e => this.addDestinationLocation(e.detail.value)
|
||||
/** @param {DragEvent} e */
|
||||
#nodeDragSourceHandler = e => this.addSourceLocation(...e.detail.value)
|
||||
/** @param {DragEvent} e */
|
||||
#nodeDragDestinatonHandler = e => this.addDestinationLocation(...e.detail.value)
|
||||
#nodeReflowSourceHandler = e => this.setSourceLocation()
|
||||
#nodeReflowDestinatonHandler = e => this.setDestinationLocation()
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import VariableConversionNodeTemplate from "../template/node/VariableConversionN
|
||||
import VariableOperationNodeTemplate from "../template/node/VariableOperationNodeTemplate"
|
||||
|
||||
/**
|
||||
* @typedef {import("./IDraggableElement").DragEvent} DragEvent
|
||||
* @typedef {import("./IElement").default} IElement
|
||||
* @typedef {import("./PinElement").default} PinElement
|
||||
* @typedef {typeof NodeElement} NodeElementConstructor
|
||||
@@ -22,9 +23,6 @@ import VariableOperationNodeTemplate from "../template/node/VariableOperationNod
|
||||
/** @extends {ISelectableDraggableElement<ObjectEntity, NodeTemplate>} */
|
||||
export default class NodeElement extends ISelectableDraggableElement {
|
||||
|
||||
static #typeTemplateMap = {
|
||||
}
|
||||
|
||||
static properties = {
|
||||
...ISelectableDraggableElement.properties,
|
||||
typePath: {
|
||||
@@ -84,12 +82,13 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
/** @type {NodeElement[]} */
|
||||
boundComments = []
|
||||
#commentDragged = false
|
||||
/** @param {DragEvent} e */
|
||||
#commentDragHandler = e => {
|
||||
// If selected, it will already drag, also must check if under nested comments, it must drag just once
|
||||
if (!this.selected && !this.#commentDragged) {
|
||||
this.#commentDragged = true
|
||||
this.addNextUpdatedCallbacks(() => this.#commentDragged = false)
|
||||
this.addLocation(e.detail.value)
|
||||
this.addLocation(...e.detail.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
this.nodeDisplayName = this.getNodeDisplayName()
|
||||
this.pureFunction = this.entity.bIsPureFunc
|
||||
this.dragLinkObjects = []
|
||||
super.setLocation([this.entity.NodePosX.value, this.entity.NodePosY.value])
|
||||
super.setLocation(this.entity.NodePosX.value, this.entity.NodePosY.value)
|
||||
if (this.entity.NodeWidth && this.entity.NodeHeight) {
|
||||
this.sizeX = this.entity.NodeWidth.value
|
||||
this.sizeY = this.entity.NodeHeight.value
|
||||
@@ -318,10 +317,10 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
return this.entity.CustomProperties.filter(v => v instanceof PinEntity)
|
||||
}
|
||||
|
||||
setLocation(value = [0, 0], acknowledge = true) {
|
||||
this.entity.NodePosX.value = value[0]
|
||||
this.entity.NodePosY.value = value[1]
|
||||
super.setLocation(value, acknowledge)
|
||||
setLocation(x = 0, y = 0, acknowledge = true) {
|
||||
this.entity.NodePosX.value = x
|
||||
this.entity.NodePosY.value = y
|
||||
super.setLocation(x, y, acknowledge)
|
||||
}
|
||||
|
||||
acknowledgeDelete() {
|
||||
|
||||
Reference in New Issue
Block a user