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

Custom properties for game objects #163

Merged
merged 20 commits into from
May 9, 2023

Conversation

Dgzt
Copy link
Collaborator

@Dgzt Dgzt commented May 1, 2023

Implementation of #150 feature request.

Usage in editor:

  1. Click to the Add component button on a game object in inspector:
    image

  2. Select CUSTOM PROPERTIES item in the dropdown and click to the Add component button:
    image

  3. See the new custom properties component in inspector:
    image

    You can remove added custom properties component with the X button on the left side. And you can collapse this widget with ˇ button on the right side.

  4. Can add new custom property key-value pair with Add button. It will create an empty key-value pair and can change their texts.
    image

  5. There is only one restriction: can not be 2 keys with same text. In this case if the user click out from the key field the key's value change back to the previous valid value.
    image

Usage in runtime:

GameObject go = getYourGameObject();
CustomPropertiesComponent component = (CustomPropertiesComponent) go.findComponentByType(Component.Type.CUSTOM_PROPERTIES);
String hp = component.get("hp");
Gdx.app.log("", "HP: " + hp);

This is not braking change, you can use in any project without data lost.

@Dgzt Dgzt changed the title Custom properties for game objects #150 Custom properties for game objects May 1, 2023
@Dgzt Dgzt linked an issue May 1, 2023 that may be closed by this pull request
@Dgzt Dgzt added the enhancement New feature or request label May 1, 2023
@JamesTKhan
Copy link
Owner

JamesTKhan commented May 1, 2023

Hi @Dgzt I understand this is still a work in progress but it looks like this would be adding properties map to every single GameObject rather then an optional ECS style component that can be added/removed from GameObjects. Wanted to bring that up before you got too far

Ping me on discord if you have questions about that

@Dgzt Dgzt marked this pull request as ready for review May 4, 2023 11:45
@antzGames
Copy link
Collaborator

Errors in editor code:

GameObjectInspector.kt: (41, 25): Symbol is declared in module 'java.desktop' which does not export package 'sun.java2d.loops'

Removed unused import and its fine now. Starting to test.

@antzGames
Copy link
Collaborator

antzGames commented May 5, 2023

