Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrimKey not called on struct of Map #59

Closed
enrico-giovanni opened this issue Aug 9, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@enrico-giovanni
Copy link

commented Aug 9, 2017

ue4 4.16.3
sio 0.6.2
environment: Blueprint

This JSON is what I receive on the server:

{
  "actions": {
    "my_key": {
      "value_5_0C62405F4F8CD0DE2EFE1C84058E954D": 123,
      "vector_8_CBC3A5A248B0C7EFE10514AF9D644328": {
        "x": 1,
        "y": 1,
        "z": 1
      }
    }
  }
}

when I Emit this Actions struct:
struct Actions, field 'actions' which is a map of String -> Action
struct Action, fields 'value' = Float, 'vector' = Vector

The two fields value and vector seem not properly trimmed

The BP nodes I'm using are:

variable get Actions -> Struct to JSON Object -> ToJSONValue -> Emit
@getnamo

This comment has been minimized.

Copy link
Owner

commented Aug 9, 2017

Interesting, can you provide an image of your blueprint node for setting the data?

@enrico-giovanni

This comment has been minimized.

Copy link
Author

commented Aug 11, 2017

Here I call the server just to show the JSON:
bp

This is the variable my_struct_with_map's definition:
struct_with_map

This is the type of the value-side of the map:
simple_struct

This is the some values assigned to the my_struct_with_map variable:
variable

This is what the server receives:

{
  "my_map": {
    "key_1": {
      "number_5_525DA0A94AA47E09B7EE258D9F1224B9": 1,
      "text_7_D6E1B42A479104B9D09BCF87B93E186D": "one"
    },
    "key_2": {
      "number_5_525DA0A94AA47E09B7EE258D9F1224B9": 2,
      "text_7_D6E1B42A479104B9D09BCF87B93E186D": "two"
    }
  }
}

This is the expected:

{
  "my_map": {
    "key_1": {
      "number": 1,
      "text": "one"
    },
    "key_2": {
      "number": 2,
      "text": "two"
    }
  }
}

In your code I've seen two or three trimming functions, which I believe you use to trim the default selector name assigned by UE4.
Maybe you need to recurse into the struct and apply one of these functions.

Btw, congrats for this nice library :)

EJ

@getnamo

This comment has been minimized.

Copy link
Owner

commented Aug 12, 2017

Excellent this should be all I need. I'll make a pass on this for the next update. Those names btw only appear when you create bp structs (vs c++ ue4 structs), I assume this is Unreal's way to ensure the keys are unique and you are correct it appears my trimming function isn't looping through them correctly for nested maps.

@getnamo getnamo self-assigned this Aug 21, 2017

@getnamo getnamo added the bug label Aug 21, 2017

@getnamo

This comment has been minimized.

Copy link
Owner

commented Nov 6, 2017

Pushed a fix for this in: f640f63

After initially checking the source, I realized I had never tested nor supported TMaps in BP Structs. Getting those to trim for UE4 struct with TMap -> JSON string was pretty simple (a few lines around f640f63#diff-be1bcd60c471b6d04fc0dfb03a660fceR274), but to get the other way working (json string -> fill struct with tmaps) was much more complicated.

I settled for a way to mark tmap short names in my trimming mapping function and replacing them when the json value gets filled in later (f640f63#diff-be1bcd60c471b6d04fc0dfb03a660fceR429). Because UE4 can only contain TMaps of the same type this system works pretty darn well.

To test the system I made a very complicated nested struct with different types of TMaps (int/string), nested structs of nested struct, arrays etc... definitely overboard.

Top Level Struct with various TMaps
toplevelstruct

My Simple Struct
simplestruct

Nested Test Struct
nestedstruct

Its sub struct
subnestedstruct

with a few default values tested

ue4struct

which went through a round trip of encoding and decoding

testingsetup

it spits out valid json

{  
   "integermap":{  
      "1.0":{  
         "vecKey":{  
            "x":1,
            "y":2,
            "z":3
         },
         "stringKey":"",
         "structKey":{  
            "testVar_3_asdlkajsd":false,
            "memberVar_5":[  
               4,
               5
            ],
            "stringKey":"I shouldn't clash!"
         },
         "arrayKey":[  

         ],
         "boolKey":true
      },
      "3.0":{  
         "vecKey":{  
            "x":0,
            "y":0,
            "z":0
         },
         "stringKey":"yolo",
         "structKey":{  
            "testVar_3_asdlkajsd":true,
            "memberVar_5":[  
               1.2000000476837158
            ],
            "stringKey":"I shouldn't clash!"
         },
         "arrayKey":[  
            {  
               "boolMeBro":[  
                  true,
                  false
               ]
            }
         ],
         "boolKey":false
      }
   },
   "stringfloatmap":{  
      "a string":-1,
      "another string":2.5339999198913574
   },
   "my_map":{  
      "key_1":{  
         "text":"one",
         "number":1
      },
      "key_2":{  
         "text":"two",
         "number":2
      }
   }
}

and the receiving struct correctly has the internal bp names set

debugview

This should be now be a dependable path, but let me know if you find a use case that doesn't pass.

Will coalesce a few more fixes before pushing a binary 4.18 release.

@getnamo

This comment has been minimized.

Copy link
Owner

commented Nov 8, 2017

Closing issue. Re-open if any bugs appear.

@getnamo getnamo closed this Nov 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.