Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[ldtk] parse array type values in LdtkFieldInstance - #123

#123
Merged
jeremyfa merged 1 commit into
ceramic-engine:masterceramic-engine/ceramic:masterfrom
gaboose:mastergaboose/ceramic:masterCopy head branch name to clipboard
Sep 11, 2023
Merged

[ldtk] parse array type values in LdtkFieldInstance#123
jeremyfa merged 1 commit into
ceramic-engine:masterceramic-engine/ceramic:masterfrom
gaboose:mastergaboose/ceramic:masterCopy head branch name to clipboard

Conversation

@gaboose

@gaboose gaboose commented Sep 10, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

gaboose commented Sep 11, 2023

Copy link
Copy Markdown
Contributor Author

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.