barsdeveloper / ueblueprint

Unreal Engine's Blueprint visualization web library
https://barsdeveloper.github.io/ueblueprint/
MIT License
46 stars 13 forks source link

R, G, B, A keys can have any type #21

Closed barsdeveloper closed 2 months ago

barsdeveloper commented 6 months ago
Begin Object Class=/Script/UnrealEd.MaterialGraphNode Name="MaterialGraphNode_202" ExportPath=/Script/UnrealEd.MaterialGraphNode'/Engine/Transient.卡通:MaterialGraph_0.MaterialGraphNode_202'
   Begin Object Class=/Script/Engine.MaterialExpressionSubtract Name="MaterialExpressionSubtract_10" ExportPath=/Script/Engine.MaterialExpressionSubtract'/Engine/Transient.卡通:MaterialGraph_0.MaterialGraphNode_202.MaterialExpressionSubtract_10'
   End Object
   Begin Object Name="MaterialExpressionSubtract_10" ExportPath=/Script/Engine.MaterialExpressionSubtract'/Engine/Transient.卡通:MaterialGraph_0.MaterialGraphNode_202.MaterialExpressionSubtract_10'
      A=(Expression="/Script/Engine.MaterialExpressionSaturate'MaterialGraphNode_237.MaterialExpressionSaturate_3'")
      B=(Expression="/Script/Engine.MaterialExpressionSaturate'MaterialGraphNode_201.MaterialExpressionSaturate_7'")
      MaterialExpressionEditorX=0
      MaterialExpressionEditorY=0
      MaterialExpressionGuid=7202C13642DA1225C118CF867599387C
      Material="/Script/UnrealEd.PreviewMaterial'/Engine/Transient.卡通'"
   End Object
   MaterialExpression=/Script/Engine.MaterialExpressionSubtract'MaterialExpressionSubtract_10'
   NodePosX=0
   NodePosY=0
   NodeGuid=7008F5AC49E8F5BFD4C707819A58C021
   CustomProperties Pin (PinId=86D4DE5E48C71A576ED0519B982907B3,PinName="A",PinType.PinCategory="optional",PinType.PinSubCategory="red",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",LinkedTo=(),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
   CustomProperties Pin (PinId=5C75E1374E1E7436C72B9FA072875C04,PinName="B",PinType.PinCategory="optional",PinType.PinSubCategory="red",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",LinkedTo=(),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
   CustomProperties Pin (PinId=528D346A49976B0854764CA755AF2F93,PinName="Output",PinFriendlyName=NSLOCTEXT("MaterialGraphNode", "Space", " "),Direction="EGPD_Output",PinType.PinCategory="",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,LinkedTo=(),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
End Object

Error

A=(Expression="/Script/Engine.MaterialExpressionSaturate'MaterialGraphNode_237.MaterialExpressionSaturate_3'") B=(Expression="/Script/Engine.MaterialExpressionSaturate'MaterialGraphNode_201.MaterialExpressionSaturate_7'")

Originally posted by @chendongde310 in https://github.com/barsdeveloper/ueblueprint/issues/18#issuecomment-2105616336

chendongde310 commented 6 months ago

This is a Temporary Solution: To avoid such errors, we can prepend a custom complex character prefix (e.g., 'UNT') to these strings before parsing and remove it after serialization. This method employs specific functions to escape regex special characters, add the prefix, and remove it.

Implementation Code:

// Function to add a prefix
addUntPrefix(value) {
    function escapeRegExp(string) {
        return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Escaping special characters in regex
    }
    const rules = ["A=(Expression=", "B=(Expression="];
    let result = value;
    rules.forEach(rule => {
        const pattern = new RegExp(escapeRegExp(rule), 'g');
        result = result.replace(pattern, `_UNT_${rule}`);
    });
    return result;
}

// Function to parse multiple objects using the prefix
readMultiple(value) {
    return ObjectEntity.getMultipleObjectsGrammar().parse(this.addUntPrefix(value))
}

// Function to remove the prefix
removeUntPrefix(value) {
    return value.replace(/_UNT_/g, '');
}

// Using the removal function during writing
doWrite(
    entity,
    insideString,
    indentation = "",
    wrap = this.wrap,
    attributeSeparator = this.attributeSeparator,
    trailingSeparator = this.trailingSeparator,
    attributeValueConjunctionSign = this.attributeValueConjunctionSign,
    attributeKeyPrinter = this.attributeKeyPrinter,
) {
    // Omitting the specific writing logic
    return this.removeUntPrefix(result)
}

Explanation: This is a temporary solution to handle specific string formats by temporarily adding a prefix before the string is parsed and removing it when needed. This approach relies on specific string formats and regex rules, and may require adjustments based on actual usage scenarios.