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

onChangeMap add-on compliance, output added #4318

Merged
merged 7 commits into from
Nov 3, 2023

Conversation

Jmr3366
Copy link
Contributor

@Jmr3366 Jmr3366 commented Oct 3, 2023

Identify the Bug or Feature request

Feature #1574

Initial creation of onChangeMap was not add-on compliant.
This also resolves a false/positive event trigger when entering the menu Map - Edit Map dialog - Cancel (the event will still trigger if variables are changed and selecting OK).

Description of the Change

Compliance, tested with add-ons
Added output mapID,mapName

Possible Drawbacks

No additional drawbacks from prior PR

Release Notes

Any macro named onChangeMap located on a library token will execute when the map is changed.
The macro will also receive the mapID and mapName through macro.args.


This change is Reviewable

ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer();
try {
var libs = new LibraryManager().getLegacyEventTargets(ON_CHANGE_MAP_CALLBACK).get();
if (!libs.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's better to exit the method if libs.isEmpty(). Generally it's better to handle the conditions you don't want first. Otherwise they tend to be forgotten. You also get less indent.

null,
Collections.emptyMap());
} catch (InterruptedException | ExecutionException e) {
throw new AssertionError("Error retrieving library namespace");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to add the original exception as inner exception or at least log it. Otherwise it will be difficult to determine the reason for the AssertionError if it ever occurs in a log file.

@thelsing thelsing mentioned this pull request Oct 14, 2023
@Jmr3366 Jmr3366 requested a review from thelsing October 15, 2023 00:40
ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer();
try {
var libs = new LibraryManager().getLegacyEventTargets(ON_CHANGE_MAP_CALLBACK).get();
if (libs.isEmpty()) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add braces and indentation to this if for readability.

EventMacroUtil.callEventHandler(
ON_CHANGE_MAP_CALLBACK,
libraryNamespace,
currentZR.getZone().getId().toString() "," currentZR.getZone().toString(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the second argument as it's not needed - if the event handler does need it, it can get it based on the ID.

The result of Zone#toString() is also not very predictable: depending on whether it's a GM or player client, and whether the name and display name match, there could be several possible values. So if we keep the parameter, we should pick either getName() or getDisplayName() for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I glanced at the code and don't see an answer — why is the zone name being used instead of the id in the first place? If it's just informational, why not just the zone id and let the listener query other attributes that it wants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumingly thought there would be added value to include the textual name as it was readily available.
I will remove it.

@kwvanderlinde
Copy link
Collaborator

This also resolves a false/positive event trigger when entering the menu Map - Edit Map dialog - Cancel (the event will still trigger if variables are changed and selecting OK).

@Jmr3366 I don't see anything in this PR that will address that point. Is it just the addition of parameters to onChangeMap, or was there meant to be more to this PR?

@Jmr3366
Copy link
Contributor Author

Jmr3366 commented Oct 19, 2023

@kwvanderlinde I'm not certain what was causing the edit map-cancel event trigger issue. When I found that issue, I was also requested to test and make it add-on compliant. Once converted the issue I described was gone.

That said, this function is victim to how a rename of a map is really a copy, paste, delete (thus causing this event to fire). This update does not change that.

@cwisniew cwisniew added the feature Adding functionality that adds value label Oct 19, 2023
@cwisniew cwisniew added this pull request to the merge queue Nov 3, 2023
Merged via the queue into RPTools:develop with commit 574115a Nov 3, 2023
4 checks passed
@Jmr3366 Jmr3366 deleted the onChangeMap-upd branch November 3, 2023 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding functionality that adds value
Projects
Development

Successfully merging this pull request may close these issues.

5 participants