mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-21 05:27:34 +08:00
Niagara and Metasound nodes WIP
* Keep track of entities * Fix renaming * Niagara variables wip * Several niagara decode and test * Move nodeTemplate code to dedicated file, self node added * Move node decoding functions to dedicated files * Move pin decoding logic to dedicated files * Accept space separated keys in objects * Build * Prevent a crash in case of incomplete object * Avoid creating objects unnecessarily * types formatting * Initial metasound style * Common pcg nodes colors * Fix string serialization * Metasound new styles and fixes * More metasound styles and colors * WIP * Several fixes * More tests and fixes * Clean gitignore
This commit is contained in:
88
js/entity/BlueprintEntity.js
Normal file
88
js/entity/BlueprintEntity.js
Normal file
@@ -0,0 +1,88 @@
|
||||
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,
|
||||
entity.ScriptVariables,
|
||||
(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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user