mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-15 17:54:52 +08:00
WIP
This commit is contained in:
131
dist/ueblueprint.js
vendored
131
dist/ueblueprint.js
vendored
@@ -613,37 +613,6 @@ class Utility {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Attribute} a
|
||||
* @param {Attribute} b
|
||||
*/
|
||||
static equals(a, b) {
|
||||
while (a instanceof MirroredEntity) {
|
||||
a = a.get();
|
||||
}
|
||||
while (b instanceof MirroredEntity) {
|
||||
b = b.get();
|
||||
}
|
||||
// Here we cannot check both instanceof IEntity because this would introduce a circular include dependency
|
||||
if (/** @type {IEntity?} */(a)?.equals && /** @type {IEntity?} */(b)?.equals) {
|
||||
return /** @type {IEntity} */(a).equals(/** @type {IEntity} */(b))
|
||||
}
|
||||
a = Utility.sanitize(a);
|
||||
b = Utility.sanitize(b);
|
||||
if (a?.constructor === BigInt && b?.constructor === Number) {
|
||||
b = BigInt(b);
|
||||
} else if (a?.constructor === Number && b?.constructor === BigInt) {
|
||||
a = BigInt(a);
|
||||
}
|
||||
if (a === b) {
|
||||
return true
|
||||
}
|
||||
if (a instanceof Array && b instanceof Array) {
|
||||
return a.length === b.length && a.every((value, i) => Utility.equals(value, b[i]))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
@@ -2381,30 +2350,24 @@ class IEntity {
|
||||
|
||||
/** @type {(v: String) => String} */
|
||||
static same = v => v
|
||||
|
||||
/** @type {(entity: IEntity, serialized: String) => String} */
|
||||
static notWrapped = (entity, serialized) => serialized
|
||||
|
||||
/** @type {(entity: IEntity, serialized: String) => String} */
|
||||
static defaultWrapped = (entity, serialized) => `${entity.lookbehind}(${serialized})`
|
||||
|
||||
static defaultWrapped = (entity, serialized) => `${entity.#lookbehind}(${serialized})`
|
||||
static wrap = this.defaultWrapped
|
||||
|
||||
static attributeSeparator = ","
|
||||
static keySeparator = "="
|
||||
|
||||
/** @type {(k: String) => String} */
|
||||
static printKey = k => k
|
||||
|
||||
/** @type {P<IEntity>} */
|
||||
static grammar = /** @type {any} */(Parsernostrum.failure())
|
||||
|
||||
/** @type {P<IEntity>} */
|
||||
static unknownEntityGrammar
|
||||
|
||||
static unknownEntity
|
||||
/** @type {{ [key: String]: typeof IEntity }} */
|
||||
static attributes = {}
|
||||
|
||||
/** @type {String | String[]} */
|
||||
static lookbehind = ""
|
||||
/** @type {(type: typeof IEntity) => InstanceType<typeof IEntity>} */
|
||||
static default
|
||||
static nullable = false
|
||||
@@ -2424,12 +2387,9 @@ class IEntity {
|
||||
this.#trailing = value;
|
||||
}
|
||||
|
||||
/** @type {String | String[]} */
|
||||
static lookbehind = ""
|
||||
|
||||
#lookbehind = /** @type {String} */(this.Self().lookbehind)
|
||||
get lookbehind() {
|
||||
return this.#lookbehind
|
||||
return this.#lookbehind.trim()
|
||||
}
|
||||
set lookbehind(value) {
|
||||
this.#lookbehind = value;
|
||||
@@ -2445,13 +2405,23 @@ class IEntity {
|
||||
}
|
||||
|
||||
constructor(values = {}) {
|
||||
const keys = Utility.mergeArrays(Object.keys(values), Object.keys(this.Self().attributes));
|
||||
const attributes = this.Self().attributes;
|
||||
const keys = Utility.mergeArrays(
|
||||
Object.keys(values),
|
||||
Object.entries(attributes).filter(([k, v]) => v.default !== undefined).map(([k, v]) => k)
|
||||
);
|
||||
for (const key of keys) {
|
||||
if (values[key] !== undefined) {
|
||||
if (values[key].constructor === Object) {
|
||||
// It is part of a nested key (words separated by ".")
|
||||
values[key] = new (
|
||||
attributes[key] !== undefined ? attributes[key] : IEntity.unknownEntity
|
||||
)(values[key]);
|
||||
}
|
||||
this[key] = values[key];
|
||||
continue
|
||||
}
|
||||
const attribute = this.Self().attributes[key];
|
||||
const attribute = attributes[key];
|
||||
if (attribute.default !== undefined) {
|
||||
this[key] = attribute.default(attribute);
|
||||
continue
|
||||
@@ -2854,7 +2824,7 @@ class Grammar {
|
||||
static createEntityGrammar(entityType, entriesSeparator = this.commaSeparation, complete = false, minKeys = 1) {
|
||||
const lookbehind = entityType.lookbehind instanceof Array ? entityType.lookbehind.join("|") : entityType.lookbehind;
|
||||
return Parsernostrum.seq(
|
||||
Parsernostrum.reg(new RegExp(String.raw`(${lookbehind})\s*\(\s*`), 1),
|
||||
Parsernostrum.reg(new RegExp(String.raw`(${lookbehind}\s*)\(\s*`), 1),
|
||||
this.createAttributeGrammar(entityType).sepBy(entriesSeparator, minKeys),
|
||||
Parsernostrum.reg(/\s*(,\s*)?\)/, 1), // optional trailing comma
|
||||
)
|
||||
@@ -4304,6 +4274,10 @@ class ArrayEntity extends IEntity {
|
||||
static type
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
get length() {
|
||||
return this.values.length
|
||||
}
|
||||
|
||||
/** @param {T[]} values */
|
||||
constructor(values = []) {
|
||||
super();
|
||||
@@ -4331,7 +4305,7 @@ class ArrayEntity extends IEntity {
|
||||
* @param {T} type
|
||||
*/
|
||||
static of(type) {
|
||||
const result = /** @type {{type: T, grammar: P<ArrayEntity<ExtractType<T>>> } & typeof ArrayEntity<ExtractType<T>>} */(
|
||||
const result = /** @type {typeof ArrayEntity<ExtractType<T>> & {type: T, grammar: P<ArrayEntity<ExtractType<T>>> }} */(
|
||||
this.asUniqueClass()
|
||||
);
|
||||
result.type = /** @type {ExtractType<T>} */(type);
|
||||
@@ -4508,6 +4482,7 @@ class ByteEntity extends IntegerEntity {
|
||||
|
||||
class ComputedTypeEntity extends IEntity {
|
||||
|
||||
static grammar = undefined
|
||||
/** @type {(entity: IEntity) => typeof IEntity} */
|
||||
static f
|
||||
|
||||
@@ -5227,7 +5202,6 @@ class PinEntity extends IEntity {
|
||||
[Configuration.paths.vector4f]: SimpleSerializationVector4DEntity,
|
||||
}
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
PinId: GuidEntity.withDefault(),
|
||||
PinName: StringEntity.withDefault(),
|
||||
PinFriendlyName: AlternativesEntity.accepting(
|
||||
@@ -5239,12 +5213,12 @@ 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,
|
||||
@@ -5311,7 +5285,7 @@ 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
|
||||
}
|
||||
@@ -5345,7 +5319,7 @@ class PinEntity extends IEntity {
|
||||
}
|
||||
}
|
||||
if (category === "optional") {
|
||||
switch (this.PinType.PinSubCategory) {
|
||||
switch (this.PinType.PinSubCategory.toString()) {
|
||||
case "red":
|
||||
return "real"
|
||||
case "rg":
|
||||
@@ -5394,7 +5368,7 @@ class PinEntity extends IEntity {
|
||||
}
|
||||
|
||||
isExecution() {
|
||||
return this.PinType.PinCategory === "exec"
|
||||
return this.PinType.PinCategory.toString() === "exec"
|
||||
}
|
||||
|
||||
isHidden() {
|
||||
@@ -5402,11 +5376,11 @@ 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() {
|
||||
@@ -5419,12 +5393,12 @@ 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
|
||||
@@ -5436,12 +5410,12 @@ 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;
|
||||
}
|
||||
@@ -5628,7 +5602,7 @@ class MacroGraphReferenceEntity extends IEntity {
|
||||
}
|
||||
|
||||
/** @template {typeof IEntity} T */
|
||||
class MirroredEntity$1 extends IEntity {
|
||||
class MirroredEntity extends IEntity {
|
||||
|
||||
/** @type {typeof IEntity} */
|
||||
static type
|
||||
@@ -5653,7 +5627,7 @@ class MirroredEntity$1 extends IEntity {
|
||||
/** @returns {typeof IEntity} */
|
||||
static getTargetType() {
|
||||
const result = this.type;
|
||||
if (result.prototype instanceof MirroredEntity$1) {
|
||||
if (result.prototype instanceof MirroredEntity) {
|
||||
return /** @type {typeof MirroredEntity} */(result).getTargetType()
|
||||
}
|
||||
return result
|
||||
@@ -5805,15 +5779,15 @@ class ObjectEntity extends IEntity {
|
||||
MoveMode: SymbolEntity,
|
||||
TimelineName: StringEntity,
|
||||
TimelineGuid: GuidEntity,
|
||||
SizeX: MirroredEntity$1.of(IntegerEntity),
|
||||
SizeY: MirroredEntity$1.of(IntegerEntity),
|
||||
Text: MirroredEntity$1.of(StringEntity),
|
||||
MaterialExpressionEditorX: MirroredEntity$1.of(IntegerEntity),
|
||||
MaterialExpressionEditorY: MirroredEntity$1.of(IntegerEntity),
|
||||
SizeX: MirroredEntity.of(IntegerEntity),
|
||||
SizeY: MirroredEntity.of(IntegerEntity),
|
||||
Text: MirroredEntity.of(StringEntity),
|
||||
MaterialExpressionEditorX: MirroredEntity.of(IntegerEntity),
|
||||
MaterialExpressionEditorY: MirroredEntity.of(IntegerEntity),
|
||||
NodeTitle: StringEntity,
|
||||
NodeTitleColor: LinearColorEntity,
|
||||
PositionX: MirroredEntity$1.of(IntegerEntity),
|
||||
PositionY: MirroredEntity$1.of(IntegerEntity),
|
||||
PositionX: MirroredEntity.of(IntegerEntity),
|
||||
PositionY: MirroredEntity.of(IntegerEntity),
|
||||
SettingsInterface: ObjectReferenceEntity,
|
||||
PCGNode: ObjectReferenceEntity,
|
||||
HiGenGridSize: SymbolEntity,
|
||||
@@ -5838,7 +5812,7 @@ class ObjectEntity extends IEntity {
|
||||
ErrorType: IntegerEntity,
|
||||
ErrorMsg: StringEntity,
|
||||
ScriptVariables: ArrayEntity.of(ScriptVariableEntity),
|
||||
Node: MirroredEntity$1.of(ObjectReferenceEntity),
|
||||
Node: MirroredEntity.of(ObjectReferenceEntity),
|
||||
ExportedNodes: StringEntity,
|
||||
CustomProperties: ArrayEntity.of(AlternativesEntity.accepting(PinEntity, UnknownPinEntity)).withDefault().flagSilent(),
|
||||
}
|
||||
@@ -6034,16 +6008,16 @@ class ObjectEntity extends IEntity {
|
||||
this.getPinEntities().find(pin => pin.PinName === pinName && (pin.recomputesNodeTitleOnChange = true))
|
||||
);
|
||||
obj.R = new (
|
||||
MirroredEntity$1.of(BooleanEntity).withDefault().flagSilent()
|
||||
MirroredEntity.of(BooleanEntity).withDefault().flagSilent()
|
||||
)(() => rgbaPins[0].DefaultValue);
|
||||
obj.G = new (
|
||||
MirroredEntity$1.of(BooleanEntity).withDefault().flagSilent()
|
||||
MirroredEntity.of(BooleanEntity).withDefault().flagSilent()
|
||||
)(() => rgbaPins[1].DefaultValue);
|
||||
obj.B = new (
|
||||
MirroredEntity$1.of(BooleanEntity).withDefault().flagSilent()
|
||||
MirroredEntity.of(BooleanEntity).withDefault().flagSilent()
|
||||
)(() => rgbaPins[2].DefaultValue);
|
||||
obj.A = new (
|
||||
MirroredEntity$1.of(BooleanEntity).withDefault().flagSilent()
|
||||
MirroredEntity.of(BooleanEntity).withDefault().flagSilent()
|
||||
)(() => rgbaPins[3].DefaultValue);
|
||||
obj.keys = [...Configuration.rgba, ...super.keys.filter(k => !Configuration.rgba.includes(k))];
|
||||
}
|
||||
@@ -6115,7 +6089,7 @@ class ObjectEntity extends IEntity {
|
||||
if (dropCounter) {
|
||||
return this.getNameAndCounter()[0]
|
||||
}
|
||||
return this.Name
|
||||
return this.Name.print()
|
||||
}
|
||||
|
||||
/** @returns {[String, Number]} */
|
||||
@@ -12835,10 +12809,15 @@ class UnknownKeysEntity extends IEntity {
|
||||
attributes.forEach(attributeSetter => attributeSetter(values));
|
||||
return new this(values)
|
||||
}).label("UnknownKeysEntity")
|
||||
|
||||
static {
|
||||
IEntity.unknownEntity = this;
|
||||
}
|
||||
}
|
||||
|
||||
class NullEntity extends IEntity {
|
||||
|
||||
// @ts-expect-error
|
||||
static grammar = Parsernostrum.reg(new RegExp(String.raw`\(${Parsernostrum.whitespaceInlineOpt.getParser().regexp.source}\)`))
|
||||
.map(v => new this())
|
||||
|
||||
|
||||
6
dist/ueblueprint.min.js
vendored
6
dist/ueblueprint.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -181,37 +181,6 @@ export default class Utility {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Attribute} a
|
||||
* @param {Attribute} b
|
||||
*/
|
||||
static equals(a, b) {
|
||||
while (a instanceof MirroredEntity) {
|
||||
a = a.get()
|
||||
}
|
||||
while (b instanceof MirroredEntity) {
|
||||
b = b.get()
|
||||
}
|
||||
// Here we cannot check both instanceof IEntity because this would introduce a circular include dependency
|
||||
if (/** @type {IEntity?} */(a)?.equals && /** @type {IEntity?} */(b)?.equals) {
|
||||
return /** @type {IEntity} */(a).equals(/** @type {IEntity} */(b))
|
||||
}
|
||||
a = Utility.sanitize(a)
|
||||
b = Utility.sanitize(b)
|
||||
if (a?.constructor === BigInt && b?.constructor === Number) {
|
||||
b = BigInt(b)
|
||||
} else if (a?.constructor === Number && b?.constructor === BigInt) {
|
||||
a = BigInt(a)
|
||||
}
|
||||
if (a === b) {
|
||||
return true
|
||||
}
|
||||
if (a instanceof Array && b instanceof Array) {
|
||||
return a.length === b.length && a.every((value, i) => Utility.equals(value, b[i]))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
|
||||
@@ -9,6 +9,10 @@ export default class ArrayEntity extends IEntity {
|
||||
static type
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
get length() {
|
||||
return this.values.length
|
||||
}
|
||||
|
||||
/** @param {T[]} values */
|
||||
constructor(values = []) {
|
||||
super()
|
||||
@@ -36,7 +40,7 @@ export default class ArrayEntity extends IEntity {
|
||||
* @param {T} type
|
||||
*/
|
||||
static of(type) {
|
||||
const result = /** @type {{type: T, grammar: P<ArrayEntity<ExtractType<T>>> } & typeof ArrayEntity<ExtractType<T>>} */(
|
||||
const result = /** @type {typeof ArrayEntity<ExtractType<T>> & {type: T, grammar: P<ArrayEntity<ExtractType<T>>> }} */(
|
||||
this.asUniqueClass()
|
||||
)
|
||||
result.type = /** @type {ExtractType<T>} */(type)
|
||||
|
||||
@@ -2,6 +2,7 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class ComputedTypeEntity extends IEntity {
|
||||
|
||||
static grammar = undefined
|
||||
/** @type {(entity: IEntity) => typeof IEntity} */
|
||||
static f
|
||||
|
||||
|
||||
@@ -6,30 +6,24 @@ export default class IEntity {
|
||||
|
||||
/** @type {(v: String) => String} */
|
||||
static same = v => v
|
||||
|
||||
/** @type {(entity: IEntity, serialized: String) => String} */
|
||||
static notWrapped = (entity, serialized) => serialized
|
||||
|
||||
/** @type {(entity: IEntity, serialized: String) => String} */
|
||||
static defaultWrapped = (entity, serialized) => `${entity.lookbehind}(${serialized})`
|
||||
|
||||
static defaultWrapped = (entity, serialized) => `${entity.#lookbehind}(${serialized})`
|
||||
static wrap = this.defaultWrapped
|
||||
|
||||
static attributeSeparator = ","
|
||||
static keySeparator = "="
|
||||
|
||||
/** @type {(k: String) => String} */
|
||||
static printKey = k => k
|
||||
|
||||
/** @type {P<IEntity>} */
|
||||
static grammar = /** @type {any} */(P.failure())
|
||||
|
||||
/** @type {P<IEntity>} */
|
||||
static unknownEntityGrammar
|
||||
|
||||
static unknownEntity
|
||||
/** @type {{ [key: String]: typeof IEntity }} */
|
||||
static attributes = {}
|
||||
|
||||
/** @type {String | String[]} */
|
||||
static lookbehind = ""
|
||||
/** @type {(type: typeof IEntity) => InstanceType<typeof IEntity>} */
|
||||
static default
|
||||
static nullable = false
|
||||
@@ -49,12 +43,9 @@ export default class IEntity {
|
||||
this.#trailing = value
|
||||
}
|
||||
|
||||
/** @type {String | String[]} */
|
||||
static lookbehind = ""
|
||||
|
||||
#lookbehind = /** @type {String} */(this.Self().lookbehind)
|
||||
get lookbehind() {
|
||||
return this.#lookbehind
|
||||
return this.#lookbehind.trim()
|
||||
}
|
||||
set lookbehind(value) {
|
||||
this.#lookbehind = value
|
||||
@@ -70,13 +61,23 @@ export default class IEntity {
|
||||
}
|
||||
|
||||
constructor(values = {}) {
|
||||
const keys = Utility.mergeArrays(Object.keys(values), Object.keys(this.Self().attributes))
|
||||
const attributes = this.Self().attributes
|
||||
const keys = Utility.mergeArrays(
|
||||
Object.keys(values),
|
||||
Object.entries(attributes).filter(([k, v]) => v.default !== undefined).map(([k, v]) => k)
|
||||
)
|
||||
for (const key of keys) {
|
||||
if (values[key] !== undefined) {
|
||||
if (values[key].constructor === Object) {
|
||||
// It is part of a nested key (words separated by ".")
|
||||
values[key] = new (
|
||||
attributes[key] !== undefined ? attributes[key] : IEntity.unknownEntity
|
||||
)(values[key])
|
||||
}
|
||||
this[key] = values[key]
|
||||
continue
|
||||
}
|
||||
const attribute = this.Self().attributes[key]
|
||||
const attribute = attributes[key]
|
||||
if (attribute.default !== undefined) {
|
||||
this[key] = attribute.default(attribute)
|
||||
continue
|
||||
|
||||
@@ -3,6 +3,7 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class NullEntity extends IEntity {
|
||||
|
||||
// @ts-expect-error
|
||||
static grammar = P.reg(new RegExp(String.raw`\(${P.whitespaceInlineOpt.getParser().regexp.source}\)`))
|
||||
.map(v => new this())
|
||||
|
||||
|
||||
@@ -406,7 +406,7 @@ export default class ObjectEntity extends IEntity {
|
||||
if (dropCounter) {
|
||||
return this.getNameAndCounter()[0]
|
||||
}
|
||||
return this.Name
|
||||
return this.Name.print()
|
||||
}
|
||||
|
||||
/** @returns {[String, Number]} */
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -25,4 +25,8 @@ export default class UnknownKeysEntity extends IEntity {
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
return new this(values)
|
||||
}).label("UnknownKeysEntity")
|
||||
|
||||
static {
|
||||
IEntity.unknownEntity = this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ export default class Grammar {
|
||||
static createEntityGrammar(entityType, entriesSeparator = this.commaSeparation, complete = false, minKeys = 1) {
|
||||
const lookbehind = entityType.lookbehind instanceof Array ? entityType.lookbehind.join("|") : entityType.lookbehind
|
||||
return Parsernostrum.seq(
|
||||
Parsernostrum.reg(new RegExp(String.raw`(${lookbehind})\s*\(\s*`), 1),
|
||||
Parsernostrum.reg(new RegExp(String.raw`(${lookbehind}\s*)\(\s*`), 1),
|
||||
this.createAttributeGrammar(entityType).sepBy(entriesSeparator, minKeys),
|
||||
Parsernostrum.reg(/\s*(,\s*)?\)/, 1), // optional trailing comma
|
||||
)
|
||||
|
||||
@@ -26,6 +26,8 @@ import Vector2DEntity from "../js/entity/Vector2DEntity.js"
|
||||
import Vector4DEntity from "../js/entity/Vector4DEntity.js"
|
||||
import VectorEntity from "../js/entity/VectorEntity.js"
|
||||
import initializeSerializerFactory from "../js/serialization/initializeSerializerFactory.js"
|
||||
import PinEntity from "../js/entity/PinEntity.js"
|
||||
import PinTypeEntity from "../js/entity/PinTypeEntity.js"
|
||||
|
||||
test.beforeAll(() => initializeSerializerFactory())
|
||||
|
||||
@@ -749,6 +751,27 @@ test("ObjectReferenceEntity", () => {
|
||||
expect(value).toEqual(new ObjectReferenceEntity("/Game/_YukiritoLib/Textures/T_紫色渐变01.T_紫色渐变01"))
|
||||
})
|
||||
|
||||
test("PinEntity", () => {
|
||||
const grammar = PinEntity.grammar
|
||||
const s = `Pin (PinId=370DE2594FC6D3DF81672491D09FA4F2,PinName="execute",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_ComponentBoundEvent_2 CA668D354E07DD5D3FDF828A8DCB31E2,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)`
|
||||
let value = grammar.parse(s)
|
||||
expect(value).toBeInstanceOf(PinEntity)
|
||||
expect(value.PinId).toBeInstanceOf(GuidEntity)
|
||||
expect(value.PinId.equals(new GuidEntity("370DE2594FC6D3DF81672491D09FA4F2"))).toBeTruthy()
|
||||
expect(value.PinName).toBeInstanceOf(StringEntity)
|
||||
expect(value.PinName.equals(new StringEntity("execute"))).toBeTruthy()
|
||||
expect(value.PinType).toBeInstanceOf(PinTypeEntity)
|
||||
expect(value.PinType.PinCategory).toBeInstanceOf(StringEntity)
|
||||
expect(value.PinType.PinCategory.equals(new StringEntity("exec"))).toBeTruthy()
|
||||
expect(value.PinType.PinSubCategory).toBeInstanceOf(StringEntity)
|
||||
expect(value.PinType.PinSubCategory.equals(new StringEntity(""))).toBeTruthy()
|
||||
expect(value.PinType.PinSubCategoryObject).toBeInstanceOf(ObjectReferenceEntity)
|
||||
expect(value.PinType.PinSubCategoryObject.equals(ObjectReferenceEntity.createNoneInstance())).toBeTruthy()
|
||||
expect(value.PinType.bIsReference).toBeInstanceOf(BooleanEntity)
|
||||
expect(value.PinType.bIsReference.equals(new BooleanEntity(false))).toBeTruthy()
|
||||
expect(value.toString()).toEqual(s)
|
||||
})
|
||||
|
||||
test("SimpleSerializationRotatorEntity", () => {
|
||||
const grammar = SimpleSerializationRotatorEntity.grammar
|
||||
{
|
||||
Reference in New Issue
Block a user