Skip to content

Commit

Permalink
cuboid.add_member: allow list input
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 21, 2020
1 parent 30b31a6 commit 2ef9481
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -999,27 +999,26 @@ public static void registerTags() {
});

// <--[tag]
// @attribute <CuboidTag.add_member[<cuboid>]>
// @attribute <CuboidTag.add_member[<cuboid>|...]>
// @returns CuboidTag
// @mechanism CuboidTag.add_member
// @description
// Returns a modified copy of this cuboid, with the input cuboid added at the end.
// Returns a modified copy of this cuboid, with the input cuboid(s) added at the end.
// -->
registerTag("add_member", (attribute, cuboid) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("The tag CuboidTag.add_member[...] must have a value.");
return null;
}
cuboid = cuboid.clone();
CuboidTag subCuboid = attribute.contextAsType(1, CuboidTag.class);
int member = cuboid.pairs.size() + 1;

// <--[tag]
// @attribute <CuboidTag.add_member[<cuboid>].at[<index>]>
// @attribute <CuboidTag.add_member[<cuboid>|...].at[<index>]>
// @returns CuboidTag
// @mechanism CuboidTag.add_member
// @description
// Returns a modified copy of this cuboid, with the input cuboid added at the specified index.
// Returns a modified copy of this cuboid, with the input cuboid(s) added at the specified index.
// -->
if (attribute.startsWith("at", 2)) {
if (!attribute.hasContext(2)) {
Expand All @@ -1035,8 +1034,18 @@ public static void registerTags() {
if (member > cuboid.pairs.size() + 1) {
member = cuboid.pairs.size() + 1;
}
LocationPair pair = subCuboid.pairs.get(0);
cuboid.pairs.add(member - 1, new LocationPair(pair.low, pair.high));
if (attribute.getContext(1).startsWith("li@")) { // Old cuboid identity used '|' symbol, so require 'li@' to be a list
for (CuboidTag subCuboid : attribute.contextAsType(1, ListTag.class).filter(CuboidTag.class, attribute.context)) {
LocationPair pair = subCuboid.pairs.get(0);
cuboid.pairs.add(member - 1, new LocationPair(pair.low, pair.high));
member++;
}
}
else {
CuboidTag subCuboid = attribute.contextAsType(1, CuboidTag.class);
LocationPair pair = subCuboid.pairs.get(0);
cuboid.pairs.add(member - 1, new LocationPair(pair.low, pair.high));
}
return cuboid;
});

Expand Down

0 comments on commit 2ef9481

Please sign in to comment.