-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
[Feature] Typesafe datatags #669
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this PR, I think there's a difference in what we view craft data tags to be. I view them as being type-safe data associated with a craft by a namespaced key.
The first and foremost of this would be the contacts system, I envision ContactsManager
would have the following line:
public static final NamespacedKey CONTACTS = new NamespacedKey("movecraft", "contacts");
Then anywhere you need to get the contacts from a craft you would run the following:
craft.getObjectTag(ContactsManager.CONTACTS)
to return an Object
. We'll have to decide what types we want explicit type safety on (since it's a lot of duplicate code for each), but here's my initial list that should cover most data in crafts:
- boolean
- double
- long
- String
- Object (like craft properties, type safety will be the responsibility of the user)
Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java
Outdated
Show resolved
Hide resolved
Movecraft/src/main/java/net/countercraft/movecraft/craft/SinkingCraftImpl.java
Outdated
Show resolved
Hide resolved
Movecraft/src/main/java/net/countercraft/movecraft/craft/CruiseOnPilotSubCraft.java
Outdated
Show resolved
Hide resolved
Movecraft/src/main/java/net/countercraft/movecraft/craft/SubCraftImpl.java
Outdated
Show resolved
Hide resolved
Movecraft/src/main/java/net/countercraft/movecraft/craft/SubcraftRotateCraft.java
Outdated
Show resolved
Hide resolved
api/src/main/java/net/countercraft/movecraft/craft/datatag/CraftDataTagContainer.java
Outdated
Show resolved
Hide resolved
api/src/main/java/net/countercraft/movecraft/craft/datatag/ICraftDataTag.java
Outdated
Show resolved
Hide resolved
Well what i expect is this:
If i want the contacts, i can just do That way, no cast is necessary and i can directly access it. |
That's an interesting approach and I like the implicit type safety built in. Is it possible we could change the supplier to a |
Yes, sure, that's a good idea! |
Movecraft/src/main/java/net/countercraft/movecraft/craft/CruiseOnPilotSubCraft.java
Outdated
Show resolved
Hide resolved
api/src/main/java/net/countercraft/movecraft/craft/datatag/CraftDataTagContainer.java
Outdated
Show resolved
Hide resolved
I've tried out this system to implement contacts and I much prefer it over the map it used to contain! Once this PR is cleaned up and merged I'll rebase these changes and merge them as well. |
I was also planning to use this for various changes i want to make to movecraft combat (mainly a overall rework of directors), glad you like it. |
…into typesafe-datatags # Conflicts: # api/src/main/java/net/countercraft/movecraft/craft/datatag/CraftDataTagContainer.java
Removed the unnecessary interface, that interface is only really useful if we want to directly support datatypes that can directly react to events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only thing left is to clear up the diff with the following files:
Movecraft/src/main/java/net/countercraft/movecraft/craft/CruiseOnPilotSubCraft.java
Movecraft/src/main/java/net/countercraft/movecraft/craft/SinkingCraftImpl.java
Movecraft/src/main/java/net/countercraft/movecraft/craft/SubCraftImpl.java
Movecraft/src/main/java/net/countercraft/movecraft/craft/SubcraftRotateCraft.java
Done |
Describe in detail what your pull request accomplishes
This PR adds typesafe datatags. Datatags work similar to craftfile properties in that they need to be registered before using them. Their value can be accessed via methods on the craft directly.
Checklist
TODO list:
API classesAccess methodsRelated PRs: