mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-21 13:47:37 +08:00
Rotator entity
This commit is contained in:
@@ -31,6 +31,10 @@ export default class BoolPinTemplate extends IInputPinTemplate {
|
||||
return [this.#input.checked ? "true" : "false"]
|
||||
}
|
||||
|
||||
setDefaultValue(pin, values = [], rawValues = values) {
|
||||
pin.setDefaultValue(values[0] == "true")
|
||||
}
|
||||
|
||||
/** @param {PinElement} pin */
|
||||
renderInput(pin) {
|
||||
if (pin.isInput()) {
|
||||
|
||||
@@ -32,13 +32,13 @@ export default class IInputPinTemplate extends PinTemplate {
|
||||
super.firstUpdated(pin, changedProperties)
|
||||
this.#inputContentElements = [...pin.querySelectorAll(".ueb-pin-input-content")]
|
||||
if (this.#inputContentElements.length) {
|
||||
this.setInputs(pin, this.getInputs(pin))
|
||||
this.setInputs(pin, this.getInputs(pin), false)
|
||||
let self = this
|
||||
this.onFocusHandler = _ => pin.blueprint.dispatchEditTextEvent(true)
|
||||
this.onFocusOutHandler = e => {
|
||||
e.preventDefault()
|
||||
document.getSelection()?.removeAllRanges() // Deselect text inside the input
|
||||
self.setInputs(pin, this.getInputs(pin))
|
||||
self.setInputs(pin, this.getInputs(pin), true)
|
||||
pin.blueprint.dispatchEditTextEvent(false)
|
||||
}
|
||||
this.#inputContentElements.forEach(element => {
|
||||
@@ -89,12 +89,14 @@ export default class IInputPinTemplate extends PinTemplate {
|
||||
(element, i) => element.innerText = values[i]
|
||||
)
|
||||
if (updateDefaultValue) {
|
||||
pin.setDefaultValue(values
|
||||
.map(v => IInputPinTemplate.stringFromInputToUE(v)) // Double newline at the end of a contenteditable element
|
||||
.reduce((acc, cur) => acc + cur, ""))
|
||||
this.setDefaultValue(pin, values.map(v => IInputPinTemplate.stringFromInputToUE(v)), values)
|
||||
}
|
||||
}
|
||||
|
||||
setDefaultValue(pin, values = [], rawValues = values) {
|
||||
pin.setDefaultValue(values.reduce((acc, cur) => acc + cur, ""))
|
||||
}
|
||||
|
||||
/** @param {PinElement} pin */
|
||||
renderInput(pin) {
|
||||
if (pin.isInput()) {
|
||||
|
||||
@@ -9,11 +9,11 @@ export default class RealPinTemplate extends IInputPinTemplate {
|
||||
* @param {PinElement} pin
|
||||
* @param {String[]?} values
|
||||
*/
|
||||
setInputs(pin, values = []) {
|
||||
setInputs(pin, values = [], updateDefaultValue = false) {
|
||||
if (!values || values.length == 0) {
|
||||
values = this.getInput(pin)
|
||||
}
|
||||
let updateDefaultValue = true
|
||||
let parsedValues = []
|
||||
for (let i = 0; i < values.length; ++i) {
|
||||
let num = parseFloat(values[i])
|
||||
if (isNaN(num)) {
|
||||
@@ -25,8 +25,14 @@ export default class RealPinTemplate extends IInputPinTemplate {
|
||||
num = 0
|
||||
updateDefaultValue = false
|
||||
}
|
||||
parsedValues.push(num)
|
||||
values[i] = Utility.minDecimals(num)
|
||||
}
|
||||
super.setInputs(pin, values, updateDefaultValue)
|
||||
super.setInputs(pin, values, false)
|
||||
this.setDefaultValue(pin, parsedValues, values)
|
||||
}
|
||||
|
||||
setDefaultValue(pin, values = [], rawValues = values) {
|
||||
pin.setDefaultValue(values[0])
|
||||
}
|
||||
}
|
||||
|
||||
41
js/template/RotatorPinTemplate.js
Normal file
41
js/template/RotatorPinTemplate.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { html } from "lit"
|
||||
import RotatorEntity from "../entity/RotatorEntity"
|
||||
import IInputPinTemplate from "./IInputPinTemplate"
|
||||
import RealPinTemplate from "./RealPinTemplate"
|
||||
|
||||
export default class RotatorPinTemplate extends RealPinTemplate {
|
||||
|
||||
setDefaultValue(pin, values = [], rawValues = values) {
|
||||
if (!(pin.entity.DefaultValue instanceof RotatorEntity)) {
|
||||
throw new TypeError("Expected DefaultValue to be a VectorEntity")
|
||||
}
|
||||
let rotator = pin.entity.DefaultValue
|
||||
rotator.R = values[0] // Roll
|
||||
rotator.P = values[1] // Pitch
|
||||
rotator.Y = values[2] // Yaw
|
||||
}
|
||||
|
||||
/** @param {PinElement} pin */
|
||||
renderInput(pin) {
|
||||
if (pin.isInput()) {
|
||||
return html`
|
||||
<span class="ueb-pin-input-label">X</span>
|
||||
<div class="ueb-pin-input">
|
||||
<span class="ueb-pin-input-content ueb-pin-input-x" role="textbox" contenteditable="true"
|
||||
.innerText="${IInputPinTemplate.stringFromUEToInput(pin.entity.getDefaultValue().R.toString())}"></span>
|
||||
</div>
|
||||
<span class="ueb-pin-input-label">Y</span>
|
||||
<div class="ueb-pin-input">
|
||||
<span class="ueb-pin-input-content ueb-pin-input-y" role="textbox" contenteditable="true"
|
||||
.innerText="${IInputPinTemplate.stringFromUEToInput(pin.entity.getDefaultValue().P.toString())}"></span>
|
||||
</div>
|
||||
<span class="ueb-pin-input-label">Z</span>
|
||||
<div class="ueb-pin-input">
|
||||
<span class="ueb-pin-input-content ueb-pin-input-z" role="textbox" contenteditable="true"
|
||||
.innerText="${IInputPinTemplate.stringFromUEToInput(pin.entity.getDefaultValue().Y.toString())}"></span>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
return html``
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { html } from "lit"
|
||||
import VectorEntity from "../entity/VectorEntity"
|
||||
import IInputPinTemplate from "./IInputPinTemplate"
|
||||
import RealPinTemplate from "./RealPinTemplate"
|
||||
|
||||
@@ -9,6 +10,16 @@ import RealPinTemplate from "./RealPinTemplate"
|
||||
|
||||
export default class VectorPinTemplate extends RealPinTemplate {
|
||||
|
||||
setDefaultValue(pin, values = [], rawValues = values) {
|
||||
if (!(pin.entity.DefaultValue instanceof VectorEntity)) {
|
||||
throw new TypeError("Expected DefaultValue to be a VectorEntity")
|
||||
}
|
||||
let vector = pin.entity.DefaultValue
|
||||
vector.X = values[0]
|
||||
vector.Y = values[1]
|
||||
vector.Z = values[2]
|
||||
}
|
||||
|
||||
/** @param {PinElement} pin */
|
||||
renderInput(pin) {
|
||||
if (pin.isInput()) {
|
||||
|
||||
Reference in New Issue
Block a user