mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-22 22:27:30 +08:00
Byte pin type
This commit is contained in:
@@ -20,6 +20,7 @@ export default class Configuration {
|
||||
"default": css`167, 167, 167`,
|
||||
"exec": css`240, 240, 240`,
|
||||
"int": css`32, 224, 173`,
|
||||
"int64": css`170, 224, 172`,
|
||||
"name": css`203, 129, 252`,
|
||||
"real": css`50, 187, 0`,
|
||||
"string": css`213, 0, 176`,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import BoolInputPinTemplate from "../template/pin/BoolPinTemplate"
|
||||
import BytePinTemplate from "../template/pin/BytePinTemplate"
|
||||
import Configuration from "../Configuration"
|
||||
import ElementFactory from "./ElementFactory"
|
||||
import ExecPinTemplate from "../template/pin/ExecPinTemplate"
|
||||
@@ -37,10 +38,12 @@ export default class PinElement extends IElement {
|
||||
static #inputPinTemplates = {
|
||||
"/Script/CoreUObject.LinearColor": LinearColorInputPinTemplate,
|
||||
"/Script/CoreUObject.Rotator": RotatorInputPinTemplate,
|
||||
"/Script/CoreUObject.Vector2D": Vector2DPinTemplate,
|
||||
"/Script/CoreUObject.Vector": VectorPinTemplate,
|
||||
"/Script/CoreUObject.Vector2D": Vector2DPinTemplate,
|
||||
"bool": BoolInputPinTemplate,
|
||||
"byte": BytePinTemplate,
|
||||
"int": IntInputPinTemplate,
|
||||
"int64": IntInputPinTemplate,
|
||||
"MUTABLE_REFERENCE": ReferencePinTemplate,
|
||||
"name": NameInputPinTemplate,
|
||||
"real": RealInputPinTemplate,
|
||||
|
||||
24
js/entity/ByteEntity.js
Executable file
24
js/entity/ByteEntity.js
Executable file
@@ -0,0 +1,24 @@
|
||||
import IntegerEntity from "./IntegerEntity"
|
||||
|
||||
export default class ByteEntity extends IntegerEntity {
|
||||
|
||||
static attributes = {
|
||||
value: 0,
|
||||
}
|
||||
|
||||
/** @param {Object | Number | String} values */
|
||||
constructor(values = 0) {
|
||||
super(values)
|
||||
/** @type {Number} */
|
||||
const value = Math.round(this.value)
|
||||
this.value = value >= 0 && value < 1 << 8 ? value : 0
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import VariableReferenceEntity from "../entity/VariableReferenceEntity"
|
||||
import Vector2DEntity from "../entity/Vector2DEntity"
|
||||
import VectorEntity from "../entity/VectorEntity"
|
||||
import SimpleSerializationVector2DEntity from "../entity/SimpleSerializationVector2DEntity"
|
||||
import ByteEntity from "../entity/ByteEntity"
|
||||
|
||||
let P = Parsimmon
|
||||
|
||||
@@ -61,6 +62,8 @@ export default class Grammar {
|
||||
)
|
||||
case Boolean:
|
||||
return r.Boolean
|
||||
case ByteEntity:
|
||||
return r.Byte
|
||||
case FunctionReferenceEntity:
|
||||
return r.FunctionReference
|
||||
case GuidEntity:
|
||||
@@ -241,6 +244,13 @@ export default class Grammar {
|
||||
/** @param {Grammar} r */
|
||||
Integer = r => P.regex(/[\-\+]?[0-9]+/).map(v => new IntegerEntity(v)).desc("an integer")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Byte = r => P.regex(/\+?[0-9]+/)
|
||||
.map(v => parseInt(v))
|
||||
.assert(v => v >= 0 && v < 1 << 8)
|
||||
.map(v => new ByteEntity(v))
|
||||
.desc("a Byte")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
Guid = r => r.HexDigit.times(32).tie().map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal value")
|
||||
|
||||
|
||||
29
js/template/pin/BytePinTemplate.js
Normal file
29
js/template/pin/BytePinTemplate.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { html } from "lit"
|
||||
import ByteEntity from "../../entity/ByteEntity"
|
||||
import IInputPinTemplate from "./IInputPinTemplate"
|
||||
import INumericInputPinTemplate from "./INumericInputPinTemplate"
|
||||
|
||||
/** @typedef {import("../../entity/IntegerEntity").default} IntEntity */
|
||||
|
||||
/** @extends INumericInputPinTemplate<ByteEntity> */
|
||||
export default class IntInputPinTemplate extends INumericInputPinTemplate {
|
||||
|
||||
setDefaultValue(values = [], rawValues = values) {
|
||||
const integer = this.element.getDefaultValue(true)
|
||||
if (!(integer instanceof ByteEntity)) {
|
||||
throw new TypeError("Expected DefaultValue to be a ByteEntity")
|
||||
}
|
||||
integer.value = values[0]
|
||||
this.element.requestUpdate("DefaultValue", integer)
|
||||
}
|
||||
|
||||
renderInput() {
|
||||
return html`
|
||||
<div class="ueb-pin-input">
|
||||
<ueb-input .singleLine="${true}"
|
||||
.innerText="${IInputPinTemplate.stringFromUEToInput(this.element.getDefaultValue()?.toString() ?? "0")}">
|
||||
</ueb-input>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,8 @@ import INumericInputPinTemplate from "./INumericInputPinTemplate"
|
||||
export default class IntInputPinTemplate extends INumericInputPinTemplate {
|
||||
|
||||
setDefaultValue(values = [], rawValues = values) {
|
||||
let value = parseInt(values[0])
|
||||
const integer = this.element.getDefaultValue(true)
|
||||
if (!(integer instanceof IntegerEntity)) {
|
||||
throw new TypeError("Expected DefaultValue to be a IntegerEntity")
|
||||
}
|
||||
integer.value = values[0]
|
||||
this.element.requestUpdate("DefaultValue", integer)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export default class RealInputPinTemplate extends INumericPinTemplate {
|
||||
return html`
|
||||
<div class="ueb-pin-input">
|
||||
<ueb-input .singleLine="${true}"
|
||||
.innerText="${IInputPinTemplate.stringFromUEToInput(Utility.minDecimals(this.element.entity.DefaultValue ?? 0))}">
|
||||
.innerText="${IInputPinTemplate.stringFromUEToInput(Utility.minDecimals(this.element.getDefaultValue() ?? 0))}">
|
||||
</ueb-input>
|
||||
</div>
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user