mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
* Still WIP * WIP * ArrayEntity parsing fixed * Fix format text entity * Tests for various entity classes and update entity class implementations * More tests and fixed * More entities fixed * Simple entities serialization fixed * Entities tests fixed * Remove serialization bits * Fix Function reference * CustomProperties creating fixed * WIP * Better typing for grammars * Decoding code fixes * Fixing still * Several fixes * rename toString to serialize * Several fixes * More fixes * Moving more stuff out of Utility * Several fixes * Fixing Linear color entity print * Serialization fixes * Fix serialization * Method to compute grammar * Renaming fix * Fix array grammar and equality check * Fix inlined keys * Fix type * Several serialization fixes * Fix undefined dereference * Several fixes * More fixes and cleanup * Fix keys quoting mechanism * Fix natural number assignment * Fix Int64 toString() * Fix quoted keys for inlined arrays * Fix PG pins * Fix several test cases * Types fixes * New pin default value empty * Fix non existing DefaultValue for variadic nodes * Smaller fixes for crashes * Fix link color when attached to knot * Linking test and more reliability operations for adding pins * Improve issue 18 test * More tests and fixes * Fix enum pin entity * Remove failing test
89 lines
3.0 KiB
JavaScript
89 lines
3.0 KiB
JavaScript
import Configuration from "../Configuration.js"
|
|
import Utility from "../Utility.js"
|
|
import ObjectEntity from "./ObjectEntity.js"
|
|
|
|
export default class BlueprintEntity extends ObjectEntity {
|
|
|
|
/** @type {Map<String, Number>} */
|
|
#objectEntitiesNameCounter = new Map()
|
|
|
|
/** @type {ObjectEntity[]}" */
|
|
#objectEntities = []
|
|
get objectEntities() {
|
|
return this.#objectEntities
|
|
}
|
|
|
|
/** @param {ObjectEntity} entity */
|
|
getHomonymObjectEntity(entity) {
|
|
const name = entity.getObjectName(false)
|
|
return this.#objectEntities.find(entity => entity.getObjectName() == name)
|
|
}
|
|
|
|
/** @param {String} name */
|
|
takeFreeName(name) {
|
|
name = name.replace(/_\d+$/, "")
|
|
const counter = (this.#objectEntitiesNameCounter.get(name) ?? -1) + 1
|
|
this.#objectEntitiesNameCounter.set(name, counter)
|
|
return Configuration.nodeTitle(name, counter)
|
|
}
|
|
|
|
/** @param {ObjectEntity} entity */
|
|
addObjectEntity(entity) {
|
|
if (!this.#objectEntities.includes(entity)) {
|
|
this.#objectEntities.push(entity)
|
|
const [name, counter] = entity.getNameAndCounter()
|
|
this.#objectEntitiesNameCounter.set(
|
|
name,
|
|
Math.max((this.#objectEntitiesNameCounter.get(name) ?? 0), counter)
|
|
)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
/** @param {ObjectEntity} entity */
|
|
removeObjectEntity(entity) {
|
|
const index = this.#objectEntities.indexOf(entity)
|
|
if (index >= 0) {
|
|
const last = this.#objectEntities.pop()
|
|
if (index < this.#objectEntities.length) {
|
|
this.#objectEntities[index] = last
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
/** @param {ObjectEntity} entity */
|
|
mergeWith(entity) {
|
|
if (!entity.ScriptVariables || entity.ScriptVariables.length === 0) {
|
|
return this
|
|
}
|
|
if (!this.ScriptVariables || this.ScriptVariables.length === 0) {
|
|
this.ScriptVariables = entity.ScriptVariables
|
|
}
|
|
let scriptVariables = Utility.mergeArrays(
|
|
this.ScriptVariables.valueOf(),
|
|
entity.ScriptVariables.valueOf(),
|
|
(l, r) => l.OriginalChangeId.value == r.OriginalChangeId.value
|
|
)
|
|
if (scriptVariables.length === this.ScriptVariables.length) {
|
|
return this
|
|
}
|
|
const entries = scriptVariables.concat(scriptVariables).map((v, i) => {
|
|
const name = Configuration.subObjectAttributeNameFromReference(v.ScriptVariable, i >= scriptVariables.length)
|
|
return [
|
|
name,
|
|
this[name] ?? entity[name]
|
|
]
|
|
})
|
|
entries.push(
|
|
...Object.entries(this).filter(([k, v]) =>
|
|
!k.startsWith(Configuration.subObjectAttributeNamePrefix)
|
|
&& k !== "ExportedNodes"
|
|
)
|
|
)
|
|
return new BlueprintEntity(Object.fromEntries(entries))
|
|
}
|
|
}
|