Skip to content

Commit

Permalink
(NEEDS VALIDATION) new simplified core tag with param registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 17, 2022
1 parent ad6d678 commit 2beb05f
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 608 deletions.
Expand Up @@ -224,15 +224,12 @@ public static void registerTags() {
// # narrates "HELLO WORLD"
// - narrate <binary[48454c4c4f20574f524c44].text_decode[us-ascii]>
// -->
tagProcessor.registerStaticTag(ElementTag.class, "text_decode", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
tagProcessor.registerStaticTag(ElementTag.class, ElementTag.class, "text_decode", (attribute, object, encoding) -> {
try {
return new ElementTag(new String(object.data, attribute.getParam()));
return new ElementTag(new String(object.data, encoding.asString()));
}
catch (UnsupportedEncodingException ex) {
attribute.echoError("Invalid encoding '" + attribute.getParam() + "'");
attribute.echoError("Invalid encoding '" + encoding + "'");
return null;
}
});
Expand Down Expand Up @@ -313,12 +310,9 @@ else if (object.data.length == 4) {
// # Narrates binary data "4b68507f1746b0e5f3efe99b8ef42afef79da017", the exact SHA-1 hash of ASCII "HELLO WORLD".
// - narrate <binary[48454c4c4f20574f524c44].hash[SHA-1]>
// -->
tagProcessor.registerStaticTag(BinaryTag.class, "hash", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
tagProcessor.registerStaticTag(BinaryTag.class, ElementTag.class, "hash", (attribute, object, format) -> {
try {
MessageDigest md = MessageDigest.getInstance(attribute.getParam());
MessageDigest md = MessageDigest.getInstance(format.asString());
md.update(object.data, 0, object.data.length);
return new BinaryTag(md.digest());
}
Expand Down
Expand Up @@ -410,12 +410,8 @@ public static void registerTags() {
// @description
// Returns this duration minus another.
// -->
tagProcessor.registerStaticTag(DurationTag.class, "sub", (attribute, object) -> {
if (!attribute.hasParam()) {
Debug.echoError("The tag DurationTag.sub[...] must have a value.");
return null;
}
return new DurationTag(object.getTicks() - attribute.paramAsType(DurationTag.class).getTicks());
tagProcessor.registerStaticTag(DurationTag.class, DurationTag.class, "sub", (attribute, object, secondVal) -> {
return new DurationTag(object.getTicks() - secondVal.getTicks());
});

// <--[tag]
Expand All @@ -424,72 +420,56 @@ public static void registerTags() {
// @description
// Returns this duration plus another.
// -->
tagProcessor.registerStaticTag(DurationTag.class, "add", (attribute, object) -> {
if (!attribute.hasParam()) {
Debug.echoError("The tag DurationTag.add[...] must have a value.");
return null;
}
return new DurationTag(object.getTicks() + attribute.paramAsType(DurationTag.class).getTicks());
tagProcessor.registerStaticTag(DurationTag.class, DurationTag.class, "add", (attribute, object, secondVal) -> {
return new DurationTag(object.getTicks() + secondVal.getTicks());
});

// <--[tag]
// @attribute <DurationTag.is_more_than[<number>]>
// @attribute <DurationTag.is_more_than[<duration>]>
// @returns ElementTag(Boolean)
// @group comparison
// @description
// Returns whether this duration is greater than the input duration.
// Equivalent to if comparison: >
// -->
tagProcessor.registerStaticTag(ElementTag.class, "is_more_than", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(object.seconds > attribute.paramAsType(DurationTag.class).seconds);
tagProcessor.registerStaticTag(ElementTag.class, DurationTag.class, "is_more_than", (attribute, object, secondVal) -> {
return new ElementTag(object.seconds > secondVal.seconds);
});

// <--[tag]
// @attribute <DurationTag.is_less_than[<number>]>
// @attribute <DurationTag.is_less_than[<duration>]>
// @returns ElementTag(Boolean)
// @group comparison
// @description
// Returns whether this duration is less than the input duration.
// Equivalent to if comparison: <
// -->
tagProcessor.registerStaticTag(ElementTag.class, "is_less_than", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(object.seconds < attribute.paramAsType(DurationTag.class).seconds);
tagProcessor.registerStaticTag(ElementTag.class, DurationTag.class, "is_less_than", (attribute, object, secondVal) -> {
return new ElementTag(object.seconds < secondVal.seconds);
});

// <--[tag]
// @attribute <DurationTag.is_more_than_or_equal_to[<number>]>
// @attribute <DurationTag.is_more_than_or_equal_to[<duration>]>
// @returns ElementTag(Boolean)
// @group comparison
// @description
// Returns whether this duration is greater than or equal to the input duration.
// Equivalent to if comparison: >=
// -->
tagProcessor.registerStaticTag(ElementTag.class, "is_more_than_or_equal_to", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(object.seconds >= attribute.paramAsType(DurationTag.class).seconds);
tagProcessor.registerStaticTag(ElementTag.class, DurationTag.class, "is_more_than_or_equal_to", (attribute, object, secondVal) -> {
return new ElementTag(object.seconds >= secondVal.seconds);
});

// <--[tag]
// @attribute <DurationTag.is_less_than_or_equal_to[<number>]>
// @attribute <DurationTag.is_less_than_or_equal_to[<duration>]>
// @returns ElementTag(Boolean)
// @group comparison
// @description
// Returns whether this duration is less than or equal to the input duration.
// Equivalent to if comparison: <=
// -->
tagProcessor.registerStaticTag(ElementTag.class, "is_less_than_or_equal_to", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(object.seconds <= attribute.paramAsType(DurationTag.class).seconds);
tagProcessor.registerStaticTag(ElementTag.class, DurationTag.class, "is_less_than_or_equal_to", (attribute, object, secondVal) -> {
return new ElementTag(object.seconds <= secondVal.seconds);
});

tagProcessor.registerTag(TimeTag.class, "time", (attribute, object) -> {
Expand Down

0 comments on commit 2beb05f

Please sign in to comment.