Skip to content

Commit

Permalink
Fix to not hide partially GM-only light sources in the menu
Browse files Browse the repository at this point in the history
It's possible for only some lights in an aura light source to be marked as GM-only (or OWNER-only). These were not being
shown in the right-click menu despite players being able to see them once equipped. Now these auras will show in the
menu, and will only be hidden if the entire auras is GM-only.

This also include a refactor to avoid duplicated logic between campaign light sources and unique light sources, while
also avoiding some of the complicated looping.
  • Loading branch information
kwvanderlinde committed Nov 2, 2023
1 parent f760dd0 commit 27a95c2
Showing 1 changed file with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -146,25 +147,7 @@ protected JMenu createLightSourceMenu() {

// Add unique light sources for the token.
{
JMenu subMenu = new JMenu("Unique");

List<LightSource> lightSources = new ArrayList<>(tokenUnderMouse.getUniqueLightSources());
Collections.sort(lightSources);

LIGHTSOURCES:
for (LightSource lightSource : lightSources) {
for (Light light : lightSource.getLightList()) {
// TODO Shouldn't we only skip if *all* child lights are GM only. And what about owner
// only?
if (light.isGM() && !MapTool.getPlayer().isGM()) {
continue LIGHTSOURCES;
}
}
JCheckBoxMenuItem menuItem =
new JCheckBoxMenuItem(new ToggleLightSourceAction(lightSource));
menuItem.setSelected(tokenUnderMouse.hasLightSource(lightSource));
subMenu.add(menuItem);
}
JMenu subMenu = createLightCategoryMenu("Unique", tokenUnderMouse.getUniqueLightSources());
if (subMenu.getItemCount() != 0) {
menu.add(subMenu);
menu.addSeparator();
Expand All @@ -173,30 +156,34 @@ protected JMenu createLightSourceMenu() {

for (Entry<String, Map<GUID, LightSource>> entry :
MapTool.getCampaign().getLightSourcesMap().entrySet()) {
JMenu subMenu = new JMenu(entry.getKey());

List<LightSource> lightSources = new ArrayList<>(entry.getValue().values());
Collections.sort(lightSources);

LIGHTSOURCES:
for (LightSource lightSource : lightSources) {
for (Light light : lightSource.getLightList()) {
// TODO Shouldn't we only skip if *all* child lights are GM only. And what about owner
// only?
if (light.isGM() && !MapTool.getPlayer().isGM()) {
continue LIGHTSOURCES;
}
}
JMenu subMenu = createLightCategoryMenu(entry.getKey(), entry.getValue().values());
if (subMenu.getItemCount() != 0) {
menu.add(subMenu);
}
}
return menu;
}

protected JMenu createLightCategoryMenu(String categoryName, Collection<LightSource> sources) {
JMenu subMenu = new JMenu(categoryName);

List<LightSource> lightSources = new ArrayList<>(sources);
Collections.sort(lightSources);

for (LightSource lightSource : lightSources) {
// Don't include light sources that don't have lights visible to the player. Note that the
// player must be an owner to use the popup, so don't bother checking `::isOwner()`.
boolean include =
MapTool.getPlayer().isGM() || !lightSource.getLightList().stream().allMatch(Light::isGM);
if (include) {
JCheckBoxMenuItem menuItem =
new JCheckBoxMenuItem(new ToggleLightSourceAction(lightSource));
menuItem.setSelected(tokenUnderMouse.hasLightSource(lightSource));
subMenu.add(menuItem);
}
if (subMenu.getItemCount() != 0) {
menu.add(subMenu);
}
}
return menu;

return subMenu;
}

protected Token getTokenUnderMouse() {
Expand Down

0 comments on commit 27a95c2

Please sign in to comment.