Skip to content

Conversation

@gaboose
Copy link
Contributor

@gaboose gaboose commented Sep 10, 2023

I noticed that if a field type is an array, value is set to rawValue. That's because

var isArray = type.startsWith('Array<');
if (isArray) {
    type = type.substring(1, type.length - 1);
}

transforms a type like Array<EntityRef> to rray<EntityRef. And that triggers the default switch arm, which is value = rawValue.

This change fixes the substring call to type.substring(6, type.length - 1) and converts/parses each item in the array individually.

trace(value) of an example Array<EntityRef> field type prints:

before the change

[{
    entityIid : a6ef0200-3b70-11ee-9c74-6bbcb7dc7313, 
    layerIid : 2bfdcfb0-c640-11ed-86f5-fb5c0168c734, 
    levelIid : d9fd3dc0-c640-11ed-8339-fd6e013c85c7, 
    worldIid : 963995f0-1460-11ee-8ba5-d7a793b95fd9
},{
    entityIid : a7d54350-3b70-11ee-9c74-c5e2355e556d, 
    layerIid : 2bfdcfb0-c640-11ed-86f5-fb5c0168c734, 
    levelIid : d9fd3dc0-c640-11ed-8339-fd6e013c85c7, 
    worldIid : 963995f0-1460-11ee-8ba5-d7a793b95fd9
}]

after the change

[LdtkEntityInstance(identifier=Rock def=... gridX=10 gridY=14 pxX=160 pxY=224 fieldInstances=[LdtkFieldInstance(identifier=sprite_states value=[idle 2] tile=null),LdtkFieldInstance(identifier=dialog value=null tile=null)] width=48 height=48 iid=a6ef0200-3b70-11ee-9c74-6bbcb7dc7313),LdtkEntityInstance(identifier=Rock def=... gridX=7 gridY=14 pxX=112 pxY=224 fieldInstances=[LdtkFieldInstance(identifier=sprite_states value=[idle 2] tile=null),LdtkFieldInstance(identifier=dialog value=null tile=null)] width=48 height=48 iid=a7d54350-3b70-11ee-9c74-c5e2355e556d)]

@jeremyfa
Copy link
Member

Ah good catch :) I didn't really test the Array type yet as you can see, so thank you for proofreading and fixing my code 😄

@jeremyfa jeremyfa merged commit 33f486b into ceramic-engine:master Sep 11, 2023
@gaboose
Copy link
Contributor Author

gaboose commented Sep 11, 2023

No problem! Just ran into it while working on my own little project. Really cool engine ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants