mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-03 23:55:04 +08:00
Fixes and Utility test added
This commit is contained in:
@@ -8,21 +8,19 @@ describe('empty spec', () => {
|
||||
cy.get("ueb-blueprint")
|
||||
.click(100, 300)
|
||||
.then(blueprint => Utility.paste(blueprint[0], String.raw`
|
||||
Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name="K2Node_CallFunction_7"
|
||||
FunctionReference=(MemberParent=/Script/CoreUObject.Class'"/Script/UMG.WidgetBlueprintLibrary"',MemberName="DrawLine")
|
||||
NodePosX=-400
|
||||
NodePosY=-496
|
||||
AdvancedPinDisplay=Hidden
|
||||
NodeGuid=1E381F16F1004F99B8FA2B31A302B728
|
||||
CustomProperties Pin (PinId=9450390250EA422BAF09BEC8929A9294,PinName="execute",PinToolTip="\nExec",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=C83869E5A13240F6B14F812FDB0AB4C2,PinName="then",PinToolTip="\nExec",Direction="EGPD_Output",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=29F8D8746CF548D28EB5C459761706DE,PinName="self",PinFriendlyName=NSLOCTEXT("K2Node", "Target", "Target"),PinToolTip="Target\nWidget Blueprint Library Object Reference",PinType.PinCategory="object",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.Class'"/Script/UMG.WidgetBlueprintLibrary"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultObject="/Script/UMG.Default__WidgetBlueprintLibrary",PersistentGuid=00000000000000000000000000000000,bHidden=True,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=D776BF6820F34C91BE75B9952CC791BE,PinName="Context",PinToolTip="Context\nPaint Context Structure (by ref)",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/UMG.PaintContext"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=True,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=4CABFB9E228940589C5A6DE7D4F4D084,PinName="PositionA",PinToolTip="Position A\nVector 2D Structure\n\nStarting position of the line in local space.",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/CoreUObject.Vector2D"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=F688B2830ED74443B306F450C430B45C,PinName="PositionB",PinToolTip="Position B\nVector 2D Structure\n\nEnding position of the line in local space.",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/CoreUObject.Vector2D"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=6A10CA2DBB4C4F23A9B61417A4039F6F,PinName="Tint",PinToolTip="Tint\nLinear Color Structure\n\nColor to render the line.",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/CoreUObject.LinearColor"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue="(R=1.000000,G=1.000000,B=1.000000,A=1.000000)",AutogeneratedDefaultValue="(R=1.000000,G=1.000000,B=1.000000,A=1.000000)",PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=7A6AC1B873304455A159B2434E733265,PinName="bAntiAlias",PinToolTip="Anti Alias\nBoolean\n\nWhether the line should be antialiased.",PinType.PinCategory="bool",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue="true",AutogeneratedDefaultValue="true",PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=True,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=9F002C20FBB94382B2AB8CC59B28BDA4,PinName="Thickness",PinToolTip="Thickness\nFloat (single-precision)\n\nHow many pixels thick this line should be.",PinType.PinCategory="real",PinType.PinSubCategory="float",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue="1.000000",AutogeneratedDefaultValue="1.000000",PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=True,bOrphanedPin=False,)
|
||||
Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name="K2Node_CallFunction_0"
|
||||
FunctionReference=(MemberParent=/Script/CoreUObject.Class'"/Script/UMG.WidgetBlueprintLibrary"',MemberName="DrawBox")
|
||||
NodePosX=-528
|
||||
NodePosY=16
|
||||
NodeGuid=CCD05D4C46B44D439A8A54892EF35583
|
||||
CustomProperties Pin (PinId=5FBDA39535314BB8A54233DACD0127B5,PinName="execute",PinToolTip="\nExec",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=50CAADA252984578932EC85ABF55694C,PinName="then",PinToolTip="\nExec",Direction="EGPD_Output",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=55779C53183948C1B4EF08ADB42E06EB,PinName="self",PinFriendlyName=NSLOCTEXT("K2Node", "Target", "Target"),PinToolTip="Target\nWidget Blueprint Library Object Reference",PinType.PinCategory="object",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.Class'"/Script/UMG.WidgetBlueprintLibrary"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultObject="/Script/UMG.Default__WidgetBlueprintLibrary",PersistentGuid=00000000000000000000000000000000,bHidden=True,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=7EB988E8F2B4448AAE788347A8B1A52A,PinName="Context",PinToolTip="Context\nPaint Context Structure (by ref)",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/UMG.PaintContext"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=True,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=6FC51CC5388D41A19A21A3BBB73D709D,PinName="Position",PinToolTip="Position\nVector 2D Structure",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/CoreUObject.Vector2D"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=CFF6C22A93A44624B9E9D3062A0D2C92,PinName="Size",PinToolTip="Size\nVector 2D Structure",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/CoreUObject.Vector2D"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=0F39A82607874DEBB85E7CF660A8CEE5,PinName="Brush",PinToolTip="Brush\nSlate Brush Asset Object Reference",PinType.PinCategory="object",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.Class'"/Script/Engine.SlateBrushAsset"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=24480A396D474F85A2891846975A2AC6,PinName="Tint",PinToolTip="Tint\nLinear Color Structure",PinType.PinCategory="struct",PinType.PinSubCategory="",PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct'"/Script/CoreUObject.LinearColor"',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue="(R=1.000000,G=1.000000,B=1.000000,A=1.000000)",AutogeneratedDefaultValue="(R=1.000000,G=1.000000,B=1.000000,A=1.000000)",PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
End Object
|
||||
`))
|
||||
})
|
||||
|
||||
@@ -155,27 +155,28 @@ describe("Entity initialization", () => {
|
||||
.which.is.instanceOf(SimpleObject)
|
||||
.and.is.deep.equal({ a: 12, b: 13 })
|
||||
)
|
||||
it("has quebec, a number between 1 and 10", () => expect(entity)
|
||||
it("has quebec undefined", () => expect(entity)
|
||||
.to.have.property("quebec")
|
||||
.which.is.a("number")
|
||||
.and.is.equal(1)
|
||||
.which.is.undefined
|
||||
)
|
||||
it("quebec can be assigned and it always filtered", () => {
|
||||
const entity = new ComplexEntity()
|
||||
entity.quebec = 2
|
||||
expect(entity.quebec).to.be.equal(2)
|
||||
expect(entity.quebec, "assigned 2").to.be.equal(2)
|
||||
entity["quebec"] = 7
|
||||
expect(entity.quebec).to.be.equal(7)
|
||||
expect(entity.quebec, "assigned 7").to.be.equal(7)
|
||||
entity.quebec = 1
|
||||
expect(entity.quebec).to.be.equal(1)
|
||||
expect(entity.quebec, "assigned 1").to.be.equal(1)
|
||||
entity["quebec"] = 10
|
||||
expect(entity.quebec).to.be.equal(10)
|
||||
expect(entity.quebec, "assigned 10").to.be.equal(10)
|
||||
entity.quebec = 0
|
||||
expect(entity.quebec).to.be.equal(1)
|
||||
expect(entity.quebec, "assigned 0").to.be.equal(10)
|
||||
entity["quebec"] = 11
|
||||
expect(entity.quebec).to.be.equal(10)
|
||||
expect(entity.quebec, "assigned 11").to.be.equal(10)
|
||||
entity.quebec = -1
|
||||
expect(entity.quebec).to.be.equal(1)
|
||||
expect(entity.quebec, "assigned -1").to.be.equal(10)
|
||||
entity.quebec = 6
|
||||
expect(entity.quebec, "assigned 6").to.be.equal(6)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
147
cypress/e2e/utility.cy.js
Normal file
147
cypress/e2e/utility.cy.js
Normal file
@@ -0,0 +1,147 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
import Utility from "../../js/Utility"
|
||||
|
||||
describe("Utility functions testing", () => {
|
||||
before(() => {
|
||||
expect(Utility,).to.be.a("function")
|
||||
})
|
||||
|
||||
context("Utility", () => {
|
||||
it("clamp method test", () => {
|
||||
expect(Utility.clamp(-4, -3)).to.be.equal(-3)
|
||||
expect(Utility.clamp(-1, -3, -2)).to.be.equal(-2)
|
||||
expect(Utility.clamp(5, 1, 11)).to.be.equal(5)
|
||||
})
|
||||
it("minDecimals method test", () => {
|
||||
expect(Utility.minDecimals(3.1, 3)).to.be.equal("3.100")
|
||||
expect(Utility.minDecimals(-100, 2)).to.be.equal("-100.00")
|
||||
expect(Utility.minDecimals(0.43, 0)).to.be.equal("0.43")
|
||||
expect(Utility.minDecimals(0.43, 1)).to.be.equal("0.43")
|
||||
expect(Utility.minDecimals(0.43, 2)).to.be.equal("0.43")
|
||||
expect(Utility.minDecimals(0.43, 3)).to.be.equal("0.430")
|
||||
expect(Utility.minDecimals(-2, 0)).to.be.equal("-2")
|
||||
})
|
||||
it("roundDecimals method test", () => {
|
||||
expect(Utility.roundDecimals(8.543943, 0)).to.be.equal(9)
|
||||
expect(Utility.roundDecimals(8.543943, 1)).to.be.equal(8.5)
|
||||
expect(Utility.roundDecimals(8.543943, 2)).to.be.equal(8.54)
|
||||
expect(Utility.roundDecimals(8.543943, 3)).to.be.equal(8.544)
|
||||
expect(Utility.roundDecimals(-2.192837, 0)).to.be.equal(-2)
|
||||
expect(Utility.roundDecimals(-2.192837, 1)).to.be.equal(-2.2)
|
||||
expect(Utility.roundDecimals(-2.192837, 2)).to.be.equal(-2.19)
|
||||
expect(Utility.roundDecimals(-2.192837, 3)).to.be.equal(-2.193)
|
||||
expect(Utility.roundDecimals(-2.192837, 4)).to.be.equal(-2.1928)
|
||||
})
|
||||
it("approximatelyEqual method test", () => {
|
||||
expect(Utility.approximatelyEqual(0.2 + 0.1, 0.3)).to.be.true
|
||||
expect(Utility.approximatelyEqual(-0.2 - 0.1, -0.3)).to.be.true
|
||||
expect(Utility.approximatelyEqual(0.1000001, 0.1)).to.be.false
|
||||
expect(Utility.approximatelyEqual(40.1 + 0.2, 40.3)).to.be.true
|
||||
expect(Utility.approximatelyEqual(2, 3)).to.be.false
|
||||
})
|
||||
it("equals method test", () => {
|
||||
expect(Utility.equals(0.2, 0.2)).to.be.true
|
||||
expect(Utility.equals(new Number(0.7), 0.7)).to.be.true
|
||||
expect(Utility.equals(-40.3, new Number(-40.3))).to.be.true
|
||||
expect(Utility.equals(new Number(-40.3), new Number(-40.3))).to.be.true
|
||||
expect(Utility.equals(0.2 + 0.1, 0.3)).to.be.false // Strict equality
|
||||
expect(Utility.equals(null, undefined)).to.be.false
|
||||
expect(Utility.equals(undefined, null)).to.be.false
|
||||
expect(Utility.equals(0, false)).to.be.false
|
||||
expect(Utility.equals(false, false)).to.be.true
|
||||
expect(Utility.equals(2n, 2)).to.be.true
|
||||
expect(Utility.equals(-6845, -6845n)).to.be.true
|
||||
expect(Utility.equals(7735n, 7736)).to.be.false
|
||||
expect(Utility.equals("abc", "abc")).to.be.true
|
||||
expect(Utility.equals(new String("abc"), new String("abc"))).to.be.true
|
||||
expect(Utility.equals("abc", "aBc")).to.be.false
|
||||
expect(Utility.equals(
|
||||
[-2, "alpha", new String("beta"), new Number(40), [1, 2, 3]],
|
||||
[new Number(-2), new String("alpha"), new String("beta"), new Number(40), new Array(1, 2, 3)]
|
||||
)).to.be.true
|
||||
expect(Utility.equals(
|
||||
[-2.1, "alpha", new String("beta"), new Number(40), [1, 2, 3]],
|
||||
[new Number(-2), new String("alpha"), new String("beta"), new Number(40), new Array(1, 2, 3)]
|
||||
)).to.be.false // First element is different
|
||||
expect(Utility.equals(
|
||||
[-2, "Alpha", new String("beta"), new Number(40), [1, 2, 3]],
|
||||
[new Number(-2), new String("alpha"), new String("beta"), new Number(40), new Array(1, 2, 3)]
|
||||
)).to.be.false // Second element is different
|
||||
})
|
||||
it("isValueOfType method test", () => {
|
||||
expect(Utility.isValueOfType(34, Number)).to.be.true
|
||||
expect(Utility.isValueOfType(new Number(34), Number)).to.be.true
|
||||
expect(Utility.isValueOfType("34", String)).to.be.true
|
||||
expect(Utility.isValueOfType("34", Number)).to.be.false
|
||||
})
|
||||
it("mergeArrays method test", () => {
|
||||
expect(Utility.mergeArrays(
|
||||
[],
|
||||
[]
|
||||
)).to.be.deep.equal(
|
||||
[]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
["alpba", "beta"],
|
||||
[]
|
||||
)).to.be.deep.equal(
|
||||
["alpba", "beta"]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
[],
|
||||
["alpba", "beta"]
|
||||
)).to.be.deep.equal(
|
||||
["alpba", "beta"]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
[1, 3, 5, 7, 9],
|
||||
[1, 2, 3, 4, 5]
|
||||
)).to.be.deep.equal(
|
||||
[1, 2, 3, 4, 5, 7, 9]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
[6, 7, 8],
|
||||
[1, 2, 3]
|
||||
)).to.be.deep.equal(
|
||||
[6, 7, 8, 1, 2, 3]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
["e", "f", "g", "h"],
|
||||
["a", "b", "c", "d"]
|
||||
)).to.be.deep.equal(
|
||||
["e", "f", "g", "h", "a", "b", "c", "d"]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
["e", "f", "g", "h"],
|
||||
["a", "b", "c", "d", "e"]
|
||||
)).to.be.deep.equal(
|
||||
["a", "b", "c", "d", "e", "f", "g", "h"]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
[2, 4, 6, 8],
|
||||
[6, 4, 2]
|
||||
)).to.be.deep.equal(
|
||||
[2, 4, 6, 8]
|
||||
)
|
||||
expect(Utility.mergeArrays(
|
||||
[2, 4, 6, 8],
|
||||
[4, 5, 6, 8, 1, 2]
|
||||
)).to.be.deep.equal(
|
||||
[2, 4, 5, 6, 8, 1]
|
||||
)
|
||||
})
|
||||
it("capitalFirstLetter method test", () => {
|
||||
expect(Utility.capitalFirstLetter("")).to.be.equal("")
|
||||
expect(Utility.capitalFirstLetter("hello world")).to.be.equal("Hello world")
|
||||
})
|
||||
it("range method test", () => {
|
||||
expect(Utility.range()).to.be.deep.equal([])
|
||||
expect(Utility.range(5, 5)).to.be.deep.equal([])
|
||||
expect(Utility.range(5, 6)).to.be.deep.equal([5])
|
||||
expect(Utility.range(1, 10, 3)).to.be.deep.equal([1, 4, 7])
|
||||
expect(Utility.range(0, -3)).to.be.deep.equal([0, -1, -2])
|
||||
expect(Utility.range(7, -7, -4)).to.be.deep.equal([7, 3, -1, -5])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -58,8 +58,8 @@ export default class ComplexEntity extends IEntity {
|
||||
},
|
||||
papa: () => new SimpleObject(12, 13),
|
||||
quebec: {
|
||||
value: 0, // will assign 1 according to filter
|
||||
filter: v => Utility.clamp(v, 1, 10),
|
||||
value: 0, // will assign undefined because it does not satisfy the predicate
|
||||
predicate: v => v >= 1 && v <= 10,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
82
dist/ueblueprint.js
vendored
82
dist/ueblueprint.js
vendored
@@ -41,7 +41,7 @@ class Configuration {
|
||||
"bool": i$3`117, 0, 0`,
|
||||
"byte": i$3`0, 110, 98`,
|
||||
"class": i$3`88, 0, 186`,
|
||||
"default": i$3`167, 167, 167`,
|
||||
"default": i$3`255, 255, 255`,
|
||||
"exec": i$3`240, 240, 240`,
|
||||
"int": i$3`32, 224, 173`,
|
||||
"int64": i$3`170, 224, 172`,
|
||||
@@ -65,6 +65,7 @@ class Configuration {
|
||||
end: "ueb-edit-text-end",
|
||||
}
|
||||
static enableZoomIn = ["LeftControl", "RightControl"] // Button to enable more than 0 (1:1) zoom
|
||||
static epsilon = 1e-8
|
||||
static expandGridSize = 400
|
||||
static focusEventName = {
|
||||
begin: "blueprint-focus",
|
||||
@@ -428,7 +429,7 @@ class Utility {
|
||||
return 1 / (1 + (x / (1 - x) ** -curvature))
|
||||
}
|
||||
|
||||
static clamp(val, min, max) {
|
||||
static clamp(val, min = -Infinity, max = Infinity) {
|
||||
return Math.min(Math.max(val, min), max)
|
||||
}
|
||||
|
||||
@@ -448,7 +449,7 @@ class Utility {
|
||||
*/
|
||||
static minDecimals(num, decimals = 1) {
|
||||
const powered = num * 10 ** decimals;
|
||||
if (Math.abs(powered % 1) > Number.EPSILON) {
|
||||
if (Math.abs(powered % 1) > Configuration.epsilon) {
|
||||
// More decimal digits than required
|
||||
return num.toString()
|
||||
}
|
||||
@@ -469,7 +470,7 @@ class Utility {
|
||||
* @param {Number} b
|
||||
*/
|
||||
static approximatelyEqual(a, b) {
|
||||
return !(Math.abs(a - b) > Number.EPSILON)
|
||||
return !(Math.abs(a - b) > Configuration.epsilon)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -552,12 +553,18 @@ class Utility {
|
||||
static equals(a, b) {
|
||||
a = Utility.sanitize(a);
|
||||
b = Utility.sanitize(b);
|
||||
if (a?.constructor === BigInt && b?.constructor === Number) {
|
||||
b = BigInt(b);
|
||||
} else if (a?.constructor === Number && b?.constructor === BigInt) {
|
||||
a = BigInt(a);
|
||||
}
|
||||
if (a === b) {
|
||||
return true
|
||||
}
|
||||
if (a instanceof Array && b instanceof Array) {
|
||||
return a.length == b.length && !a.find((value, i) => !Utility.equals(value, b[i]))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -579,16 +586,16 @@ class Utility {
|
||||
* @param {AnyValue} value
|
||||
* @param {AnyValueConstructor} type
|
||||
*/
|
||||
static isValueOfType(value, type) {
|
||||
return value === null || (value instanceof type || value.constructor === type)
|
||||
static isValueOfType(value, type, acceptNull = false) {
|
||||
return (acceptNull && value === null) || value instanceof type || value?.constructor === type
|
||||
}
|
||||
|
||||
/** @param {AnyValue} value */
|
||||
static sanitize(value, targetType = /** @type {AnyValueConstructor} */(value?.constructor)) {
|
||||
if (targetType instanceof Array) {
|
||||
let type = targetType.find(t => Utility.isValueOfType(value, t));
|
||||
if (targetType instanceof UnionType) {
|
||||
let type = targetType.types.find(t => Utility.isValueOfType(value, t, false));
|
||||
if (!type) {
|
||||
type = targetType[0];
|
||||
type = targetType.getFirstType();
|
||||
}
|
||||
targetType = type;
|
||||
}
|
||||
@@ -627,22 +634,25 @@ class Utility {
|
||||
a = [...a];
|
||||
b = [...b];
|
||||
restart:
|
||||
for (let j = 0; j < b.length; ++j) {
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (a[i] == b[j]) {
|
||||
// Found an element in common in the two arrays
|
||||
result.push(
|
||||
// Take and append all the elements skipped from a
|
||||
...a.splice(0, i),
|
||||
// Take and append all the elements skippend from b
|
||||
...b.splice(0, j),
|
||||
// Take and append the element in common
|
||||
...a.splice(0, 1)
|
||||
);
|
||||
b.shift(); // Remove the same element from b
|
||||
break restart
|
||||
while (true) {
|
||||
for (let j = 0; j < b.length; ++j) {
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (a[i] == b[j]) {
|
||||
// Found an element in common in the two arrays
|
||||
result.push(
|
||||
// Take and append all the elements skipped from a
|
||||
...a.splice(0, i),
|
||||
// Take and append all the elements skippend from b
|
||||
...b.splice(0, j),
|
||||
// Take and append the element in common
|
||||
...a.splice(0, 1)
|
||||
);
|
||||
b.shift(); // Remove the same element from b
|
||||
continue restart
|
||||
}
|
||||
}
|
||||
}
|
||||
break restart
|
||||
}
|
||||
// Append remaining the elements in the arrays and make it unique
|
||||
return [...(new Set(result.concat(...a, ...b)))]
|
||||
@@ -886,9 +896,15 @@ class IEntity {
|
||||
return this["#" + attributeName]
|
||||
},
|
||||
set(v) {
|
||||
if (attribute.predicate(v)) {
|
||||
this["#" + attributeName] = v;
|
||||
if (!attribute.predicate?.(v)) {
|
||||
console.warn(
|
||||
`UEBlueprint: Tried to assign attribute ${prefix}${attributeName} to `
|
||||
+ `${this.constructor.name} not satisfying the predicate`
|
||||
|
||||
);
|
||||
return
|
||||
}
|
||||
this["#" + attributeName] = v;
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -1629,6 +1645,10 @@ class Vector2DEntity extends IEntity {
|
||||
Y: 0,
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes);
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
super(values);
|
||||
/** @type {Number} */ this.X;
|
||||
@@ -1647,6 +1667,10 @@ class VectorEntity extends IEntity {
|
||||
Z: 0,
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes);
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
super(values);
|
||||
/** @type {Number} */ this.X;
|
||||
@@ -1941,6 +1965,10 @@ class VariableReferenceEntity extends IEntity {
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes);
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
super(values);
|
||||
/** @type {String} */ this.MemberName;
|
||||
@@ -2191,6 +2219,10 @@ class UnknownKeysEntity extends IEntity {
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes);
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
super(values);
|
||||
/** @type {String} */ this.lookbehind;
|
||||
|
||||
6
dist/ueblueprint.min.js
vendored
6
dist/ueblueprint.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -17,7 +17,7 @@ export default class Configuration {
|
||||
"bool": css`117, 0, 0`,
|
||||
"byte": css`0, 110, 98`,
|
||||
"class": css`88, 0, 186`,
|
||||
"default": css`167, 167, 167`,
|
||||
"default": css`255, 255, 255`,
|
||||
"exec": css`240, 240, 240`,
|
||||
"int": css`32, 224, 173`,
|
||||
"int64": css`170, 224, 172`,
|
||||
@@ -41,6 +41,7 @@ export default class Configuration {
|
||||
end: "ueb-edit-text-end",
|
||||
}
|
||||
static enableZoomIn = ["LeftControl", "RightControl"] // Button to enable more than 0 (1:1) zoom
|
||||
static epsilon = 1e-8
|
||||
static expandGridSize = 400
|
||||
static focusEventName = {
|
||||
begin: "blueprint-focus",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import Configuration from "./Configuration"
|
||||
import SubAttributesDeclaration from "./entity/SubObject"
|
||||
import UnionType from "./entity/UnionType"
|
||||
|
||||
/**
|
||||
* @typedef {import("./element/IElement").default} IElement
|
||||
@@ -33,7 +35,7 @@ export default class Utility {
|
||||
return 1 / (1 + (x / (1 - x) ** -curvature))
|
||||
}
|
||||
|
||||
static clamp(val, min, max) {
|
||||
static clamp(val, min = -Infinity, max = Infinity) {
|
||||
return Math.min(Math.max(val, min), max)
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ export default class Utility {
|
||||
*/
|
||||
static minDecimals(num, decimals = 1) {
|
||||
const powered = num * 10 ** decimals
|
||||
if (Math.abs(powered % 1) > Number.EPSILON) {
|
||||
if (Math.abs(powered % 1) > Configuration.epsilon) {
|
||||
// More decimal digits than required
|
||||
return num.toString()
|
||||
}
|
||||
@@ -74,7 +76,7 @@ export default class Utility {
|
||||
* @param {Number} b
|
||||
*/
|
||||
static approximatelyEqual(a, b) {
|
||||
return !(Math.abs(a - b) > Number.EPSILON)
|
||||
return !(Math.abs(a - b) > Configuration.epsilon)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,12 +159,18 @@ export default class Utility {
|
||||
static equals(a, b) {
|
||||
a = Utility.sanitize(a)
|
||||
b = Utility.sanitize(b)
|
||||
if (a?.constructor === BigInt && b?.constructor === Number) {
|
||||
b = BigInt(b)
|
||||
} else if (a?.constructor === Number && b?.constructor === BigInt) {
|
||||
a = BigInt(a)
|
||||
}
|
||||
if (a === b) {
|
||||
return true
|
||||
}
|
||||
if (a instanceof Array && b instanceof Array) {
|
||||
return a.length == b.length && !a.find((value, i) => !Utility.equals(value, b[i]))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,16 +192,16 @@ export default class Utility {
|
||||
* @param {AnyValue} value
|
||||
* @param {AnyValueConstructor} type
|
||||
*/
|
||||
static isValueOfType(value, type) {
|
||||
return value === null || (value instanceof type || value.constructor === type)
|
||||
static isValueOfType(value, type, acceptNull = false) {
|
||||
return (acceptNull && value === null) || value instanceof type || value?.constructor === type
|
||||
}
|
||||
|
||||
/** @param {AnyValue} value */
|
||||
static sanitize(value, targetType = /** @type {AnyValueConstructor} */(value?.constructor)) {
|
||||
if (targetType instanceof Array) {
|
||||
let type = targetType.find(t => Utility.isValueOfType(value, t))
|
||||
if (targetType instanceof UnionType) {
|
||||
let type = targetType.types.find(t => Utility.isValueOfType(value, t, false))
|
||||
if (!type) {
|
||||
type = targetType[0]
|
||||
type = targetType.getFirstType()
|
||||
}
|
||||
targetType = type
|
||||
}
|
||||
@@ -232,22 +240,25 @@ export default class Utility {
|
||||
a = [...a]
|
||||
b = [...b]
|
||||
restart:
|
||||
for (let j = 0; j < b.length; ++j) {
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (a[i] == b[j]) {
|
||||
// Found an element in common in the two arrays
|
||||
result.push(
|
||||
// Take and append all the elements skipped from a
|
||||
...a.splice(0, i),
|
||||
// Take and append all the elements skippend from b
|
||||
...b.splice(0, j),
|
||||
// Take and append the element in common
|
||||
...a.splice(0, 1)
|
||||
)
|
||||
b.shift() // Remove the same element from b
|
||||
break restart
|
||||
while (true) {
|
||||
for (let j = 0; j < b.length; ++j) {
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (a[i] == b[j]) {
|
||||
// Found an element in common in the two arrays
|
||||
result.push(
|
||||
// Take and append all the elements skipped from a
|
||||
...a.splice(0, i),
|
||||
// Take and append all the elements skippend from b
|
||||
...b.splice(0, j),
|
||||
// Take and append the element in common
|
||||
...a.splice(0, 1)
|
||||
)
|
||||
b.shift() // Remove the same element from b
|
||||
continue restart
|
||||
}
|
||||
}
|
||||
}
|
||||
break restart
|
||||
}
|
||||
// Append remaining the elements in the arrays and make it unique
|
||||
return [...(new Set(result.concat(...a, ...b)))]
|
||||
@@ -331,7 +342,7 @@ export default class Utility {
|
||||
* @param {Number} begin
|
||||
* @param {Number} end
|
||||
*/
|
||||
static range(begin, end, step = 1) {
|
||||
static range(begin = 0, end = 0, step = end >= begin ? 1 : -1) {
|
||||
return Array.from({ length: Math.ceil((end - begin) / step) }, (_, i) => begin + (i * step))
|
||||
}
|
||||
|
||||
|
||||
@@ -121,9 +121,15 @@ export default class IEntity {
|
||||
return this["#" + attributeName]
|
||||
},
|
||||
set(v) {
|
||||
if (attribute.predicate(v)) {
|
||||
this["#" + attributeName] = v
|
||||
if (!attribute.predicate?.(v)) {
|
||||
console.warn(
|
||||
`UEBlueprint: Tried to assign attribute ${prefix}${attributeName} to `
|
||||
+ `${this.constructor.name} not satisfying the predicate`
|
||||
|
||||
)
|
||||
return
|
||||
}
|
||||
this["#" + attributeName] = v
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user