Here are some observations in the EDITOR:

  1. So when you try to add more than 1 light component you get a error popup saying you cannot add a duplicate component. For custom properties, you dont get an error, it just stay on the Add Component popup. We should be consistent imo.
  2. I cannot replicate this but the ordering of the key/value pairs sometimes just changes. Also when you save/exit/start Mundus the ordering changes. I dont consider this a big issue, but if you have an easy solution then maybe we should fix?
  3. I tested JSON and HTML as values in the editor and then saved and reopen project. For some reason on the JSON it escapes the quotes, but on the HTML it does not. The view on the Mundus editor is ok though. See saved file example below:
{customProperties:{A:1,C:"{    \"firstName\": \"John\",    \"lastName\": \"Doe\"}",B:<a class=anchor-link href=#json-arrays aria-hidden=true title="Anchor Link">,D:5}

Output in the RUNTIME (Desktop) is:

1
<a class=anchor-link href=#json-arrays aria-hidden=true title="Anchor Link">
{    "firstName": "John",    "lastName": "Doe"}
5
  1. I tried to test the field length limit without success. What is the field length limit?

@antzGames
Copy link
Collaborator

This breaks GWT compatibility on the runtime. Will not compile:

> Task :html:compileGwt
Compiling module com.antz.ode4libGDX.GdxDefinition
   Tracing compile failure path for type 'com.antz.ode4libGDX.screens.DemoCrashScreen'
      [ERROR] Errors in 'file:/C:/Users/antho/Downloads/GDX%20Stuff/My_GDX_Projects/ode4j-GWT-Compatible-libGDX/core/src/main/java/com/antz/ode4libGDX/screens/DemoCrashScreen.java'
         [ERROR] Line 492: CUSTOM_PROPERTIES cannot be resolved or is not a field
   [ERROR] Aborting compile due to errors in some input files
[ERROR] Error saving compilation unit to cache file: C:\Users\antho\Downloads\GDX Stuff\My_GDX_Projects\ode4j-GWT-Compatible-libGDX\html\build\gwt\cache\gwt-unitCache\gwt-unitCache-7b9fbb59f8661539c34f46974ce5fb573aac79fc-C90BB3B791D3293DB8D5BA1AB0A974D4-00000187ED130C59
java.io.IOException: Stream Closed
	at java.base/java.io.RandomAccessFile.seek0(Native Method)
	at java.base/java.io.RandomAccessFile.seek(RandomAccessFile.java:591)
	at com.google.gwt.dev.util.DiskCache.transferToStream(DiskCache.java:161)
	at com.google.gwt.dev.util.DiskCacheToken.writeObject(DiskCacheToken.java:73)

@Dgzt
Copy link
Collaborator Author

Dgzt commented May 6, 2023

Thank you for your test and response!

Errors in editor code:

GameObjectInspector.kt: (41, 25): Symbol is declared in module 'java.desktop' which does not export package 'sun.java2d.loops'

Removed unused import and its fine now. Starting to test.

I don't know how I didn't see this. Thank you, removed it.

1. So when you try to add more than 1 light component you get a error popup saying you cannot add a duplicate component.  For custom properties, you dont get an error, it just stay on the `Add Component` popup.  We should be consistent imo.

Fixed.

2. I cannot replicate this but the ordering of the key/value pairs sometimes just changes.  Also when you save/exit/start Mundus the ordering changes.  I dont consider this a big issue, but if you have an easy solution then maybe we should fix?

I tried to use libGDX's OrderedMap to store sorting, but seen it doesn't work. Currently I don't know good and easy solution for it. But if someone has an idea for it just please write.

3. I tested JSON and HTML as values in the editor and then saved and reopen project.  For some reason on the JSON it escapes the quotes, but on the HTML it does not.  The view on the Mundus editor is ok though. 

The libGDX's json parser does this, but them work in editor and runtime also so I think it is not problem.

4. I tried to test the field length limit without success.  What is the field length limit?

I didn't set limit for field. I think the limit is that what visui's VisTextField or libGDX's json parser can handle. I don' know how many is but more then enough for us.

This breaks GWT compatibility on the runtime. Will not compile:

> Task :html:compileGwt
Compiling module com.antz.ode4libGDX.GdxDefinition
   Tracing compile failure path for type 'com.antz.ode4libGDX.screens.DemoCrashScreen'
      [ERROR] Errors in 'file:/C:/Users/antho/Downloads/GDX%20Stuff/My_GDX_Projects/ode4j-GWT-Compatible-libGDX/core/src/main/java/com/antz/ode4libGDX/screens/DemoCrashScreen.java'
         [ERROR] Line 492: CUSTOM_PROPERTIES cannot be resolved or is not a field
   [ERROR] Aborting compile due to errors in some input files
[ERROR] Error saving compilation unit to cache file: C:\Users\antho\Downloads\GDX Stuff\My_GDX_Projects\ode4j-GWT-Compatible-libGDX\html\build\gwt\cache\gwt-unitCache\gwt-unitCache-7b9fbb59f8661539c34f46974ce5fb573aac79fc-C90BB3B791D3293DB8D5BA1AB0A974D4-00000187ED130C59
java.io.IOException: Stream Closed
	at java.base/java.io.RandomAccessFile.seek0(Native Method)
	at java.base/java.io.RandomAccessFile.seek(RandomAccessFile.java:591)
	at com.google.gwt.dev.util.DiskCache.transferToStream(DiskCache.java:161)
	at com.google.gwt.dev.util.DiskCacheToken.writeObject(DiskCacheToken.java:73)

Strange. I've tried with this:

...
import static com.mbrlabs.mundus.commons.scene3d.components.Component.Type.CUSTOM_PROPERTIES;
...

CustomPropertiesComponent component = (CustomPropertiesComponent) go.findComponentByType(CUSTOM_PROPERTIES);
...

and this also:

...
import com.mbrlabs.mundus.commons.scene3d.components.Component;
...

CustomPropertiesComponent component = (CustomPropertiesComponent) go.findComponentByType(Component.Type.CUSTOM_PROPERTIES);
...

But both work for me.
image

Could you post codes near line 492 in DemoCrashScreen.java? Where you used this component. I will try to reproduce this error.

@antzGames
Copy link
Collaborator

antzGames commented May 6, 2023

So my bad. I updated the build.gradle for core but not html project when I tested last night.

It was pointing to master snapshot sources from JTK's repo. That is why it couldnt find the new type during GWT compile.

I wouldnt worry about the ordering of the properties. So everything works fine. Good work. Thank you for doing this.

I will leave it up to @JamesTKhan to do final review and PR merge.

@JamesTKhan
Copy link
Owner

The sort order changing sounds a little strange. When I have some time to review I will try to replicate as I am wondering what is causing it.

…tom-properties

# Conflicts:
#	editor/CHANGES
#	gdx-runtime/CHANGES
@Dgzt
Copy link
Collaborator Author

Dgzt commented May 7, 2023

I think I found the reason of order problem. It called ObjectMap's putAll method instead of OrderedMap's method. I pushed the fix.

@JamesTKhan
Copy link
Owner

I should be able to test this out tomorrow

@JamesTKhan
Copy link
Owner

Looks good. I tested on Desktop and GWT and was able to retrieve data. If we find any edge case issues with it once it starts being used more we can patch it as needed. Thanks. @Dgzt I created a Wiki page using one of my old PR's and this PR to create a developer guide on how to add components to make it easier in the future. Let me know if it looks good since this is still fresh in your head.

https://github.com/JamesTKhan/Mundus/wiki/Steps-to-add-a-new-Component

@JamesTKhan JamesTKhan merged commit ff0d1a8 into JamesTKhan:master May 9, 2023
@Dgzt Dgzt deleted the game-object-custom-properties branch May 9, 2023 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ability to add meta data to GameObjects
3 participants