Files
ueblueprint/js/serialization/ToStringSerializer.js
barsdeveloper a5813d0b4d 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
2024-05-20 12:56:36 +02:00

29 lines
864 B
JavaScript
Executable File

import Utility from "../Utility.js"
import Serializer from "./Serializer.js"
/**
* @template {AttributeConstructor<Attribute>} T
* @extends {Serializer<T>}
*/
export default class ToStringSerializer extends Serializer {
/** @param {T} entityType */
constructor(entityType, escape = true) {
super(entityType)
if (escape) {
this.wrap = (entity, serialized) => Utility.escapeString(serialized)
}
}
/**
* @param {ConstructedType<T>} entity
* @param {Boolean} insideString
*/
doWrite(entity, insideString, indentation = "") {
return !insideString && entity.constructor === String
? `"${this.wrap(entity, entity.toString())}"` // String will have quotes if not inside a string already
: this.wrap(entity, entity.toString())
}
}