Skip to content

Commit

Permalink
PolygonTag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 22, 2021
1 parent 831b89d commit 2779b8a
Show file tree
Hide file tree
Showing 12 changed files with 936 additions and 52 deletions.
Expand Up @@ -480,6 +480,9 @@ else if (subit.equals("ellipsoid")) {
else if (lower.equals("ellipsoid")) {
return EllipsoidTag.getNotableEllipsoidsContaining(location).size() > 0;
}
else if (lower.equals("polygon")) {
return PolygonTag.getNotedPolygonsContaining(location).size() > 0;
}
else if (WorldTag.matches(inputText)) {
return CoreUtilities.equalsIgnoreCase(location.getWorld().getName(), lower);
}
Expand All @@ -499,6 +502,14 @@ else if (EllipsoidTag.matches(inputText)) {
}
return ellipsoid.contains(location);
}
else if (PolygonTag.matches(inputText)) {
PolygonTag polygon = PolygonTag.valueOf(inputText, getTagContext(path));
if (polygon == null || !polygon.isUnique()) {
Debug.echoError("Invalid event 'in:<area>' switch [" + getName() + "] (invalid polygon): '" + path.event + "' for " + path.container.getName());
return false;
}
return polygon.doesContainLocation(location);
}
else if (isAdvancedMatchable(lower)) {
MatchHelper matcher = createMatcher(lower);
for (CuboidTag cuboid : NotableManager.getAllType(CuboidTag.class)) {
Expand Down
@@ -1,7 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
import com.denizenscript.denizencore.objects.*;
Expand Down Expand Up @@ -78,7 +77,6 @@ public static List<CuboidTag> getNotableCuboidsContaining(Location location) {
cuboids.add(cuboid);
}
}

return cuboids;
}

Expand Down Expand Up @@ -510,7 +508,7 @@ public ListTag getBlocks(Attribute attribute) {
return getBlocks(null, attribute);
}

private boolean matchesMaterialList(Location loc, List<MaterialTag> materials, Attribute attribute) {
public static boolean matchesMaterialList(Location loc, List<MaterialTag> materials, Attribute attribute) {
if (materials == null) {
return true;
}
Expand Down Expand Up @@ -1540,11 +1538,11 @@ public static void registerTags() {
// Gets the name of a noted CuboidTag. If the cuboid isn't noted, this is null.
// -->
registerTag("note_name", (attribute, cuboid) -> {
String notname = NotableManager.getSavedId(cuboid);
if (notname == null) {
String noteName = NotableManager.getSavedId(cuboid);
if (noteName == null) {
return null;
}
return new ElementTag(notname);
return new ElementTag(noteName);
}, "notable_name");

registerTag("full", (attribute, cuboid) -> {
Expand Down
Expand Up @@ -1845,11 +1845,11 @@ else if (meta.hasDisplayName() && CoreUtilities.toLowerCase(meta.getDisplayName(
// Gets the name of a noted InventoryTag. If the inventory isn't noted, this is null.
// -->
registerTag("note_name", (attribute, object) -> {
String notname = NotableManager.getSavedId(object);
if (notname == null) {
String noteName = NotableManager.getSavedId(object);
if (noteName == null) {
return null;
}
return new ElementTag(notname);
return new ElementTag(noteName);
}, "notable_name");

// <--[tag]
Expand Down
Expand Up @@ -731,11 +731,11 @@ else if (container != null) {

registerTag("notable_name", (attribute, object) -> {
Deprecations.notableItems.warn();
String notname = NotableManager.getSavedId(object);
if (notname == null) {
String noteName = NotableManager.getSavedId(object);
if (noteName == null) {
return null;
}
return new ElementTag(notname);
return new ElementTag(noteName);
});

// <--[tag]
Expand Down
Expand Up @@ -2656,11 +2656,11 @@ else if (attribute.startsWith("unexplored_structure", 2) && attribute.hasContext
// Gets the name of a noted LocationTag. If the location isn't noted, this is null.
// -->
registerTag("note_name", (attribute, object) -> {
String notname = NotableManager.getSavedId((object));
if (notname == null) {
String noteName = NotableManager.getSavedId((object));
if (noteName == null) {
return null;
}
return new ElementTag(notname);
return new ElementTag(noteName);
}, "notable_name");

/////////////////////
Expand Down Expand Up @@ -2897,10 +2897,10 @@ else if (attribute.startsWith("vertical", 2)) {
});

// <--[tag]
// @attribute <LocationTag.is_within[<cuboid>/<ellipsoid>]>
// @attribute <LocationTag.is_within[<area>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the location is within the cuboid or ellipsoid.
// Returns whether the location is within the specified area (cuboid, ellipsoid, polygon, ...).
// -->
registerTag("is_within", (attribute, object) -> {
if (!attribute.hasContext(1)) {
Expand All @@ -2912,6 +2912,12 @@ else if (attribute.startsWith("vertical", 2)) {
return new ElementTag(ellipsoid.contains(object));
}
}
else if (PolygonTag.matches(attribute.getContext(1))) {
PolygonTag polygon = attribute.contextAsType(1, PolygonTag.class);
if (polygon != null) {
return new ElementTag(polygon.doesContainLocation(object));
}
}
else {
CuboidTag cuboid = attribute.contextAsType(1, CuboidTag.class);
if (cuboid != null) {
Expand Down Expand Up @@ -2999,6 +3005,21 @@ else if (attribute.startsWith("vertical", 2)) {
return ellipsoid_list;
});

// <--[tag]
// @attribute <LocationTag.polygons>
// @returns ListTag(PolygonTag)
// @description
// Returns a ListTag of all noted PolygonTags that include this location.
// -->
registerTag("polygons", (attribute, object) -> {
List<PolygonTag> polygons = PolygonTag.getNotedPolygonsContaining(object);
ListTag polygon_list = new ListTag();
for (PolygonTag polygon : polygons) {
polygon_list.addObject(polygon);
}
return polygon_list;
});

// <--[tag]
// @attribute <LocationTag.is_liquid>
// @returns ElementTag(Boolean)
Expand Down

0 comments on commit 2779b8a

Please sign in to comment.