Fixing mirrored ExportPath

This commit is contained in:
barsdeveloper
2024-12-19 23:57:31 +02:00
parent 2173e2b421
commit e40e6ba52b
8 changed files with 276 additions and 62 deletions

View File

@@ -413,9 +413,11 @@ export default class Blueprint extends IElement {
this.entity.updateNameIndex(name)
if (element.getType() == Configuration.paths.niagaraClipboardContent) {
this.entity = this.entity.mergeWith(element.entity)
const additionalSerialization = atob(element.entity.ExportedNodes.toString())
this.template.getPasteInputObject().pasted(additionalSerialization)
.forEach(node => node.entity.exported = true)
const additionalSerialization = atob(element.entity.ExportedNodes?.toString() ?? "")
if (additionalSerialization) {
this.template.getPasteInputObject().pasted(additionalSerialization)
.forEach(node => node.entity.exported = true)
}
continue
}
const homonym = this.entity.getHomonymObjectEntity(element.entity)

View File

@@ -135,8 +135,8 @@ export default class NodeElement extends ISelectableDraggableElement {
"Name",
/** @param {InstanceType<typeof ObjectEntity.attributes.Name>} newName */
newName => {
this.#redirectLinksBeforeRename(newName.value)
this.nodeTitle = newName.value
this.#redirectLinksBeforeRename(newName?.toString())
this.nodeTitle = newName?.toString()
this.nodeDisplayName = nodeTitle(entity)
}
)

View File

@@ -372,36 +372,39 @@ export default class ObjectEntity extends IEntity {
})
// Mirror name part of the object in ExportPath
const originalName = this.Name?.toString()
const exportPath = this.ExportPath?.valueOf()
if (exportPath?.path.endsWith(this.Name?.toString())) {
if (originalName && exportPath?.path.endsWith(originalName)) {
const mirroredEntity = /** @type {typeof ObjectEntity} */(this.constructor).attributes.ExportPath
const prefix = exportPath.path.substring(0, exportPath.path.length - this.Name.toString().length)
this.ExportPath = new mirroredEntity(
() => new (mirroredEntity.type)(exportPath.type, prefix + this.Name.toString(), exportPath.full)
() => new (mirroredEntity.type)(
exportPath.type,
exportPath.path.replace(originalName, (this.Name ?? "")?.toString()),
exportPath.full
)
)
}
// Mirror name part of the nested object in ExportPath
if (this.Name) {
for (const k of Object.keys(this)) {
if (!k.startsWith(Configuration.subObjectAttributeNamePrefix)) {
if (originalName) {
const values = Object.values(this)
for (let i = 0; i < values.length; ++i) {
const value = values[i]
if (value instanceof ObjectEntity) {
values.push(...Object.values(value))
if (!value.ExportPath?.valueOf(this).path.includes(originalName)) {
continue
}
} else {
continue
}
/** @type {ObjectEntity} */
const subObject = this[k]
if (!subObject.ExportPath?.valueOf(this).path.includes(this.Name.toString())) {
continue
}
const originalExportPath = subObject.ExportPath.valueOf(this)
const position = originalExportPath.path.indexOf(this.Name.toString())
const prefix = originalExportPath.path.substring(0, position)
const suffix = originalExportPath.path.substring(position + this.Name.toString().length)
const mirroredEntity = /** @type {typeof ObjectEntity} */(subObject.constructor).attributes.ExportPath
subObject.ExportPath = new mirroredEntity(
const mirroredEntity = /** @type {typeof ObjectEntity} */(value.constructor).attributes.ExportPath
const exportPath = value.ExportPath?.valueOf()
value.ExportPath = new mirroredEntity(
(self = this) => new (mirroredEntity.type)(
originalExportPath.type,
prefix + (self.Name ?? "").toString() + suffix,
originalExportPath.full
exportPath.type,
exportPath.path.replace(originalName, (this.Name ?? "")?.toString()),
exportPath.full
)
)
}