This commit is contained in:
barsdeveloper
2024-06-06 20:10:17 +02:00
parent 6d99db5fd1
commit ad4ba2c46d
12 changed files with 123 additions and 142 deletions

View File

@@ -1,3 +1,4 @@
import P from "parsernostrum"
import Configuration from "../Configuration.js"
import pinColor from "../decoding/pinColor.js"
import pinTitle from "../decoding/pinTitle.js"
@@ -31,7 +32,6 @@ import StringEntity from "./StringEntity.js"
import Vector2DEntity from "./Vector2DEntity.js"
import Vector4DEntity from "./Vector4DEntity.js"
import VectorEntity from "./VectorEntity.js"
import P from "parsernostrum"
/** @template {IEntity} T */
export default class PinEntity extends IEntity {
@@ -63,7 +63,6 @@ export default class PinEntity extends IEntity {
[Configuration.paths.vector4f]: SimpleSerializationVector4DEntity,
}
static attributes = {
...super.attributes,
PinId: GuidEntity.withDefault(),
PinName: StringEntity.withDefault(),
PinFriendlyName: AlternativesEntity.accepting(
@@ -75,12 +74,12 @@ export default class PinEntity extends IEntity {
PinToolTip: StringEntity,
Direction: StringEntity,
PinType: PinTypeEntity.withDefault().flagInlined(),
LinkedTo: ArrayEntity.of(PinReferenceEntity),
LinkedTo: ArrayEntity.of(PinReferenceEntity).withDefault().flagSilent(),
SubPins: ArrayEntity.of(PinReferenceEntity),
ParentPin: PinReferenceEntity,
DefaultValue:
ComputedTypeEntity.from(
/** @param {PinEntity} pinEntity */
// @ts-expect-error
pinEntity => pinEntity.getEntityType(true) ?? StringEntity
).flagSerialized(),
AutogeneratedDefaultValue: StringEntity,
@@ -147,7 +146,7 @@ export default class PinEntity extends IEntity {
}
getType() {
const category = this.PinType.PinCategory.toLocaleLowerCase()
const category = this.PinType.PinCategory.toString().toLocaleLowerCase()
if (category === "struct" || category === "class" || category === "object" || category === "type") {
return this.PinType.PinSubCategoryObject.path
}
@@ -181,7 +180,7 @@ export default class PinEntity extends IEntity {
}
}
if (category === "optional") {
switch (this.PinType.PinSubCategory) {
switch (this.PinType.PinSubCategory.toString()) {
case "red":
return "real"
case "rg":
@@ -230,7 +229,7 @@ export default class PinEntity extends IEntity {
}
isExecution() {
return this.PinType.PinCategory === "exec"
return this.PinType.PinCategory.toString() === "exec"
}
isHidden() {
@@ -238,11 +237,11 @@ export default class PinEntity extends IEntity {
}
isInput() {
return !this.bHidden && this.Direction != "EGPD_Output"
return !this.bHidden && this.Direction.toString() != "EGPD_Output"
}
isOutput() {
return !this.bHidden && this.Direction == "EGPD_Output"
return !this.bHidden && this.Direction.toString() == "EGPD_Output"
}
isLinked() {
@@ -255,12 +254,12 @@ export default class PinEntity extends IEntity {
* @returns true if it was not already linked to the tarket
*/
linkTo(targetObjectName, targetPinEntity) {
const linkFound = this.LinkedTo?.some(pinReferenceEntity =>
const linkFound = this.LinkedTo.values?.some(pinReferenceEntity =>
pinReferenceEntity.objectName.toString() == targetObjectName
&& pinReferenceEntity.pinGuid.valueOf() == targetPinEntity.PinId.valueOf()
)
if (!linkFound) {
(this.LinkedTo ??= []).push(new PinReferenceEntity(targetObjectName, targetPinEntity.PinId,))
this.LinkedTo.values.push(new PinReferenceEntity(targetObjectName, targetPinEntity.PinId,))
return true
}
return false // Already linked
@@ -272,12 +271,12 @@ export default class PinEntity extends IEntity {
* @returns true if it was linked to the target
*/
unlinkFrom(targetObjectName, targetPinEntity) {
const indexElement = this.LinkedTo?.findIndex(pinReferenceEntity => {
const indexElement = this.LinkedTo.values?.findIndex(pinReferenceEntity => {
return pinReferenceEntity.objectName.toString() == targetObjectName
&& pinReferenceEntity.pinGuid.valueOf() == targetPinEntity.PinId.valueOf()
})
if (indexElement >= 0) {
this.LinkedTo.splice(indexElement, 1)
this.LinkedTo.values.splice(indexElement, 1)
if (this.LinkedTo.length === 0 && PinEntity.attributes.LinkedTo.default === undefined) {
this.LinkedTo = undefined
}