diff --git a/src/main/java/com/denizenscript/denizencore/objects/core/ElementTag.java b/src/main/java/com/denizenscript/denizencore/objects/core/ElementTag.java index cb5bb132..994855fd 100644 --- a/src/main/java/com/denizenscript/denizencore/objects/core/ElementTag.java +++ b/src/main/java/com/denizenscript/denizencore/objects/core/ElementTag.java @@ -673,10 +673,12 @@ public static void registerTags() { // @attribute // @returns ListTag // @group conversion + // @deprecated use as[list] // @description - // Returns the element as a ListTag. + // Deprecated in favor of <@link tag ObjectTag.as> // --> tagProcessor.registerStaticTag(ListTag.class, "as_list", (attribute, object) -> { + Deprecations.asXTags.warn(attribute.context); String element = object.element; return handleNull(element, ListTag.valueOf(element, attribute.context), "ListTag", attribute.hasAlternative()); }, "aslist"); @@ -685,10 +687,12 @@ public static void registerTags() { // @attribute // @returns MapTag // @group conversion + // @deprecated use as[map] // @description - // Returns the element as a MapTag. + // Deprecated in favor of <@link tag ObjectTag.as> // --> tagProcessor.registerStaticTag(MapTag.class, "as_map", (attribute, object) -> { + Deprecations.asXTags.warn(attribute.context); String element = object.element; return handleNull(element, MapTag.valueOf(element, attribute.context), "MapTag", attribute.hasAlternative()); }); @@ -697,10 +701,12 @@ public static void registerTags() { // @attribute // @returns CustomObjectTag // @group conversion + // @deprecated use as[custom] // @description - // Returns the element as a custom object. + // Deprecated in favor of <@link tag ObjectTag.as> // --> tagProcessor.registerTag(CustomObjectTag.class, "as_custom", (attribute, object) -> { + Deprecations.asXTags.warn(attribute.context); String element = object.element; return handleNull(element, CustomObjectTag.valueOf(element, attribute.context), "Custom", attribute.hasAlternative()); }, "ascustom"); @@ -709,11 +715,12 @@ public static void registerTags() { // @attribute // @returns ScriptTag // @group conversion + // @deprecated use as[script] // @description - // Returns the element as a ScriptTag. - // Note: the value must be a valid script. + // Deprecated in favor of <@link tag ObjectTag.as> // --> tagProcessor.registerStaticTag(ScriptTag.class, "as_script", (attribute, object) -> { + Deprecations.asXTags.warn(attribute.context); String element = object.element; return handleNull(element, ScriptTag.valueOf(element, attribute.context), "ScriptTag", attribute.hasAlternative()); }, "asscript"); @@ -722,11 +729,12 @@ public static void registerTags() { // @attribute // @returns QueueTag // @group conversion + // @deprecated use as[queue] // @description - // Returns the element as a QueueTag. - // Note: the value must be a valid QueueTag. + // Deprecated in favor of <@link tag ObjectTag.as> // --> tagProcessor.registerTag(QueueTag.class, "as_queue", (attribute, object) -> { + Deprecations.asXTags.warn(attribute.context); String element = object.element; return handleNull(element, QueueTag.valueOf(element, attribute.context), "QueueTag", attribute.hasAlternative()); }, "asqueue"); @@ -735,11 +743,12 @@ public static void registerTags() { // @attribute // @returns DurationTag // @group conversion + // @deprecated use as[duration] // @description - // Returns the element as a Duration. - // Note: the value must be a valid Duration. + // Deprecated in favor of <@link tag ObjectTag.as> // --> tagProcessor.registerStaticTag(DurationTag.class, "as_duration", (attribute, object) -> { + Deprecations.asXTags.warn(attribute.context); String element = object.element; return handleNull(element, DurationTag.valueOf(element, attribute.context), "DurationTag", attribute.hasAlternative()); }, "asduration"); diff --git a/src/main/java/com/denizenscript/denizencore/tags/ObjectTagProcessor.java b/src/main/java/com/denizenscript/denizencore/tags/ObjectTagProcessor.java index 4eac9cb2..5e7008ae 100644 --- a/src/main/java/com/denizenscript/denizencore/tags/ObjectTagProcessor.java +++ b/src/main/java/com/denizenscript/denizencore/tags/ObjectTagProcessor.java @@ -354,6 +354,34 @@ public void generateCoreTags() { } return new JavaReflectedObjectTag(obj); }); + + // <--[tag] + // @attribute ]> + // @returns ObjectTag + // @description + // Returns the object, automatically converted to the named object type. + // Type names can be of the long form, like "ListTag", "MapTag", "ElementTag", ... or the short form, like "List", "Map", "Element", ... + // Type name input is not case-sensitive, so "List" or "list" are the same. + // @example + // my_example: + // type: task + // # Some input can be any raw object type, but will be forced to a list using 'as[list]' below + // definitions: some_input + // script: + // - narrate "Input list has size <[some_input].as[list].size>" + // --> + registerTag(ObjectTag.class, ElementTag.class, "as", (attribute, object, asType) -> { + ObjectType type = ObjectFetcher.objectsByName.get(asType.asLowerString()); + if (type == null) { + attribute.echoError("Invalid object type '" + asType + "'. Cannot convert."); + return null; + } + ObjectTag result = object.asType(type, attribute.context); + if (result == null) { + attribute.echoError("Cannot convert object '" + object + "' to type '" + type.longName + "'."); + } + return result; + }); } public void registerFutureTagDeprecation(String name, String... deprecatedVariants) { diff --git a/src/main/java/com/denizenscript/denizencore/utilities/Deprecations.java b/src/main/java/com/denizenscript/denizencore/utilities/Deprecations.java index 0937220e..56291c22 100644 --- a/src/main/java/com/denizenscript/denizencore/utilities/Deprecations.java +++ b/src/main/java/com/denizenscript/denizencore/utilities/Deprecations.java @@ -101,6 +101,9 @@ public class Deprecations { // Added 2022/04/11, deprecate officially by 2024. public static Warning prebinaryTags = new FutureWarning("prebinaryTags", "Tags and tools related to binary processing that predate the BinaryTag feature are deprecated in favor of using BinaryTag. This includes 'ElementTag.base64_encode/decode', 'hex_encode/decode', ... refer to meta-docs for specifics"); + // Added 2022/08/21, deprecate officially by 2025. + public static Warning asXTags = new FutureWarning("asXTags", "Tags of the form 'as_x' where 'x' is a type, such as 'as_list', are deprecated in favor of the tag ObjectTag.as[], used like 'as[list]'."); + // ==================== PAST deprecations of things that are already gone but still have a warning left behind ==================== // Removed in February 2020.