mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-15 01:24:41 +08:00
Small refactoring
This commit is contained in:
128
dist/ueblueprint.js
vendored
128
dist/ueblueprint.js
vendored
@@ -829,7 +829,7 @@ class GuidEntity extends Entity {
|
||||
}
|
||||
let guid = "";
|
||||
values.forEach(n => {
|
||||
guid += ('00000000' + n.toString(16).toUpperCase()).slice(-8);
|
||||
guid += ("0".repeat(8) + n.toString(16).toUpperCase()).slice(-8);
|
||||
});
|
||||
return new GuidEntity({ valud: guid })
|
||||
}
|
||||
@@ -2097,6 +2097,34 @@ class Blueprint extends GraphElement {
|
||||
|
||||
customElements.define('u-blueprint', Blueprint);
|
||||
|
||||
class GraphLink extends GraphElement {
|
||||
|
||||
/**
|
||||
*
|
||||
* @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', GraphLink);
|
||||
|
||||
class GeneralSerializer extends Serializer {
|
||||
|
||||
constructor(wrap, entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) {
|
||||
@@ -2133,34 +2161,6 @@ class CustomSerializer extends GeneralSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
class GraphLink extends GraphElement {
|
||||
|
||||
/**
|
||||
*
|
||||
* @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', GraphLink);
|
||||
|
||||
class ToStringSerializer extends GeneralSerializer {
|
||||
|
||||
constructor(entityType) {
|
||||
@@ -2173,38 +2173,42 @@ class ToStringSerializer extends GeneralSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
ObjectEntity,
|
||||
new ObjectSerializer()
|
||||
);
|
||||
SerializerFactory.registerSerializer(
|
||||
PinEntity,
|
||||
new GeneralSerializer(v => `Pin (${v})`, PinEntity, "", ",", true)
|
||||
);
|
||||
SerializerFactory.registerSerializer(
|
||||
FunctionReferenceEntity,
|
||||
new GeneralSerializer(v => `(${v})`, FunctionReferenceEntity, "", ",", false)
|
||||
);
|
||||
SerializerFactory.registerSerializer(
|
||||
LocalizedTextEntity,
|
||||
new GeneralSerializer(v => `NSLOCTEXT(${v})`, LocalizedTextEntity, "", ",", false, "", _ => "")
|
||||
);
|
||||
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
|
||||
: ""
|
||||
))
|
||||
);
|
||||
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity));
|
||||
SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity));
|
||||
SerializerFactory.registerSerializer(IntegerEntity, new ToStringSerializer(IntegerEntity));
|
||||
function initializeSerializerFactory() {
|
||||
SerializerFactory.registerSerializer(
|
||||
ObjectEntity,
|
||||
new ObjectSerializer()
|
||||
);
|
||||
SerializerFactory.registerSerializer(
|
||||
PinEntity,
|
||||
new GeneralSerializer(v => `Pin (${v})`, PinEntity, "", ",", true)
|
||||
);
|
||||
SerializerFactory.registerSerializer(
|
||||
FunctionReferenceEntity,
|
||||
new GeneralSerializer(v => `(${v})`, FunctionReferenceEntity, "", ",", false)
|
||||
);
|
||||
SerializerFactory.registerSerializer(
|
||||
LocalizedTextEntity,
|
||||
new GeneralSerializer(v => `NSLOCTEXT(${v})`, LocalizedTextEntity, "", ",", false, "", _ => "")
|
||||
);
|
||||
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
|
||||
: ""
|
||||
))
|
||||
);
|
||||
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity));
|
||||
SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity));
|
||||
SerializerFactory.registerSerializer(IntegerEntity, new ToStringSerializer(IntegerEntity));
|
||||
}
|
||||
|
||||
initializeSerializerFactory();
|
||||
|
||||
export { Blueprint, GraphLink, GraphNode };
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class GuidEntity extends Entity {
|
||||
}
|
||||
let guid = ""
|
||||
values.forEach(n => {
|
||||
guid += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
guid += ("0".repeat(8) + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return new GuidEntity({ valud: guid })
|
||||
}
|
||||
|
||||
50
js/export.js
50
js/export.js
@@ -1,53 +1,9 @@
|
||||
import Blueprint from "./Blueprint"
|
||||
import CustomSerializer from "./serialization/CustomSerializer"
|
||||
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 IntegerEntity from "./entity/IntegerEntity"
|
||||
import LocalizedTextEntity from "./entity/LocalizedTextEntity"
|
||||
import ObjectEntity from "./entity/ObjectEntity"
|
||||
import ObjectReferenceEntity from "./entity/ObjectReferenceEntity"
|
||||
import ObjectSerializer from "./serialization/ObjectSerializer"
|
||||
import PathSymbolEntity from "./entity/PathSymbolEntity"
|
||||
import PinEntity from "./entity/PinEntity"
|
||||
import PinReferenceEntity from "./entity/PinReferenceEntity"
|
||||
import SerializerFactory from "./serialization/SerializerFactory"
|
||||
import ToStringSerializer from "./serialization/ToStringSerializer"
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
ObjectEntity,
|
||||
new ObjectSerializer()
|
||||
)
|
||||
SerializerFactory.registerSerializer(
|
||||
PinEntity,
|
||||
new GeneralSerializer(v => `Pin (${v})`, PinEntity, "", ",", true)
|
||||
)
|
||||
SerializerFactory.registerSerializer(
|
||||
FunctionReferenceEntity,
|
||||
new GeneralSerializer(v => `(${v})`, FunctionReferenceEntity, "", ",", false)
|
||||
)
|
||||
SerializerFactory.registerSerializer(
|
||||
LocalizedTextEntity,
|
||||
new GeneralSerializer(v => `NSLOCTEXT(${v})`, LocalizedTextEntity, "", ",", false, "", _ => "")
|
||||
)
|
||||
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
|
||||
: ""
|
||||
))
|
||||
)
|
||||
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity))
|
||||
SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity))
|
||||
SerializerFactory.registerSerializer(IntegerEntity, new ToStringSerializer(IntegerEntity))
|
||||
import initializeSerializerFactory from "./serialization/initializeSerializerFactory"
|
||||
|
||||
initializeSerializerFactory()
|
||||
|
||||
export { Blueprint as Blueprint, GraphNode as GraphNode, GraphLink as GraphLink }
|
||||
50
js/serialization/initializeSerializerFactory.js
Normal file
50
js/serialization/initializeSerializerFactory.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import CustomSerializer from "./CustomSerializer"
|
||||
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity"
|
||||
import GeneralSerializer from "./GeneralSerializer"
|
||||
import GuidEntity from "../entity/GuidEntity"
|
||||
import IntegerEntity from "../entity/IntegerEntity"
|
||||
import LocalizedTextEntity from "../entity/LocalizedTextEntity"
|
||||
import ObjectEntity from "../entity/ObjectEntity"
|
||||
import ObjectReferenceEntity from "../entity/ObjectReferenceEntity"
|
||||
import ObjectSerializer from "./ObjectSerializer"
|
||||
import PathSymbolEntity from "../entity/PathSymbolEntity"
|
||||
import PinEntity from "../entity/PinEntity"
|
||||
import PinReferenceEntity from "../entity/PinReferenceEntity"
|
||||
import SerializerFactory from "./SerializerFactory"
|
||||
import ToStringSerializer from "./ToStringSerializer"
|
||||
|
||||
export default function initializeSerializerFactory() {
|
||||
SerializerFactory.registerSerializer(
|
||||
ObjectEntity,
|
||||
new ObjectSerializer()
|
||||
)
|
||||
SerializerFactory.registerSerializer(
|
||||
PinEntity,
|
||||
new GeneralSerializer(v => `Pin (${v})`, PinEntity, "", ",", true)
|
||||
)
|
||||
SerializerFactory.registerSerializer(
|
||||
FunctionReferenceEntity,
|
||||
new GeneralSerializer(v => `(${v})`, FunctionReferenceEntity, "", ",", false)
|
||||
)
|
||||
SerializerFactory.registerSerializer(
|
||||
LocalizedTextEntity,
|
||||
new GeneralSerializer(v => `NSLOCTEXT(${v})`, LocalizedTextEntity, "", ",", false, "", _ => "")
|
||||
)
|
||||
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
|
||||
: ""
|
||||
))
|
||||
)
|
||||
SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity))
|
||||
SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity))
|
||||
SerializerFactory.registerSerializer(IntegerEntity, new ToStringSerializer(IntegerEntity))
|
||||
}
|
||||
Reference in New Issue
Block a user