Small refactoring and fixes

This commit is contained in:
barsdeveloper
2024-02-16 00:58:08 +01:00
parent 34a4f2746f
commit a57fa97cff
11 changed files with 389 additions and 352 deletions

View File

@@ -112,6 +112,7 @@ export default class Configuration {
doN: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:Do N",
doOnce: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:DoOnce",
dynamicCast: "/Script/BlueprintGraph.K2Node_DynamicCast",
eAttachmentRule: "/Script/Engine.EAttachmentRule",
edGraph: "/Script/Engine.EdGraph",
edGraphPinDeprecated: "/Script/Engine.EdGraphPin_Deprecated",
eDrawDebugTrace: "/Script/Engine.EDrawDebugTrace",
@@ -278,6 +279,11 @@ export default class Configuration {
static windowCancelButtonText = "Cancel"
static windowCloseEventName = "ueb-window-close"
static CommonEnums = {
[this.paths.eAttachmentRule]: [
"KeepRelative",
"KeepWorld",
"SnapToTarget",
],
[this.paths.eMaterialSamplerType]: [
"Color",
"Grayscale",

View File

@@ -140,9 +140,9 @@ export default class Utility {
* @returns {Boolean}
*/
static isSerialized(entity, key) {
// @ts-expect-error
const attribute = (entity.attributes ?? entity.constructor?.attributes)?.[key]
return attribute ? attribute.serialized : false
return entity["attributes"]?.[key]?.serialized
?? entity.constructor["attributes"]?.[key]?.serialized
?? false
}
/** @param {String[]} keys */
@@ -164,23 +164,22 @@ export default class Utility {
/**
* @param {String[]} keys
* @param {Boolean} create
* @returns {Boolean}
*/
static objectSet(target, keys, value, create = false, defaultDictType = Object) {
static objectSet(target, keys, value, defaultDictType = Object) {
if (!(keys instanceof Array)) {
throw new TypeError("Expected keys to be an array.")
}
if (keys.length == 1) {
if (create || keys[0] in target || target[keys[0]] === undefined) {
if (keys[0] in target || target[keys[0]] === undefined) {
target[keys[0]] = value
return true
}
} else if (keys.length > 0) {
if (create && !(target[keys[0]] instanceof Object)) {
if (!(target[keys[0]] instanceof Object)) {
target[keys[0]] = new defaultDictType()
}
return Utility.objectSet(target[keys[0]], keys.slice(1), value, create, defaultDictType)
return Utility.objectSet(target[keys[0]], keys.slice(1), value, defaultDictType)
}
return false
}

View File

@@ -188,12 +188,12 @@ export default class ObjectEntity extends IEntity {
.map(currentValue =>
values => {
(values[symbol] ??= [])[index] = currentValue
Utility.objectSet(values, ["attributes", symbol, "quoted"], quoted, true)
Utility.objectSet(values, ["attributes", symbol, "quoted"], quoted)
if (!this.attributes[symbol]?.inlined) {
if (!values.attributes) {
IEntity.defineAttributes(values, {})
}
Utility.objectSet(values, ["attributes", symbol, "inlined"], true, true)
Utility.objectSet(values, ["attributes", symbol, "inlined"], true)
}
}
)
@@ -216,7 +216,7 @@ export default class ObjectEntity extends IEntity {
this.customPropertyGrammar,
Grammar.createAttributeGrammar(this),
Grammar.createAttributeGrammar(this, Grammar.attributeNameQuoted, undefined, (obj, k, v) =>
Utility.objectSet(obj, ["attributes", ...k, "quoted"], true, true)
Utility.objectSet(obj, ["attributes", ...k, "quoted"], true)
),
this.inlinedArrayEntryGrammar,
this.createSubObjectGrammar()

View File

@@ -10,9 +10,11 @@ export default class ObjectReferenceEntity extends IEntity {
...super.attributes,
type: {
default: "",
serialized: true,
},
path: {
default: "",
serialized: true,
},
}
static {
@@ -54,8 +56,8 @@ export default class ObjectReferenceEntity extends IEntity {
),
Parsernostrum.str('"'),
).map(([_0, objectReference, _1]) => objectReference),
this.fullReferenceGrammar,
this.typeReferenceGrammar,
this.fullReferenceGrammar.map(v => (Utility.objectSet(v, ["attributes", "type", "serialized"], false), v)),
this.typeReferenceGrammar.map(v => (Utility.objectSet(v, ["attributes", "type", "serialized"], false), v)),
)
}

View File

@@ -180,7 +180,7 @@ export default class Grammar {
.map(attributeValue =>
values => {
handleObjectSet(values, attributeKey, attributeValue)
Utility.objectSet(values, attributeKey, attributeValue, true)
Utility.objectSet(values, attributeKey, attributeValue)
}
)
})

View File

@@ -213,11 +213,18 @@ export default function initializeSerializerFactory() {
SerializerFactory.registerSerializer(
ObjectReferenceEntity,
new CustomSerializer(
objectReference => (objectReference.type ?? "") + (
objectReference.path
? objectReference.type ? `'"${objectReference.path}"'` : `"${objectReference.path}"`
: ""
),
objectReference => {
let type = objectReference.type ?? ""
let name = objectReference.path ?? ""
if (type && name && Utility.isSerialized(objectReference, "path")) {
name = `'${name}'`
}
let result = type + name
if (Utility.isSerialized(objectReference, "type")) {
result = `"${result}"`
}
return result
},
ObjectReferenceEntity
)
)