mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
Guid => GuidEntity
This commit is contained in:
45
dist/ueblueprint.js
vendored
45
dist/ueblueprint.js
vendored
@@ -850,34 +850,30 @@ class Entity {
|
||||
}
|
||||
}
|
||||
|
||||
class Guid extends Primitive {
|
||||
class GuidEntity extends Entity {
|
||||
|
||||
static generateGuid(random) {
|
||||
static attributes = {
|
||||
value: String
|
||||
}
|
||||
|
||||
static generateGuid(random = true) {
|
||||
let values = new Uint32Array(4);
|
||||
if (random === true) {
|
||||
crypto.getRandomValues(values);
|
||||
}
|
||||
let result = "";
|
||||
let guid = "";
|
||||
values.forEach(n => {
|
||||
result += ('00000000' + n.toString(16).toUpperCase()).slice(-8);
|
||||
guid += ('00000000' + n.toString(16).toUpperCase()).slice(-8);
|
||||
});
|
||||
return result
|
||||
return new GuidEntity({ valud: guid })
|
||||
}
|
||||
|
||||
constructor(guid) {
|
||||
super();
|
||||
// Using constructor equality and not instanceof in order to consider both primitives and objects
|
||||
if (guid?.constructor === Boolean) {
|
||||
guid = Guid.generateGuid(guid == true);
|
||||
}
|
||||
if (guid instanceof Guid) {
|
||||
guid = guid.value;
|
||||
}
|
||||
this.value = guid;
|
||||
getAttributes() {
|
||||
return GuidEntity.attributes
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,7 +921,7 @@ class PinReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
objectName: PathSymbolEntity,
|
||||
pinGuid: Guid
|
||||
pinGuid: GuidEntity
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
@@ -936,7 +932,7 @@ class PinReferenceEntity extends Entity {
|
||||
class PinEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
PinId: Guid,
|
||||
PinId: GuidEntity,
|
||||
PinName: "",
|
||||
PinFriendlyName: new TypeInitialization(LocalizedTextEntity, false, null),
|
||||
PinToolTip: "",
|
||||
@@ -956,7 +952,7 @@ class PinEntity extends Entity {
|
||||
LinkedTo: [PinReferenceEntity],
|
||||
DefaultValue: "",
|
||||
AutogeneratedDefaultValue: "",
|
||||
PersistentGuid: Guid,
|
||||
PersistentGuid: GuidEntity,
|
||||
bHidden: false,
|
||||
bNotConnectable: false,
|
||||
bDefaultValueIsReadOnly: false,
|
||||
@@ -1070,7 +1066,7 @@ class VariableReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
MemberName: String,
|
||||
MemberGuid: Guid,
|
||||
MemberGuid: GuidEntity,
|
||||
bSelfContext: false
|
||||
}
|
||||
|
||||
@@ -1090,7 +1086,7 @@ class ObjectEntity extends Entity {
|
||||
TargetType: new TypeInitialization(ObjectReferenceEntity, false, null),
|
||||
NodePosX: 0,
|
||||
NodePosY: 0,
|
||||
NodeGuid: Guid,
|
||||
NodeGuid: GuidEntity,
|
||||
CustomProperties: [PinEntity]
|
||||
}
|
||||
|
||||
@@ -1323,7 +1319,7 @@ class Grammar {
|
||||
Integer = _ => P.regex(/[0-9]+/).map(v => new Integer(v)).desc("an integer")
|
||||
String = _ => P.regex(/(?:[^"\\]|\\")*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")')
|
||||
Word = _ => P.regex(/[a-zA-Z]+/).desc("a word")
|
||||
Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new Guid(v)).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
PathSymbolEntity = _ => P.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v }))
|
||||
ReferencePath = r => P.seq(P.string("/"), r.PathSymbolEntity.map(v => v.toString()).sepBy1(P.string(".")).tieWith("."))
|
||||
.tie()
|
||||
@@ -1379,7 +1375,7 @@ class Grammar {
|
||||
return r.Integer
|
||||
case String:
|
||||
return r.String
|
||||
case Guid:
|
||||
case GuidEntity:
|
||||
return r.Guid
|
||||
case ObjectReferenceEntity:
|
||||
return r.Reference
|
||||
@@ -2224,6 +2220,7 @@ SerializerFactory.registerSerializer(
|
||||
: ""
|
||||
))
|
||||
);
|
||||
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity));
|
||||
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity));
|
||||
SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity));
|
||||
|
||||
export { Blueprint, GraphLink, GraphNode };
|
||||
|
||||
28
js/entity/GuidEntity.js
Executable file
28
js/entity/GuidEntity.js
Executable file
@@ -0,0 +1,28 @@
|
||||
import Entity from "./Entity"
|
||||
|
||||
export default class GuidEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
value: String
|
||||
}
|
||||
|
||||
static generateGuid(random = true) {
|
||||
let values = new Uint32Array(4)
|
||||
if (random === true) {
|
||||
crypto.getRandomValues(values)
|
||||
}
|
||||
let guid = ""
|
||||
values.forEach(n => {
|
||||
guid += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return new GuidEntity({ valud: guid })
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
return GuidEntity.attributes
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import Entity from "./Entity"
|
||||
import FunctionReferenceEntity from "./FunctionReferenceEntity"
|
||||
import Guid from "./primitive/Guid"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
import PinEntity from "./PinEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
@@ -17,7 +17,7 @@ export default class ObjectEntity extends Entity {
|
||||
TargetType: new TypeInitialization(ObjectReferenceEntity, false, null),
|
||||
NodePosX: 0,
|
||||
NodePosY: 0,
|
||||
NodeGuid: Guid,
|
||||
NodeGuid: GuidEntity,
|
||||
CustomProperties: [PinEntity]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Entity from "./Entity"
|
||||
import Guid from "./primitive/Guid"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import LocalizedTextEntity from "./LocalizedTextEntity"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
import PinReferenceEntity from "./PinReferenceEntity"
|
||||
@@ -8,7 +8,7 @@ import TypeInitialization from "./TypeInitialization"
|
||||
export default class PinEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
PinId: Guid,
|
||||
PinId: GuidEntity,
|
||||
PinName: "",
|
||||
PinFriendlyName: new TypeInitialization(LocalizedTextEntity, false, null),
|
||||
PinToolTip: "",
|
||||
@@ -28,7 +28,7 @@ export default class PinEntity extends Entity {
|
||||
LinkedTo: [PinReferenceEntity],
|
||||
DefaultValue: "",
|
||||
AutogeneratedDefaultValue: "",
|
||||
PersistentGuid: Guid,
|
||||
PersistentGuid: GuidEntity,
|
||||
bHidden: false,
|
||||
bNotConnectable: false,
|
||||
bDefaultValueIsReadOnly: false,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import Entity from "./Entity"
|
||||
import Guid from "./primitive/Guid"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import PathSymbol from "./PathSymbolEntity"
|
||||
|
||||
export default class PinReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
objectName: PathSymbol,
|
||||
pinGuid: Guid
|
||||
pinGuid: GuidEntity
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Entity from "./Entity"
|
||||
import Guid from "./primitive/Guid"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
|
||||
export default class VariableReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
MemberName: String,
|
||||
MemberGuid: Guid,
|
||||
MemberGuid: GuidEntity,
|
||||
bSelfContext: false
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import Primitive from "./Primitive"
|
||||
|
||||
export default class Guid extends Primitive {
|
||||
|
||||
static generateGuid(random) {
|
||||
let values = new Uint32Array(4)
|
||||
if (random === true) {
|
||||
crypto.getRandomValues(values)
|
||||
}
|
||||
let result = ""
|
||||
values.forEach(n => {
|
||||
result += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
constructor(guid) {
|
||||
super()
|
||||
// Using constructor equality and not instanceof in order to consider both primitives and objects
|
||||
if (guid?.constructor === Boolean) {
|
||||
guid = Guid.generateGuid(guid == true)
|
||||
}
|
||||
if (guid instanceof Guid) {
|
||||
guid = guid.value
|
||||
}
|
||||
this.value = guid
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import FunctionReferenceEntity from "./entity/FunctionReferenceEntity"
|
||||
import GeneralSerializer from "./serialization/GeneralSerializer"
|
||||
import GraphLink from "./graph/GraphLink"
|
||||
import GraphNode from "./graph/GraphNode"
|
||||
import GuidEntity from "./entity/GuidEntity"
|
||||
import LocalizedTextEntity from "./entity/LocalizedTextEntity"
|
||||
import ObjectEntity from "./entity/ObjectEntity"
|
||||
import ObjectReferenceEntity from "./entity/ObjectReferenceEntity"
|
||||
@@ -45,5 +46,6 @@ SerializerFactory.registerSerializer(
|
||||
))
|
||||
)
|
||||
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity))
|
||||
SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity))
|
||||
|
||||
export { Blueprint as Blueprint, GraphNode as GraphNode, GraphLink as GraphLink }
|
||||
@@ -1,5 +1,5 @@
|
||||
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity"
|
||||
import Guid from "../entity/primitive/Guid"
|
||||
import GuidEntity from "../entity/GuidEntity"
|
||||
import Integer from "../entity/primitive/Integer"
|
||||
import LocalizedTextEntity from "../entity/LocalizedTextEntity"
|
||||
import ObjectEntity from "../entity/ObjectEntity"
|
||||
@@ -24,7 +24,7 @@ export default class Grammar {
|
||||
Integer = _ => P.regex(/[0-9]+/).map(v => new Integer(v)).desc("an integer")
|
||||
String = _ => P.regex(/(?:[^"\\]|\\")*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")')
|
||||
Word = _ => P.regex(/[a-zA-Z]+/).desc("a word")
|
||||
Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new Guid(v)).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value")
|
||||
PathSymbolEntity = _ => P.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v }))
|
||||
ReferencePath = r => P.seq(P.string("/"), r.PathSymbolEntity.map(v => v.toString()).sepBy1(P.string(".")).tieWith("."))
|
||||
.tie()
|
||||
@@ -80,7 +80,7 @@ export default class Grammar {
|
||||
return r.Integer
|
||||
case String:
|
||||
return r.String
|
||||
case Guid:
|
||||
case GuidEntity:
|
||||
return r.Guid
|
||||
case ObjectReferenceEntity:
|
||||
return r.Reference
|
||||
|
||||
Reference in New Issue
Block a user