-
-
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
Initial event api, license headers #9
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.
I don't think that copy-pasting Fabric classes is the right way to do this at all. It was not sustainable for Patchwork and I don't want to support that approach here.
Maintaining a fork of Fabric API with the implementation modified to wrap around QSL is infinitely more maintainable because we can merge upstream and keep track of when they change things.
We're not assuming that anything in QSL is considered stable, so it is OK to create Fabric's APIs again almost verbatim (name style changing as needed) until we determine what changes we want.
Hmm glitch that seems more reasonable tbf. However I'd want a few conditions: Our backend reimplementation of fabric api MUST depend on a fixed version of QSL. Reason being I'll need to expose some internal compat bridges. |
Whatever you need--it's easier to change those kinds of things with experimentation, but it would be hard to lift FAPI out of QSL into a fork at a later date, so that's what's important to me. |
Ready for review. Grammar checking especially. Note the api is not final yet. |
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/Event.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/Event.java
Outdated
Show resolved
Hide resolved
@Documented // Documentation | ||
@Retention(RetentionPolicy.CLASS) // For static analysis | ||
@Target({ ElementType.FIELD, ElementType.METHOD }) | ||
public @interface ParameterInvokingEvent { |
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.
That annotation name is still super obscure, at least the doc is clear.
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.
Do you have a better idea?
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.
Sadly, no.
I don't think this can be named in a clear way anyway, and this is the best name so far.
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.
Writing the documentation is probably the best way to communicate what the annotation does.
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.
ParameterImplementedEvent
would be more clear to me, but at this point the documentation is good enough at describing its function that the name probably doesn't matter 😄
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.
Ah the age old naming question.
We could go for a more Gradle-like naming scheme with something like InvokesParameterAsCallback
for a name.
I'm not sure why you're randomly changing some names (besides |
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/Event.java
Outdated
Show resolved
Hide resolved
Fallback vs empty I'd be fine changing with some discussion. Implementation was an intentional choice since I have interpreted an Event as a holder object for a generated implementation of T. In the case of an array event, T is implemented via multiple callbacks that implement T. |
* | ||
* @param callback the callback. | ||
*/ | ||
public abstract void register(T callback); |
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.
If we wanted to add callback IDs and dependencies, now would be the time to do it. The signature of register
would then be something like
/**
* Register a callback to the event.
*
* @param id the identifier of this listener
* @param callback the callback
* @param after an array of identifiers this callback needs to be run after, if they are present
*/
public abstract void register(Identifier id, T callback, Identifier... after);
This can fairly easily be implemented in a way that does not impact invocation-time performance. It does not solve all possible problems that might arise from invoker order, but it does offer one more (relatively pain free) mechanism to mod developers.
It's worth noting that for the purpose of Fabric mod compatibility, any implementation needs to be capable of handling cases where id
is null, invoking it at any time.
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.
before
is necessary as well.
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.
before
is necessary as well.
That complicates things slightly as we can no longer just use varargs, but would be fine with some overrides (and probably better method names 😛).
/**
* Register a callback to the event.
*
* @param id the identifier of this listener
* @param callback the callback
*/
public void register(Identifier id, T callback) {
this.register(id, callback, new Identifier[0], new Identifier[0]);
}
/**
* Register a callback to the event.
*
* @param id the identifier of this listener
* @param callback the callback
* @param before an array of identifiers this callback needs to be run before, if they are present
*/
public void registerBefore(Identifier id, T callback, Identifier... before) {
this.register(id, callback, before, new Identifier[0]);
}
/**
* Register a callback to the event.
*
* @param id the identifier of this listener
* @param callback the callback
* @param after an array of identifiers this callback needs to be run after, if they are present
*/
public void registerAfter(Identifier id, T callback, Identifier... after) {
this.register(id, callback, new Identifier[0], after);
}
/**
* Register a callback to the event.
*
* @param id the identifier of this listener
* @param callback the callback
* @param before an array of identifiers this callback needs to be run before, if they are present
* @param after an array of identifiers this callback needs to be run after, if they are present
*/
public abstract void register(Identifier id, T callback, Identifier[] before, Identifier[] after);
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.
This seems very workable!
Though, shouldn't those T[]
/T...
arrays be Identifier[]
/Identifier...
, according to the javadocs?
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.
This seems very workable!
Though, shouldn't those
T[]
/T...
arrays beIdentifier[]
/Identifier...
, according to the javadocs?
Oops, yes, I knew I missed something.
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.
I know that, I was pointing out the incorrect typing on the varargs/arrays.
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.
Not fully convinced on this. Do not the API is NOT final yet
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.
Not convinced either, as Lambda explained on discord it makes every ID a rigid part of a mod's API.
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.
Screenshot of a compromise I might accept for int priorities given some surrounding conditions:
Haven seems to be on the other side of the coin on identifiers, I do note that identifiers have some advantages but some disadvantages that integers handle properly
changing priority ordering is an intentional act, you must have something to be ordered and know what you are ordered before.
no reordering is done given the absence of dependencies
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.
There is now an issue for this chain: #14
Co-authored-by: LambdAurora <aurora42lambda@gmail.com>
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/Event.java
Outdated
Show resolved
Hide resolved
@Technici4n returned to empty naming on the special |
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.
I think this is a good occasion to remove useless API complexity. Maybe ArrayEvent
should even be inlined into Event
directly.
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/EventFactory.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/Event.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/Event.java
Outdated
Show resolved
Hide resolved
* | ||
* @param callback the callback. | ||
*/ | ||
public abstract void register(T callback); |
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.
Not convinced either, as Lambda explained on discord it makes every ID a rigid part of a mod's API.
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.
Mostly just some documentation clunk that needs fixed, and this shouldn't be merged until we get the vote on #10 tomorrow or so.
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/ArrayEvent.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/ArrayEvent.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/ArrayEvent.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/ParameterInvokingEvent.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/ParameterInvokingEvent.java
Outdated
Show resolved
Hide resolved
library/core/qsl-base/src/main/java/org/quiltmc/qsl/api/event/ParameterInvokingEvent.java
Outdated
Show resolved
Hide resolved
I'm still unsure if we should resolve the debate of int/string/no priority before merging this PR. |
Co-authored-by: Glitch <glitch.g3431@gmail.com>
Heads up: decided package structure is |
I think we are done with this. |
The first task here is the new event api for using with QSL. It is quite similar to the api fabric has minus some slight semantic differences and names.
one thing needs to be done before I merge this