Object reference moved to entity

This commit is contained in:
barsdeveloper
2021-11-16 21:14:03 +01:00
parent 39e26bc0c2
commit 7ec75e1ce8
13 changed files with 346 additions and 269 deletions

View File

@@ -1,10 +1,10 @@
import Entity from "./Entity"
import ObjectReference from "./primitive/ObjectReference"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
export default class FunctionReferenceEntity extends Entity {
static attributes = {
MemberParent: ObjectReference,
MemberParent: ObjectReferenceEntity,
MemberName: ""
}

View File

@@ -1,7 +1,7 @@
import Entity from "./Entity"
import FunctionReferenceEntity from "./FunctionReferenceEntity"
import Guid from "./primitive/Guid"
import ObjectReference from "./primitive/ObjectReference"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
import PinEntity from "./PinEntity"
import TypeInitialization from "./TypeInitialization"
import VariableReferenceEntity from "./VariableReferenceEntity"
@@ -9,12 +9,12 @@ import VariableReferenceEntity from "./VariableReferenceEntity"
export default class ObjectEntity extends Entity {
static attributes = {
Class: ObjectReference,
Class: ObjectReferenceEntity,
Name: "",
bIsPureFunc: new TypeInitialization(Boolean, false, false),
VariableReference: new TypeInitialization(VariableReferenceEntity, false, null),
FunctionReference: new TypeInitialization(FunctionReferenceEntity, false, null,),
TargetType: new TypeInitialization(ObjectReference, false, null),
TargetType: new TypeInitialization(ObjectReferenceEntity, false, null),
NodePosX: 0,
NodePosY: 0,
NodeGuid: Guid,

View File

@@ -0,0 +1,13 @@
import Entity from "./Entity"
export default class ObjectReferenceEntity extends Entity {
static attributes = {
type: String,
path: String
}
getAttributes() {
return ObjectReferenceEntity.attributes
}
}

View File

@@ -1,7 +1,7 @@
import Entity from "./Entity"
import Guid from "./primitive/Guid"
import LocalizedTextEntity from "./LocalizedTextEntity"
import ObjectReference from "./primitive/ObjectReference"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
import PinReferenceEntity from "./PinReferenceEntity"
import TypeInitialization from "./TypeInitialization"
@@ -16,10 +16,10 @@ export default class PinEntity extends Entity {
PinType: {
PinCategory: "",
PinSubCategory: "",
PinSubCategoryObject: ObjectReference,
PinSubCategoryObject: ObjectReferenceEntity,
PinSubCategoryMemberReference: null,
PinValueType: null,
ContainerType: ObjectReference,
ContainerType: ObjectReferenceEntity,
bIsReference: false,
bIsConst: false,
bIsWeakPointer: false,

View File

@@ -1,23 +0,0 @@
import Primitive from "./Primitive"
export default class ObjectReference extends Primitive {
/**
*
* @param {String} type
* @param {String} path
*/
constructor(type, path) {
super()
this.type = type
this.path = path
}
toString() {
return (this.type ?? "") + (
this.path
? this.type ? `'"${this.path}"'` : this.path
: ""
)
}
}

View File

@@ -9,6 +9,8 @@ import Blueprint from "./Blueprint"
import GraphNode from "./graph/GraphNode"
import GraphLink from "./graph/GraphLink"
import PinReferenceEntity from "./entity/PinReferenceEntity"
import ObjectReferenceEntity from "./entity/ObjectReferenceEntity"
import CustomSerializer from "./serialization/CustomSerializer"
SerializerFactory.registerSerializer(
ObjectEntity,
@@ -30,5 +32,15 @@ SerializerFactory.registerSerializer(
PinReferenceEntity,
new GeneralSerializer(v => v, PinReferenceEntity, "", " ", false, "", _ => "")
)
SerializerFactory.registerSerializer(
ObjectReferenceEntity,
new CustomSerializer(
/** @param {ObjectReferenceEntity} objectReference */
objectReference => (objectReference.type ?? "") + (
objectReference.path
? objectReference.type ? `'"${objectReference.path}"'` : objectReference.path
: ""
))
)
export { Blueprint as Blueprint, GraphNode as GraphNode, GraphLink as GraphLink }

View File

@@ -0,0 +1,14 @@
import GeneralSerializer from "./GeneralSerializer"
export default class CustomSerializer extends GeneralSerializer {
constructor(objectWriter, entityType) {
super(undefined, entityType)
this.objectWriter = objectWriter
}
write(object) {
let result = this.objectWriter(object)
return result
}
}

View File

@@ -3,7 +3,7 @@ import Guid from "../entity/primitive/Guid"
import Integer from "../entity/primitive/Integer"
import LocalizedTextEntity from "../entity/LocalizedTextEntity"
import ObjectEntity from "../entity/ObjectEntity"
import ObjectReference from "../entity/primitive/ObjectReference"
import ObjectReferenceEntity from "../entity/ObjectReferenceEntity"
import Parsimmon from "parsimmon"
import PinEntity from "../entity/PinEntity"
import PinReferenceEntity from "../entity/PinReferenceEntity"
@@ -18,7 +18,7 @@ export default class Grammar {
InlineOptWhitespace = _ => P.regex(/[^\S\n]*/).desc("inline optional whitespace")
WhitespaceNewline = _ => P.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline")
Null = r => P.seq(P.string("("), r.InlineOptWhitespace, P.string(")")).map(_ => null).desc("null: ()")
None = _ => P.string("None").map(_ => new ObjectReference("None", "")).desc("none")
None = _ => P.string("None").map(_ => new ObjectReferenceEntity({ type: "None", path: "" })).desc("none")
Boolean = _ => P.alt(P.string("True"), P.string("False")).map(v => v === "True" ? true : false).desc("either True or False")
Number = _ => P.regex(/[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number")
Integer = _ => P.regex(/[0-9]+/).map(v => new Integer(v)).desc("an integer")
@@ -33,7 +33,7 @@ export default class Grammar {
.desc('a path (words with possibly underscore, separated by ".", separated by "/")')
Reference = r => P.alt(
r.None,
r.ReferencePath.map(path => new ObjectReference("", path)),
r.ReferencePath.map(path => new ObjectReferenceEntity({ type: "", path: path })),
P.seqMap(
r.Word,
P.optWhitespace,
@@ -42,7 +42,7 @@ export default class Grammar {
P.string(result.split("").reverse().join(""))
)
),
(referenceType, _, referencePath) => new ObjectReference(referenceType, referencePath)
(referenceType, _, referencePath) => new ObjectReferenceEntity({ type: referenceType, path: referencePath })
)
)
AttributeName = r => r.Word.sepBy1(P.string(".")).tieWith(".").desc('words separated by ""')
@@ -82,7 +82,7 @@ export default class Grammar {
return r.String
case Guid:
return r.Guid
case ObjectReference:
case ObjectReferenceEntity:
return r.Reference
case LocalizedTextEntity:
return r.LocalizedText

View File

@@ -49,7 +49,7 @@ export default class ObjectSerializer extends Serializer {
* @returns
*/
write(object) {
let result = `Begin Object Class=${object.Class} Name="${object.Name}"
let result = `Begin Object Class=${this.writeValue(object.Class)} Name=${this.writeValue(object.Name)}
${this.subWrite([], object)
+ object
.CustomProperties.map(pin => this.separator + this.prefix + "CustomProperties " + SerializerFactory.getSerializer(PinEntity).write(pin))