mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-21 14:24:47 +08:00
Organizing input actions in device folders
This commit is contained in:
26
js/input/common/Copy.js
Executable file
26
js/input/common/Copy.js
Executable file
@@ -0,0 +1,26 @@
|
||||
import Context from "../Context"
|
||||
import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
|
||||
export default class Copy extends Context {
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
this.copyHandler = _ => self.copied()
|
||||
}
|
||||
|
||||
blueprintFocused() {
|
||||
document.body.addEventListener("copy", this.copyHandler)
|
||||
}
|
||||
|
||||
blueprintUnfocused() {
|
||||
document.body.removeEventListener("copy", this.copyHandler)
|
||||
}
|
||||
|
||||
copied() {
|
||||
const value = this.blueprint.getNodes(true).map(node => this.serializer.write(node.entity)).join("\n")
|
||||
navigator.clipboard.writeText(value)
|
||||
}
|
||||
}
|
||||
50
js/input/common/Paste.js
Executable file
50
js/input/common/Paste.js
Executable file
@@ -0,0 +1,50 @@
|
||||
import GraphNode from "../../graph/GraphNode"
|
||||
import ObjectSerializer from "../../serialization/ObjectSerializer"
|
||||
import Context from "../Context"
|
||||
|
||||
export default class Paste extends Context {
|
||||
|
||||
constructor(target, blueprint, options = {}) {
|
||||
options.wantsFocusCallback = true
|
||||
super(target, blueprint, options)
|
||||
this.serializer = new ObjectSerializer()
|
||||
let self = this
|
||||
this.pasteHandle = e => self.pasted(e.clipboardData.getData("Text"))
|
||||
}
|
||||
|
||||
blueprintFocused() {
|
||||
document.body.addEventListener("paste", this.pasteHandle)
|
||||
}
|
||||
|
||||
blueprintUnfocused() {
|
||||
document.body.removeEventListener("paste", this.pasteHandle)
|
||||
}
|
||||
|
||||
pasted(value) {
|
||||
let top = 0
|
||||
let left = 0
|
||||
let count = 0
|
||||
let nodes = this.serializer.readMultiple(value).map(entity => {
|
||||
let node = new GraphNode(entity)
|
||||
top += node.location[1]
|
||||
left += node.location[0]
|
||||
++count
|
||||
return node
|
||||
})
|
||||
top /= count
|
||||
left /= count
|
||||
if (nodes.length > 0) {
|
||||
this.blueprint.unselectAll()
|
||||
}
|
||||
let mousePosition = this.blueprint.entity.mousePosition
|
||||
this.blueprint.addGraphElement(...nodes)
|
||||
nodes.forEach(node => {
|
||||
const locationOffset = [
|
||||
mousePosition[0] - left,
|
||||
mousePosition[1] - top,
|
||||
]
|
||||
node.addLocation(this.blueprint.compensateTranslation(locationOffset))
|
||||
node.setSelected(true)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user