Various fixes

This commit is contained in:
barsdeveloper
2023-04-16 19:48:14 +02:00
parent c1bbbfef90
commit 6ef2225396
9 changed files with 188 additions and 18 deletions

View File

@@ -1,9 +1,11 @@
/// <reference types="cypress" />
import { generateNodeTest } from "../fixtures/testUtilities.js"
import Configuration from "../../js/Configuration.js"
import SVGIcon from "../../js/SVGIcon.js"
const tests = [
{
/*{
name: "ROS Change Element",
value: String.raw`
Begin Object Class=K2Node_CallFunction Name="K2Node_CallFunction_131095"
@@ -77,6 +79,74 @@ const tests = [
pins: 2,
delegate: false,
development: false,
},*/
{
name: "Flip Flop",
value: String.raw`
Begin Object Class=K2Node_MacroInstance Name="K2Node_MacroInstance_1262"
NodePosX=3984
NodePosY=-960
NodeGuid=968059974A02AF6B67D2879EC909179A
Begin Object Class=EdGraphPin Name="EdGraphPin_59688"
End Object
Begin Object Class=EdGraphPin Name="EdGraphPin_59689"
End Object
Begin Object Class=EdGraphPin Name="EdGraphPin_59690"
End Object
Begin Object Class=EdGraphPin Name="EdGraphPin_59691"
End Object
MacroGraphReference=(MacroGraph=EdGraph'/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:FlipFlop',GraphBlueprint=Blueprint'/Engine/EditorBlueprintResources/StandardMacros.StandardMacros',GraphGuid=BFFFAAE4434E166F549665AD1AA89B60)
Pins(0)=EdGraphPin'EdGraphPin_59688'
Pins(1)=EdGraphPin'EdGraphPin_59689'
Pins(2)=EdGraphPin'EdGraphPin_59690'
Pins(3)=EdGraphPin'EdGraphPin_59691'
Begin Object Name="EdGraphPin_59688"
PinType=(PinCategory="exec")
LinkedTo(0)=EdGraphPin'K2Node_InputKey_1185.EdGraphPin_42090'
LinkedTo(1)=EdGraphPin'K2Node_InputKey_14487.EdGraphPin_45417'
End Object
Begin Object Name="EdGraphPin_59689"
PinName="A"
Direction=EGPD_Output
PinType=(PinCategory="exec")
LinkedTo(0)=EdGraphPin'K2Node_CallFunction_7370.EdGraphPin_43320'
End Object
Begin Object Name="EdGraphPin_59690"
PinName="B"
Direction=EGPD_Output
PinType=(PinCategory="exec")
LinkedTo(0)=EdGraphPin'K2Node_CallFunction_44249.EdGraphPin_43272'
End Object
Begin Object Name="EdGraphPin_59691"
PinName="IsA"
Direction=EGPD_Output
PinType=(PinCategory="bool")
End Object
End Object
`,
color: Configuration.nodeColors.gray,
icon: SVGIcon.flipflop,
pins: 4,
pinName: ["A", "B", "IsA"],
delegate: false,
development: false,
additionalTest:
/** @param {import("../../js/element/NodeElement.js").default} node */
node => {
const entity = node.entity
expect(entity.Class.type).to.be.equal("/Script/BlueprintGraph.K2Node_MacroInstance")
expect(entity.MacroGraphReference.MacroGraph.type).to.be.equal("/Script/Engine.EdGraph")
expect(entity.MacroGraphReference.MacroGraph.path).to.be.equal("/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:FlipFlop")
expect(entity.MacroGraphReference.GraphBlueprint.type).to.be.equal("/Script/Engine.Blueprint")
expect(entity.MacroGraphReference.GraphBlueprint.path).to.be.equal("/Engine/EditorBlueprintResources/StandardMacros.StandardMacros")
const pinObjects = Object.keys(entity)
.filter(k => k.startsWith(Configuration.subObjectAttributeNamePrefix))
.map(k => /** @type {import("../../js/entity/ObjectEntity.js").default} */(entity[k]))
.filter(v => v.getType())
expect(pinObjects).to.be.of.length(4)
pinObjects.forEach(v => expect(v.getType()).to.be.equal(Configuration.nodeType.edGraphPinDeprecated))
expect(entity.getPinEntities()).to.be.of.length(4)
}
},
]

View File

@@ -61,5 +61,10 @@ export function generateNodeTest(nodeTest, getBlueprint) {
const words = value.split("\n").map(row => row.match(/\s*(\w+(\s+\w+)*).+/)?.[1]).filter(v => v?.length > 0)
return expect(value).to.match(getFirstWordOrder(words))
})
if (nodeTest.additionalTest) {
it("Additional tests", () => {
nodeTest.additionalTest(node)
})
}
})
}

61
dist/ueblueprint.js vendored
View File

