Input system further simplified

This commit is contained in:
barsdeveloper
2021-10-04 21:35:01 +02:00
parent 5963836947
commit 0563663dfc
5 changed files with 69 additions and 102 deletions

23
js/input/UPointing.js Normal file
View File

@@ -0,0 +1,23 @@
import Utility from "../Utility"
export default class UPointing {
constructor(target, blueprint, options) {
/** @type {HTMLElement} */
this.target = target
/** @type {import("../UEBlueprint").default}" */
this.blueprint = blueprint
this.moveEverywhere = options?.moveEverywhere ?? false
this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement
}
getLocation(mouseEvent) {
const scaleCorrection = 1 / Utility.getScale(this.target)
const targetOffset = this.movementSpace.getBoundingClientRect()
let location = [
(mouseEvent.clientX - targetOffset.x) * scaleCorrection,
(mouseEvent.clientY - targetOffset.y) * scaleCorrection
]
return location
}
}