Started work on serialization, refactoring

This commit is contained in:
barsdeveloper
2021-10-05 17:26:34 +02:00
parent 5032289e86
commit e8d9963a18
10 changed files with 283 additions and 19 deletions

17
js/ETypesNames.js Normal file
View File

@@ -0,0 +1,17 @@
export default class ETypesNames {
constructor(type) {
switch (type) {
case 'Class':
case 'None':
this.value = type
break
default:
throw new Error('Unexpected type name')
}
}
toString() {
return this.value
}
}

20
js/FGuid.js Normal file
View File

@@ -0,0 +1,20 @@
export default class FGuid {
constructor(guid) {
if (guid?.constructor?.name === 'String') {
this.value = guid
} else if (guid?.constructor?.name === 'FGuid') {
this.value = guid.value
} else {
let random = new Uint32Array(4);
crypto.getRandomValues(random)
this.value = ""
random.forEach(n => {
this.value += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
})
}
}
toString() {
return this.value
}
}

View File

@@ -84,10 +84,6 @@ export default class UEBlueprintObject extends USelectableDraggable {
}
this.style.setProperty('--ueb-position-x', this.location[0])
this.style.setProperty('--ueb-position-y', this.location[1])
let aDiv = document.createElement('div')
aDiv.innerHTML = this.render()
this.appendChild(aDiv.firstElementChild)
}
}

22
js/UGraphEntity.js Normal file
View File

@@ -0,0 +1,22 @@
/**
* A Graph Entity is an element that can stay directly (as a first child) on the blueprint grid. Those entities are either nodes or links
*/
export default class UGraphEntity extends HTMLElement {
constructor() {
super()
/** @type {import("./UEBlueprint").default}" */
this.blueprint = null
}
connectedCallback() {
this.blueprint = this.closest('u-blueprint')
let aDiv = document.createElement('div')
aDiv.innerHTML = this.render()
this.appendChild(aDiv.firstElementChild)
}
// Subclasses want to rewrite this
render() {
return ""
}
}

70
js/UGraphPin.js Normal file
View File

@@ -0,0 +1,70 @@
import FGuid from "./FGuid";
export default class UGraphPin {
constructor(Options) {
this.PinId = new FGuid(Options?.PinId)
this.PinName = Options?.PinName ?? ""
this.PinToolTip = Options?.PinToolTip ?? ""
this.PinType = {
PinCategory: Options?.PinType?.PinCategory ?? "object",
PinSubCategory: Options?.PinType?.PinSubCategory ?? "",
PinSubCategoryMemberReference: Options?.PinType?.PinSubCategoryMemberReference ?? "",
PinValueType: Options?.PinType?.PinValueType ?? "",
PinValueType: Options?.PinType?.ContainerType ?? "None",
bIsReference: Options?.PinType?.bIsReference ?? false,
bIsConst: Options?.PinType?.bIsConst ?? false,
bIsWeakPointer: Options?.PinType?.bIsWeakPointer ?? false,
bIsUObjectWrapper: Options?.PinType?.bIsUObjectWrapper ?? false
}
this.LinkedTo = Options?.LinkedTo ?? null
this.DefaultValue = Options?.DefaultValue ?? true
this.AutogeneratedDefaultValue = Options?.AutogeneratedDefaultValue ?? false
this.PersistentGuid = Options?.PersistentGuid ?? null
this.bHidden = Options?.bHidden ?? false
this.bNotConnectable = Options?.bNotConnectable ?? false
this.bDefaultValueIsReadOnly = Options?.bDefaultValueIsReadOnly ?? false
this.bDefaultValueIsIgnored = Options?.bDefaultValueIsIgnored ?? false
this.bAdvancedView = Options?.bAdvancedView ?? false
this.bOrphanedPin = Options?.bOrphanedPin ?? false
}
static serializeValue(value) {
// No quotes
if (value === null) {
return '()'
}
if (value?.constructor?.name === 'Boolean') {
return value ? 'True' : 'False'
}
if (value?.constructor?.name === 'ETypesNames' || value?.constructor?.name === 'FGuid') {
return value.toString()
}
// Quotes
if (value?.constructor?.name === 'String') {
return `"${value}"`
}
}
static subSerialize(prefix, object) {
let result = ""
prefix += prefix != "" ? "." : ""
for (const property in object) {
if (object[property]?.constructor?.name === 'Object') {
result += UGraphPin.subSerialize(prefix + property, object[property])
} else {
result += `${prefix + property}=${UGraphPin.serializeValue(object[property])},`
}
}
return result
}
serialize() {
let result = `CustomProperties Pin (${this.constructor.subSerialize('', this)})`
return result
}
toString() {
return this.serialize()
}
}

29
js/ULink.js Normal file
View File

@@ -0,0 +1,29 @@
import UBlueprintEntity from "./UBlueprintEntity"
export default class ULink extends UBlueprintEntity {
/**
*
* @typedef {{
* node: String,
* pin: String
* }} PinReference
* @param {?PinReference} source
* @param {?PinReference} destination
*/
constructor(source, destination) {
super()
this.source = source
this.destination = destination
}
render() {
return `
<svg viewBox="0 0 100 100">
<line x1="0" y1="80" x2="100" y2="20" stroke="black" />
</svg>
`
}
}
customElements.define('u-link', ULink)

View File

@@ -1,11 +1,10 @@
import UDrag from "./input/UDrag"
import UGraphEntity from "./UGraphEntity"
export default class USelectableDraggable extends HTMLElement {
export default class USelectableDraggable extends UGraphEntity {
constructor() {
super()
/** @type {import("./UEBlueprint").default}" */
this.blueprint = null
this.dragObject = null
this.location = [0, 0]
this.selected = false
@@ -17,7 +16,7 @@ export default class USelectableDraggable extends HTMLElement {
}
connectedCallback() {
this.blueprint = this.closest('u-blueprint')
super.connectedCallback()
this.dragObject = new UDrag(this, null, { // UDrag doesn't need blueprint
looseTarget: true
})

View File

@@ -1,4 +1,5 @@
import UEBlueprint from "./UEBlueprint"
import UEBlueprintObject from "./UEBlueprintObject"
import UGraphPin from "./UGraphPin"
export { UEBlueprint, UEBlueprintObject }
export { UEBlueprint, UEBlueprintObject, UGraphPin }