Material nodes wip, various refactoring

This commit is contained in:
barsdeveloper
2023-04-25 22:31:21 +02:00
parent dd25a75c02
commit b96746d1d9
36 changed files with 776 additions and 538 deletions

View File

@@ -34,5 +34,6 @@ export default class Copy extends IInput {
copied() {
const value = this.getSerializedText()
navigator.clipboard.writeText(value)
return value
}
}

39
js/input/common/Cut.js Executable file
View File

@@ -0,0 +1,39 @@
import IInput from "../IInput.js"
import ObjectSerializer from "../../serialization/ObjectSerializer.js"
import KeyboardCanc from "../keybaord/KeyboardCanc.js"
export default class Cut extends IInput {
static #serializer = new ObjectSerializer()
/** @type {(e: ClipboardEvent) => void} */
#cutHandler
constructor(target, blueprint, options = {}) {
options.listenOnFocus ??= true
options.unlistenOnTextEdit ??= true // No nodes copy if inside a text field, just text (default behavior)
super(target, blueprint, options)
let self = this
this.#cutHandler = _ => self.cut()
}
listenEvents() {
window.addEventListener("cut", this.#cutHandler)
}
unlistenEvents() {
window.removeEventListener("cut", this.#cutHandler)
}
getSerializedText() {
return this.blueprint
.getNodes(true)
.map(node => Cut.#serializer.write(node.entity, false))
.join("")
}
cut() {
this.blueprint.template.getCopyInputObject().copied()
this.blueprint.template.getInputObject(KeyboardCanc).fire()
}
}

View File

@@ -1,5 +1,5 @@
import Configuration from "../../Configuration.js"
import IKeyboardShortcut from "./IKeyboardShortcut.js"
import Shortcut from "../../Shortcut.js"
/** @typedef {import("../../Blueprint.js").default} Blueprint */
@@ -11,7 +11,7 @@ export default class KeyboardCanc extends IKeyboardShortcut {
* @param {Object} options
*/
constructor(target, blueprint, options = {}) {
options.activationKeys = Configuration.deleteNodesKeyboardKey
options.activationKeys = Shortcut.deleteNodes
super(target, blueprint, options)
}

View File

@@ -1,5 +1,5 @@
import Configuration from "../../Configuration.js"
import IKeyboardShortcut from "./IKeyboardShortcut.js"
import Shortcut from "../../Shortcut.js"
import Zoom from "../mouse/Zoom.js"
/** @typedef {import("../../Blueprint.js").default} Blueprint */
@@ -15,7 +15,7 @@ export default class KeyboardEnableZoom extends IKeyboardShortcut {
* @param {Object} options
*/
constructor(target, blueprint, options = {}) {
options.activationKeys = Configuration.enableZoomIn
options.activationKeys = Shortcut.enableZoomIn
super(target, blueprint, options)
}

View File

@@ -1,5 +1,5 @@
import Configuration from "../../Configuration.js"
import IKeyboardShortcut from "./IKeyboardShortcut.js"
import Shortcut from "../../Shortcut.js"
/** @typedef {import("../../Blueprint.js").default} Blueprint */
@@ -11,7 +11,7 @@ export default class KeyboardSelectAll extends IKeyboardShortcut {
* @param {Object} options
*/
constructor(target, blueprint, options = {}) {
options.activationKeys = Configuration.selectAllKeyboardKey
options.activationKeys = Shortcut.selectAllNodes
super(target, blueprint, options)
}

View File

@@ -28,8 +28,8 @@ export default class MouseCreateLink extends IMouseClickDrag {
const b = this.enteredPin
const outputPin = a.isOutput() ? a : b
if (
a.nodeElement.getType() === Configuration.nodeType.knot
|| b.nodeElement.getType() === Configuration.nodeType.knot
a.nodeElement.getType() === Configuration.paths.knot
|| b.nodeElement.getType() === Configuration.paths.knot
) {
// A knot can be linked to any pin, it doesn't matter the type or input/output direction
this.link.setMessageCorrect()
@@ -79,7 +79,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
}
startDrag(location) {
if (this.target.nodeElement.getType() == Configuration.nodeType.knot) {
if (this.target.nodeElement.getType() == Configuration.paths.knot) {
this.#knotPin = this.target
}
/** @type {LinkElement} */
@@ -120,7 +120,7 @@ export default class MouseCreateLink extends IMouseClickDrag {
this.enteredPin = oppositePin
}
}
} else if (this.enteredPin.nodeElement.getType() === Configuration.nodeType.knot) {
} else if (this.enteredPin.nodeElement.getType() === Configuration.paths.knot) {
this.enteredPin = /** @type {KnotPinTemplate} */(this.enteredPin.template).getOppositePin()
}
if (!this.link.source.getLinks().find(ref => ref.equals(this.enteredPin.createPinReference()))) {