-
Notifications
You must be signed in to change notification settings - Fork 144
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
Plugin API ergonomics #395
Comments
on { ItemOnItemMessage::class }
.where { usedId == SOME_ID && targetId == SOME_OTHER_ID ||
usedId == SOME_OTHER_ID && targetId == SOME_ID
}
.then { player -> ... } (Almost?) every Other examples would include looking up players/objects/npcs when handling frames that reference their index (like |
Utility methods to deduce the indefinite article (a/an) for a string (this already exists in core in |
On getting rid of the concept of "messages" from plugins, these are the current calls to
|
Using inline reified functions in the New syntax would be something along the lines of this: on<NpcActionMessage>().where { predicate }.then { consumer } Thoughts? |
On second thought, maybe we could get rid of the predefined If we went this route, we could supply the predicate inside the consumed event itself, proposed syntax would be something along the lines of: on<NpcActionMessage> {
return@on if (predicate)
// .. consume message ..
} |
This was considered initially, but I went with the current form because of the consistency with the lambdas.
I think the current |
I think we can get rid of the |
What about reducing the amount of chaining necessary? We might be offering too much flexibility. For example, this is a collection of examples on how buttons are handled at the moment: on { ButtonMessage::class }
.where { widgetId in Emote.MAP }
.then { player ->
player.playAnimation(Emote.fromButton(widgetId)!!.animation)
}
on_button(LOGOUT_BUTTON_ID)
.where { widgetId == LOGOUT_BUTTON_ID }
.then { it.logout() }
on { ButtonMessage::class }
.where { widgetId == WALK_BUTTON_ID || widgetId == RUN_BUTTON_ID }
.then {
it.toggleRunning()
} These are the most common patterns. Maps of widget IDs to other types, or simple comparisons against a few widget IDs. Here's some shorter examples: on_button(Emote.MAP) {
player.playAnimation(Emote.fromButton(widgetId)!!.animation)
}
on_button(LOGOUT_BUTTON_ID) {
it.logout()
}
on_button(WALK_BUTTON_ID, RUN_BUTTON_ID) {
it.toggleRunning()
} This is quite a bit cleaner for all those cases. By providing a few new simple overloads we can get rid of a bunch of boilerplate and reduce the level of indentation by 1. Object actions. This might even be cleaner if we wired up creation of the old on { ObjectActionMessage::class }
.where { option == 2 && id in DUMMY_IDS }
.then { DummyAction.start(this, it, position) } new on_object_action(DUMMY_IDS, option = 2) {
DummyAction.start(this, it, position)
} Player events. old on_event { MobPositionUpdateEvent::class }
.where { mob is Player }
.then {
for ((area, action) in actions) {
if (mob.position in area) {
if (next in area) {
action.inside(mob as Player, next)
} else {
action.exit(mob as Player, next)
}
} else if (next in area) {
action.entrance(mob as Player, next)
}
}
} new on_player_event<MobPositionUpdateEvent> {
for ((area, action) in actions) {
if (mob.position in area) {
if (next in area) {
action.inside(mob as Player, next)
} else {
action.exit(mob as Player, next)
}
} else if (next in area) {
action.entrance(mob as Player, next)
}
}
} |
No description provided.
The text was updated successfully, but these errors were encountered: