mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-16 10:54:42 +08:00
Serialization fixed
This commit is contained in:
26
js/input/Copy.js
Normal file
26
js/input/Copy.js
Normal 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.copyHandle = _ => self.copied()
|
||||
}
|
||||
|
||||
blueprintFocused() {
|
||||
document.body.addEventListener("copy", this.copyHandle)
|
||||
}
|
||||
|
||||
blueprintUnfocused() {
|
||||
document.body.removeEventListener("copy", this.copyHandle)
|
||||
}
|
||||
|
||||
copied() {
|
||||
const value = this.blueprint.getNodes(true).map(node => this.serializer.write(node.entity)).join("\n")
|
||||
navigator.clipboard.writeText(value)
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,7 @@ 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"))
|
||||
}
|
||||
@@ -33,8 +31,11 @@ export default class Paste extends Context {
|
||||
})
|
||||
let mousePosition = this.blueprint.entity.mousePosition
|
||||
nodes.forEach(node => {
|
||||
node.location[0] += mousePosition[0] - left
|
||||
node.location[1] += mousePosition[1] - top
|
||||
const locationOffset = [
|
||||
mousePosition[0] - left,
|
||||
mousePosition[1] - top
|
||||
]
|
||||
node.addLocation(locationOffset)
|
||||
})
|
||||
this.blueprint.addNode(...nodes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user