@@ -104,6 +104,7 @@ class Configuration {
static nodeReflowEventName = "ueb-node-reflow"
static nodeType = {
addDelegate: "/Script/BlueprintGraph.K2Node_AddDelegate",
blueprint: "/Script/Engine.Blueprint",
callArrayFunction: "/Script/BlueprintGraph.K2Node_CallArrayFunction",
callFunction: "/Script/BlueprintGraph.K2Node_CallFunction",
comment: "/Script/UnrealEd.EdGraphNode_Comment",
@@ -114,6 +115,7 @@ class Configuration {
doN: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:Do N",
doOnce: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:DoOnce",
dynamicCast: "/Script/BlueprintGraph.K2Node_DynamicCast",
edGraph: "/Script/Engine.EdGraph",
edGraphPinDeprecated: "/Script/Engine.EdGraphPin_Deprecated",
enum: "/Script/CoreUObject.Enum",
enumLiteral: "/Script/BlueprintGraph.K2Node_EnumLiteral",
@@ -458,6 +460,7 @@ class UnionType {
}
/**
* @typedef {import("./Blueprint.js").default} Blueprint
* @typedef {import("./entity/IEntity.js").AnyValue} AnyValue
* @typedef {import("./entity/IEntity.js").AnyValueConstructor<*>} AnyValueConstructor
* @typedef {import("./entity/IEntity.js").AttributeInformation} TypeInformation
@@ -867,6 +870,16 @@ class Utility {
element.dispatchEvent(event);
}
/** @param {Blueprint} blueprint */
static async copy(blueprint) {
const event = new ClipboardEvent("copy", {
bubbles: true,
cancelable: true,
clipboardData: new DataTransfer(),
});
blueprint.dispatchEvent(event);
}
static animate(from, to, intervalSeconds, callback, timingFunction = x => {
const v = x ** 3.5;
return v / (v + ((1 - x) ** 3.5))
@@ -1363,6 +1376,20 @@ class ObjectReferenceEntity extends IEntity {
/** @type {String} */ this.path;
}
sanitize() {
if (this.type && !this.type.startsWith("/")) {
let deprecatedType = this.type + "_Deprecated";
let nodeType = Object.keys(Configuration.nodeType)
.find(type => {
const name = Utility.getNameFromPath(Configuration.nodeType[type]);
return name === this.type || name === deprecatedType
});
if (nodeType) {
this.type = Configuration.nodeType[nodeType];
}
}
}
getName() {
return Utility.getNameFromPath(this.path)
}
@@ -2915,6 +2942,23 @@ class ObjectEntity extends IEntity {
}
constructor(values, suppressWarns = false) {
let keys = Object.keys(values);
if (keys.some(k => k.startsWith(Configuration.subObjectAttributeNamePrefix))) {
let subObjectsValues = keys
.filter(k => k.startsWith(Configuration.subObjectAttributeNamePrefix))
.reduce(
(acc, k) => {
acc[k] = values[k];
return acc
},
{}
);
// Reorder suboejcts to be the first
values = {
...subObjectsValues,
...values,
};
}
super(values, suppressWarns);
/** @type {ObjectReferenceEntity} */ this.Class;
/** @type {String} */ this.Name;
@@ -2975,12 +3019,10 @@ class ObjectEntity extends IEntity {
}
// Legacy path names
if (this.Class.type && !this.Class.type.startsWith("/")) {
const nodeType = Object.keys(Configuration.nodeType)
.find(type => Utility.getNameFromPath(Configuration.nodeType[type]) === this.Class.type);
if (nodeType) {
this.Class.type = Configuration.nodeType[nodeType];
}
this.Class.sanitize();
if (this.MacroGraphReference) {
this.MacroGraphReference.MacroGraph?.sanitize();
this.MacroGraphReference.GraphBlueprint?.sanitize();
}
}
@@ -3074,6 +3116,11 @@ class ObjectEntity extends IEntity {
this.NodePosY.value = Math.round(value);
}
/** @returns {PinEntity[]} */
getPinEntities() {
return this.CustomProperties.filter(v => v instanceof PinEntity)
}
isEvent() {
switch (this.getClass()) {
case Configuration.nodeType.customEvent:
@@ -7951,7 +7998,7 @@ class NodeElement extends ISelectableDraggableElement {
/** @returns {PinEntity[]} */
getPinEntities() {
return this.entity.CustomProperties.filter(v => v instanceof PinEntity)
return this.entity.getPinEntities()
}
setLocation(x = 0, y = 0, acknowledge = true) {

File diff suppressed because one or more lines are too long

View File

@@ -80,6 +80,7 @@ export default class Configuration {
static nodeReflowEventName = "ueb-node-reflow"
static nodeType = {
addDelegate: "/Script/BlueprintGraph.K2Node_AddDelegate",
blueprint: "/Script/Engine.Blueprint",
callArrayFunction: "/Script/BlueprintGraph.K2Node_CallArrayFunction",
callFunction: "/Script/BlueprintGraph.K2Node_CallFunction",
comment: "/Script/UnrealEd.EdGraphNode_Comment",
@@ -90,6 +91,7 @@ export default class Configuration {
doN: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:Do N",
doOnce: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:DoOnce",
dynamicCast: "/Script/BlueprintGraph.K2Node_DynamicCast",
edGraph: "/Script/Engine.EdGraph",
edGraphPinDeprecated: "/Script/Engine.EdGraphPin_Deprecated",
enum: "/Script/CoreUObject.Enum",
enumLiteral: "/Script/BlueprintGraph.K2Node_EnumLiteral",

View File

@@ -3,6 +3,7 @@ import Configuration from "./Configuration.js"
import UnionType from "./entity/UnionType.js"
/**
* @typedef {import("./Blueprint.js").default} Blueprint
* @typedef {import("./entity/IEntity.js").AnyValue} AnyValue
* @typedef {import("./entity/IEntity.js").AnyValueConstructor<*>} AnyValueConstructor
* @typedef {import("./entity/IEntity.js").AttributeInformation} TypeInformation
@@ -413,6 +414,16 @@ export default class Utility {
element.dispatchEvent(event)
}
/** @param {Blueprint} blueprint */
static async copy(blueprint) {
const event = new ClipboardEvent("copy", {
bubbles: true,
cancelable: true,
clipboardData: new DataTransfer(),
})
blueprint.dispatchEvent(event)
}
static animate(from, to, intervalSeconds, callback, timingFunction = x => {
const v = x ** 3.5
return v / (v + ((1 - x) ** 3.5))

View File

@@ -280,7 +280,7 @@ export default class NodeElement extends ISelectableDraggableElement {
/** @returns {PinEntity[]} */
getPinEntities() {
return this.entity.CustomProperties.filter(v => v instanceof PinEntity)
return this.entity.getPinEntities()
}
setLocation(x = 0, y = 0, acknowledge = true) {

View File

@@ -258,6 +258,23 @@ export default class ObjectEntity extends IEntity {
}
constructor(values, suppressWarns = false) {
let keys = Object.keys(values)
if (keys.some(k => k.startsWith(Configuration.subObjectAttributeNamePrefix))) {
let subObjectsValues = keys
.filter(k => k.startsWith(Configuration.subObjectAttributeNamePrefix))
.reduce(
(acc, k) => {
acc[k] = values[k]
return acc
},
{}
)
// Reorder sub objects to be the first entries
values = {
...subObjectsValues,
...values,
}
}
super(values, suppressWarns)
/** @type {ObjectReferenceEntity} */ this.Class
/** @type {String} */ this.Name
@@ -302,7 +319,7 @@ export default class ObjectEntity extends IEntity {
/** @type {String?} */ this.ErrorMsg
/** @type {(PinEntity | UnknownPinEntity)[]} */ this.CustomProperties
// Legacy objects transform into pins
// Legacy nodes cleanup
if (this["Pins"] instanceof Array) {
this["Pins"]
.forEach(
@@ -315,15 +332,13 @@ export default class ObjectEntity extends IEntity {
this.CustomProperties.push(pinEntity)
}
})
delete this["Pins"]
}
// Legacy path names
if (this.Class.type && !this.Class.type.startsWith("/")) {
const nodeType = Object.keys(Configuration.nodeType)
.find(type => Utility.getNameFromPath(Configuration.nodeType[type]) === this.Class.type)
if (nodeType) {
this.Class.type = Configuration.nodeType[nodeType]
}
this.Class.sanitize()
if (this.MacroGraphReference) {
this.MacroGraphReference.MacroGraph?.sanitize()
this.MacroGraphReference.GraphBlueprint?.sanitize()
}
}
@@ -417,6 +432,11 @@ export default class ObjectEntity extends IEntity {
this.NodePosY.value = Math.round(value)
}
/** @returns {PinEntity[]} */
getPinEntities() {
return this.CustomProperties.filter(v => v instanceof PinEntity)
}
isEvent() {
switch (this.getClass()) {
case Configuration.nodeType.customEvent:

View File

@@ -1,3 +1,4 @@
import Configuration from "../Configuration.js"
import Utility from "../Utility.js"
import IEntity from "./IEntity.js"
@@ -27,6 +28,20 @@ export default class ObjectReferenceEntity extends IEntity {
/** @type {String} */ this.path
}
sanitize() {
if (this.type && !this.type.startsWith("/")) {
let deprecatedType = this.type + "_Deprecated"
let nodeType = Object.keys(Configuration.nodeType)
.find(type => {
const name = Utility.getNameFromPath(Configuration.nodeType[type])
return name === this.type || name === deprecatedType
})
if (nodeType) {
this.type = Configuration.nodeType[nodeType]
}
}
}
getName() {
return Utility.getNameFromPath(this.path)
}