Skip to content

Commit

Permalink
refactor api code into v2, cleanup EnumSet and remove displayId
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticdrew committed Apr 6, 2024
1 parent ff42beb commit c05bcff
Show file tree
Hide file tree
Showing 91 changed files with 409 additions and 427 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*
*/

package journeymap.client.api;
package journeymap.api.v2.client;

import com.mojang.blaze3d.platform.NativeImage;
import journeymap.client.api.display.Context;
import journeymap.client.api.display.DisplayType;
import journeymap.client.api.display.Displayable;
import journeymap.client.api.util.UIState;
import journeymap.common.api.waypoint.Waypoint;
import journeymap.api.v2.client.display.Context;
import journeymap.api.v2.client.display.DisplayType;
import journeymap.api.v2.client.display.Displayable;
import journeymap.api.v2.client.event.MappingEvent;
import journeymap.api.v2.client.util.UIState;
import journeymap.api.v2.common.waypoint.Waypoint;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -193,11 +194,11 @@ void requestMapTile(String modId, ResourceKey<Level> dimension, Context.MapType
* This call gets the current user's data path for saving custom addon data specific to the game/world the user is playing in.
* <p>
* This is only valid when Journeymap is mapping. Mods ideally should store this value on
* {@link journeymap.client.api.event.MappingEvent.Stage#MAPPING_STARTED} event.
* {@link MappingEvent.Stage#MAPPING_STARTED} event.
* <p>
* Note: Will method return null if not in world or not mapping.
* The path is flushed right after
* {@link journeymap.client.api.event.MappingEvent.Stage#MAPPING_STOPPED}
* {@link MappingEvent.Stage#MAPPING_STOPPED}
*
* @param modId The ModId
* @return a path similar to ./journeymap/data/{sp|mp}/{worldname}/addon-data/{modid}/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*
*/

package journeymap.client.api;
package journeymap.api.v2.client;

import journeymap.api.v2.common.event.ClientEventRegistry;

import javax.annotation.ParametersAreNonnullByDefault;

Expand All @@ -35,7 +37,7 @@ public interface IClientPlugin
* should retain a reference to the IClientAPI passed in, since that is what your plugin
* will use to add overlays, etc. to JourneyMap.
* <p>
* This is also a good time to call {@link journeymap.common.api.event.ClientEventRegistry} to subscribe to any
* This is also a good time to call {@link ClientEventRegistry} to subscribe to any
* desired Events.
*
* @param jmClientApi Client API implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*
*/

package journeymap.client.api;
package journeymap.api.v2.client;

import javax.annotation.Nullable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -36,11 +37,11 @@
public @interface JourneyMapPlugin
{
/**
* Mod Devs need to supply the version of journeymap-api the mod was built against,
* Mod Devs can supply the version of journeymap-api the mod was built against,
* so that it will not load the plugin if there is a breaking change.
*
* @return - The Api Version
*/
@Nullable
String apiVersion();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package journeymap.client.api.display;
package journeymap.api.v2.client.display;

/**
* Enums that describe the various display contexts in JourneyMap.
Expand All @@ -10,11 +10,6 @@ public interface Context
*/
enum UI implements Context
{
/**
* Any UI.
*/
Any,

/**
* The Fullscreen map UI.
*/
Expand All @@ -28,19 +23,31 @@ enum UI implements Context
/**
* The Webmap UI.
*/
Webmap
Webmap;

/**
* Any/All UIs.
*/
public static UI[] all()
{
return UI.values();
}
}

/**
* Map types.
*/
enum MapType implements Context
{
Any,
Day,
Night,
Underground,
Topo,
Biome
Biome;

public static MapType[] all()
{
return MapType.values();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

package journeymap.client.api.display;
package journeymap.api.v2.client.display;

import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*
*/

package journeymap.client.api.display;
package journeymap.api.v2.client.display;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.gson.annotations.Since;

import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -54,34 +53,16 @@ private Displayable()
displayType = null;
}

/**
* Constructor which will generate a GUID display id.
*
* @param modId the mod id
*/
protected Displayable(String modId)
{
this(modId, UUID.randomUUID().toString());
}

/**
* Constructor with explicit display id.
*
* @param modId the mod id
* @param displayId the display id
*/
protected Displayable(String modId, String displayId)
protected Displayable(String modId)
{
if (Strings.isNullOrEmpty(modId))
{
throw new IllegalArgumentException("modId may not be blank");
}
if (Strings.isNullOrEmpty(displayId))
{
throw new IllegalArgumentException("displayId may not be blank");
}

this.modId = modId;
this.id = displayId;
this.id = UUID.randomUUID().toString();
this.displayType = DisplayType.of(getClass());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package journeymap.client.api.display;
package journeymap.api.v2.client.display;

import journeymap.client.api.util.UIState;
import journeymap.api.v2.client.fullscreen.ModPopupMenu;
import journeymap.api.v2.client.util.UIState;
import net.minecraft.core.BlockPos;

import java.awt.geom.Point2D;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*
*/

package journeymap.client.api.display;
package journeymap.api.v2.client.display;

import journeymap.client.api.model.MapImage;
import journeymap.api.v2.client.IClientAPI;
import journeymap.api.v2.client.model.MapImage;
import net.minecraft.core.BlockPos;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -31,7 +32,7 @@
* Setters use the Builder pattern so they can be chained.
* <p>
* Note that like all Displayables, simply changing this object doesn't guarantee the player will get the changes.
* You must call {@link journeymap.client.api.IClientAPI#show(Displayable)} in order for the changes to take effect
* You must call {@link IClientAPI#show(Displayable)} in order for the changes to take effect
* in JourneyMap.
*/
@ParametersAreNonnullByDefault
Expand All @@ -45,14 +46,13 @@ public final class ImageOverlay extends Overlay
* Constructor.
*
* @param modId Your mod id.
* @param imageId A unique id for the marker (scoped to your mod) which can be used to remove/update it.
* @param northWestPoint Location of the top-left corner of the image.
* @param southEastPoint Location of the lower-right corner of the image.
* @param image The image to display as the overlay.
*/
public ImageOverlay(String modId, String imageId, BlockPos northWestPoint, BlockPos southEastPoint, MapImage image)
public ImageOverlay(String modId, BlockPos northWestPoint, BlockPos southEastPoint, MapImage image)
{
super(modId, imageId);
super(modId);
setNorthWestPoint(northWestPoint);
setSouthEastPoint(southEastPoint);
setImage(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*
*/

package journeymap.client.api.display;
package journeymap.api.v2.client.display;

import journeymap.client.api.model.MapImage;
import journeymap.api.v2.client.IClientAPI;
import journeymap.api.v2.client.model.MapImage;
import net.minecraft.core.BlockPos;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -32,7 +33,7 @@
* Setters use the Builder pattern so they can be chained.
* <p>
* Note that like all Displayables, simply changing this object doesn't guarantee the player will get the changes.
* You must call {@link journeymap.client.api.IClientAPI#show(Displayable)} in order for the changes to take effect
* You must call {@link IClientAPI#show(Displayable)} in order for the changes to take effect
* in JourneyMap.
*/
@ParametersAreNonnullByDefault
Expand All @@ -45,13 +46,12 @@ public final class MarkerOverlay extends Overlay
* Constructor.
*
* @param modId Your mod id.
* @param markerId A unique id for the marker (scoped to your mod) which can be used to remove/update it.
* @param point Location of the marker.
* @param icon The icon to display as the marker.
*/
public MarkerOverlay(String modId, String markerId, BlockPos point, MapImage icon)
public MarkerOverlay(String modId, BlockPos point, MapImage icon)
{
super(modId, markerId);
super(modId);
setPoint(point);
setIcon(icon);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
*
*/

package journeymap.client.api.display;
package journeymap.api.v2.client.display;

import com.google.common.base.MoreObjects;
import journeymap.client.api.model.TextProperties;
import journeymap.client.api.util.UIState;
import journeymap.api.v2.client.model.TextProperties;
import journeymap.api.v2.client.util.UIState;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.EnumSet;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import static journeymap.client.api.util.UIState.FULLSCREEN_ZOOM_MIN;
import static journeymap.client.api.util.UIState.ZOOM_IN_MAX;
import static journeymap.api.v2.client.util.UIState.FULLSCREEN_ZOOM_MIN;
import static journeymap.api.v2.client.util.UIState.ZOOM_IN_MAX;

/**
* Provides IDs and key information for map overlays in JourneyMap.
Expand All @@ -46,8 +48,8 @@ public abstract class Overlay extends Displayable
protected int minZoom = FULLSCREEN_ZOOM_MIN;
protected int maxZoom = ZOOM_IN_MAX;
protected int displayOrder;
protected EnumSet<Context.UI> activeUIs = EnumSet.of(Context.UI.Any);
protected EnumSet<Context.MapType> activeMapTypes = EnumSet.of(Context.MapType.Any);
protected Set<Context.UI> activeUIs = new HashSet<>(Arrays.asList(Context.UI.all()));
protected Set<Context.MapType> activeMapTypes = new HashSet<>(Arrays.asList(Context.MapType.all()));
protected TextProperties textProperties = new TextProperties();
protected IOverlayListener overlayListener;
protected boolean needsRerender = true;
Expand All @@ -56,11 +58,10 @@ public abstract class Overlay extends Displayable
* Constructor.
*
* @param modId the mod id
* @param displayId the display id
*/
Overlay(String modId, String displayId)
Overlay(String modId)
{
super(modId, displayId);
super(modId);
}

/**
Expand Down Expand Up @@ -247,7 +248,7 @@ public Overlay setTextProperties(TextProperties textProperties)
*
* @return enumset
*/
public EnumSet<Context.UI> getActiveUIs()
public Set<Context.UI> getActiveUIs()
{
return activeUIs;
}
Expand All @@ -258,13 +259,9 @@ public EnumSet<Context.UI> getActiveUIs()
* @param activeUIs active UIs
* @return this
*/
public Overlay setActiveUIs(EnumSet<Context.UI> activeUIs)
public Overlay setActiveUIs(Context.UI... activeUIs)
{
if (activeUIs.contains(Context.UI.Any))
{
activeUIs = EnumSet.of(Context.UI.Any);
}
this.activeUIs = activeUIs;
this.activeUIs.addAll(Arrays.asList(activeUIs));
return this;
}

Expand All @@ -273,7 +270,7 @@ public Overlay setActiveUIs(EnumSet<Context.UI> activeUIs)
*
* @return enumset
*/
public EnumSet<Context.MapType> getActiveMapTypes()
public Set<Context.MapType> getActiveMapTypes()
{
return activeMapTypes;
}
Expand All @@ -284,13 +281,9 @@ public EnumSet<Context.MapType> getActiveMapTypes()
* @param activeMapTypes active types
* @return this
*/
public Overlay setActiveMapTypes(EnumSet<Context.MapType> activeMapTypes)
public Overlay setActiveMapTypes(Context.MapType... activeMapTypes)
{
if (activeMapTypes.contains(Context.MapType.Any))
{
activeMapTypes = EnumSet.of(Context.MapType.Any);
}
this.activeMapTypes = activeMapTypes;
this.activeMapTypes.addAll(Arrays.asList(activeMapTypes));
return this;
}

Expand All @@ -303,8 +296,8 @@ public Overlay setActiveMapTypes(EnumSet<Context.MapType> activeMapTypes)
public boolean isActiveIn(UIState uiState)
{
return ((uiState.active && this.dimension == uiState.dimension)
&& (activeUIs.contains(Context.UI.Any) || activeUIs.contains(uiState.ui))
&& (activeMapTypes.contains(Context.MapType.Any) || activeMapTypes.contains(uiState.mapType))
&& activeUIs.contains(uiState.ui)
&& activeMapTypes.contains(uiState.mapType)
&& (this.minZoom <= uiState.zoom && this.maxZoom >= uiState.zoom));
}

Expand Down
Loading

0 comments on commit c05bcff

Please sign in to comment.