mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-13 15:27:30 +08:00
Link implementation wip
This commit is contained in:
@@ -14,11 +14,11 @@ export default class GraphElement extends HTMLElement {
|
||||
*/
|
||||
constructor(entity, template) {
|
||||
super()
|
||||
/** @type {Blueprint}" */
|
||||
/** @type {Blueprint} */
|
||||
this.blueprint = null
|
||||
/** @type {Entity}" */
|
||||
/** @type {Entity} */
|
||||
this.entity = entity
|
||||
/** @type {Template}" */
|
||||
/** @type {Template} */
|
||||
this.template = template
|
||||
/** @type {Context[]} */
|
||||
this.inputObjects = []
|
||||
|
||||
@@ -3,7 +3,7 @@ import LinkTemplate from "../template/LinkTemplate"
|
||||
|
||||
|
||||
/**
|
||||
* @type {import("./GraphPin").default} GraphPin
|
||||
* @typedef {import("./GraphPin").default} GraphPin
|
||||
*/
|
||||
export default class GraphLink extends GraphElement {
|
||||
|
||||
@@ -20,19 +20,30 @@ export default class GraphLink extends GraphElement {
|
||||
* @param {?GraphPin} destination
|
||||
*/
|
||||
constructor(source, destination) {
|
||||
super(this, new LinkTemplate())
|
||||
super({}, new LinkTemplate())
|
||||
/** @type {import("../template/LinkTemplate").default} */
|
||||
this.template
|
||||
this.setSource(source)
|
||||
this.setDestination(destination)
|
||||
this.setSourcePin(source)
|
||||
this.setDestinationPin(destination)
|
||||
}
|
||||
|
||||
setSourceLocation(location) {
|
||||
this.template.applySourceLocation(this.#source.getLinkLocation())
|
||||
if (location == null) {
|
||||
location = this.#source.template.getLinkLocation(this.#source)
|
||||
}
|
||||
this.template.applySourceLocation(this, location)
|
||||
}
|
||||
|
||||
setDestinationLocation(location) {
|
||||
this.template.applyDestinationLocation(this.#destination.getLinkLocation())
|
||||
if (location == null) {
|
||||
location = this.#destination.template.getLinkLocation(this.#destination)
|
||||
}
|
||||
this.template.applyDestinationLocation(this, location)
|
||||
}
|
||||
|
||||
|
||||
getSourcePin() {
|
||||
return this.#source
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,6 +55,12 @@ export default class GraphLink extends GraphElement {
|
||||
this.#source = graphPin
|
||||
this.#source?.addEventListener("ueb-node-delete", this.#nodeDeleteHandler)
|
||||
this.#source?.addEventListener("ueb-node-drag", this.#nodeDragSourceHandler)
|
||||
this.setSourceLocation()
|
||||
this.originatesFromInput = this.#destination == null
|
||||
}
|
||||
|
||||
getDestinationPin() {
|
||||
return this.#destination
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,6 +73,7 @@ export default class GraphLink extends GraphElement {
|
||||
this.#destination = graphPin
|
||||
this.#destination?.addEventListener("ueb-node-delete", this.#nodeDeleteHandler)
|
||||
this.#destination?.addEventListener("ueb-node-drag", this.#nodeDragDestinatonHandler)
|
||||
this.originatesFromInput = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import NodeTemplate from "../template/NodeTemplate"
|
||||
import ObjectEntity from "../entity/ObjectEntity"
|
||||
import PinEntity from "../entity/PinEntity"
|
||||
import SelectableDraggable from "./SelectableDraggable"
|
||||
import SerializerFactory from "../serialization/SerializerFactory"
|
||||
import PinEntity from "../entity/PinEntity"
|
||||
|
||||
export default class GraphNode extends SelectableDraggable {
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import GraphElement from "./GraphElement"
|
||||
import PinTemplate from "../template/PinTemplate"
|
||||
import MouseCreateLink from "../input/mouse/MouseCreateLink"
|
||||
import GraphLink from "./GraphLink"
|
||||
|
||||
export default class GraphPin extends GraphElement {
|
||||
|
||||
@@ -9,6 +8,8 @@ export default class GraphPin extends GraphElement {
|
||||
super(entity, new PinTemplate())
|
||||
/** @type {import("../entity/PinEntity").default} */
|
||||
this.entity
|
||||
/** @type {PinTemplate} */
|
||||
this.template
|
||||
/** @type {HTMLElement} */
|
||||
this.clickableElement = null
|
||||
}
|
||||
@@ -16,7 +17,8 @@ export default class GraphPin extends GraphElement {
|
||||
createInputObjects() {
|
||||
return [
|
||||
new MouseCreateLink(this.clickableElement, this.blueprint, {
|
||||
moveEverywhere: true
|
||||
moveEverywhere: true,
|
||||
looseTarget: true
|
||||
}),
|
||||
]
|
||||
}
|
||||
@@ -49,15 +51,6 @@ export default class GraphPin extends GraphElement {
|
||||
return this.entity.getType()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {GraphLink} The link created
|
||||
*/
|
||||
dragLink() {
|
||||
let link = new GraphLink(this)
|
||||
return link
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The exact location where the link originates from or arrives at.
|
||||
* @returns {Number[]} The location array
|
||||
|
||||
Reference in New Issue
Block a user