mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-04-30 05:14:26 +02:00
feat!: Add property PatchOption#values
This commit is contained in:
parent
c6095bc38a
commit
55f6c2a9fc
@ -362,15 +362,16 @@ public abstract interface annotation class app/revanced/patcher/patch/annotation
|
|||||||
|
|
||||||
public class app/revanced/patcher/patch/options/PatchOption {
|
public class app/revanced/patcher/patch/options/PatchOption {
|
||||||
public static final field PatchExtensions Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;
|
public static final field PatchExtensions Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;
|
||||||
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)V
|
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)V
|
||||||
public final fun getDefault ()Ljava/lang/Object;
|
public final fun getDefault ()Ljava/lang/Object;
|
||||||
public final fun getDescription ()Ljava/lang/String;
|
public final fun getDescription ()Ljava/lang/String;
|
||||||
public final fun getKey ()Ljava/lang/String;
|
public final fun getKey ()Ljava/lang/String;
|
||||||
public final fun getRequired ()Z
|
public final fun getRequired ()Z
|
||||||
public final fun getTitle ()Ljava/lang/String;
|
public final fun getTitle ()Ljava/lang/String;
|
||||||
public final fun getValidator ()Lkotlin/jvm/functions/Function1;
|
public final fun getValidator ()Lkotlin/jvm/functions/Function2;
|
||||||
public final fun getValue ()Ljava/lang/Object;
|
public final fun getValue ()Ljava/lang/Object;
|
||||||
public final fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
|
public final fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
|
||||||
|
public final fun getValues ()Ljava/util/Set;
|
||||||
public fun reset ()V
|
public fun reset ()V
|
||||||
public final fun setValue (Ljava/lang/Object;)V
|
public final fun setValue (Ljava/lang/Object;)V
|
||||||
public final fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
|
public final fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
|
||||||
@ -378,26 +379,26 @@ public class app/revanced/patcher/patch/options/PatchOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class app/revanced/patcher/patch/options/PatchOption$PatchExtensions {
|
public final class app/revanced/patcher/patch/options/PatchOption$PatchExtensions {
|
||||||
public final fun booleanArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun booleanArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun booleanArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun booleanArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun booleanPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun booleanPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun booleanPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun booleanPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun floatArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun floatArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun floatArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun floatArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun floatPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun floatPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun floatPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun floatPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun intArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun intArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun intArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun intArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun intPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun intPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun intPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun intPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun longArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun longArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun longArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun longArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun longPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun longPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun longPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun longPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun stringArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun stringArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun stringArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun stringArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public final fun stringPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public final fun stringPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
public static synthetic fun stringPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
public static synthetic fun stringPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class app/revanced/patcher/patch/options/PatchOptionException : java/lang/Exception {
|
public abstract class app/revanced/patcher/patch/options/PatchOptionException : java/lang/Exception {
|
||||||
|
@ -8,6 +8,7 @@ import kotlin.reflect.KProperty
|
|||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -18,10 +19,11 @@ import kotlin.reflect.KProperty
|
|||||||
open class PatchOption<T>(
|
open class PatchOption<T>(
|
||||||
val key: String,
|
val key: String,
|
||||||
val default: T?,
|
val default: T?,
|
||||||
|
val values: Set<T>,
|
||||||
val title: String?,
|
val title: String?,
|
||||||
val description: String?,
|
val description: String?,
|
||||||
val required: Boolean,
|
val required: Boolean,
|
||||||
val validator: (T?) -> Boolean
|
val validator: PatchOption<T>.(T?) -> Boolean
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* The value of the [PatchOption].
|
* The value of the [PatchOption].
|
||||||
@ -90,6 +92,7 @@ open class PatchOption<T>(
|
|||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -102,17 +105,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.stringPatchOption(
|
fun <P : Patch<*>> P.stringPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: String? = null,
|
default: String? = null,
|
||||||
|
values: Set<String> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (String?) -> Boolean = { true }
|
validator: PatchOption<String>.(String?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with an integer value and add it to the current [Patch].
|
* Create a new [PatchOption] with an integer value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -125,17 +130,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.intPatchOption(
|
fun <P : Patch<*>> P.intPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Int? = null,
|
default: Int? = null,
|
||||||
|
values: Set<Int> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Int?) -> Boolean = { true }
|
validator: PatchOption<Int?>.(Int?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with a boolean value and add it to the current [Patch].
|
* Create a new [PatchOption] with a boolean value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -148,17 +155,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.booleanPatchOption(
|
fun <P : Patch<*>> P.booleanPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Boolean? = null,
|
default: Boolean? = null,
|
||||||
|
values: Set<Boolean> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Boolean?) -> Boolean = { true }
|
validator: PatchOption<Boolean?>.(Boolean?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with a float value and add it to the current [Patch].
|
* Create a new [PatchOption] with a float value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -171,17 +180,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.floatPatchOption(
|
fun <P : Patch<*>> P.floatPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Float? = null,
|
default: Float? = null,
|
||||||
|
values: Set<Float> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Float?) -> Boolean = { true }
|
validator: PatchOption<Float?>.(Float?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with a long value and add it to the current [Patch].
|
* Create a new [PatchOption] with a long value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -194,17 +205,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.longPatchOption(
|
fun <P : Patch<*>> P.longPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Long? = null,
|
default: Long? = null,
|
||||||
|
values: Set<Long> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Long?) -> Boolean = { true }
|
validator: PatchOption<Long?>.(Long?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with a string array value and add it to the current [Patch].
|
* Create a new [PatchOption] with a string array value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -217,17 +230,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.stringArrayPatchOption(
|
fun <P : Patch<*>> P.stringArrayPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Array<String>? = null,
|
default: Array<String>? = null,
|
||||||
|
values: Set<Array<String>> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Array<String>?) -> Boolean = { true }
|
validator: PatchOption<Array<String>?>.(Array<String>?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with an integer array value and add it to the current [Patch].
|
* Create a new [PatchOption] with an integer array value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -240,17 +255,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.intArrayPatchOption(
|
fun <P : Patch<*>> P.intArrayPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Array<Int>? = null,
|
default: Array<Int>? = null,
|
||||||
|
values: Set<Array<Int>> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Array<Int>?) -> Boolean = { true }
|
validator: PatchOption<Array<Int>?>.(Array<Int>?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with a boolean array value and add it to the current [Patch].
|
* Create a new [PatchOption] with a boolean array value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -263,17 +280,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.booleanArrayPatchOption(
|
fun <P : Patch<*>> P.booleanArrayPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Array<Boolean>? = null,
|
default: Array<Boolean>? = null,
|
||||||
|
values: Set<Array<Boolean>> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Array<Boolean>?) -> Boolean = { true }
|
validator: PatchOption<Array<Boolean>?>.(Array<Boolean>?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with a float array value and add it to the current [Patch].
|
* Create a new [PatchOption] with a float array value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -286,17 +305,19 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.floatArrayPatchOption(
|
fun <P : Patch<*>> P.floatArrayPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Array<Float>? = null,
|
default: Array<Float>? = null,
|
||||||
|
values: Set<Array<Float>> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Array<Float>?) -> Boolean = { true }
|
validator: PatchOption<Array<Float>?>.(Array<Float>?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new [PatchOption] with a long array value and add it to the current [Patch].
|
* Create a new [PatchOption] with a long array value and add it to the current [Patch].
|
||||||
*
|
*
|
||||||
* @param key The identifier.
|
* @param key The identifier.
|
||||||
* @param default The default value.
|
* @param default The default value.
|
||||||
|
* @param values The set of guaranteed valid values.
|
||||||
* @param title The title.
|
* @param title The title.
|
||||||
* @param description A description.
|
* @param description A description.
|
||||||
* @param required Whether the option is required.
|
* @param required Whether the option is required.
|
||||||
@ -309,11 +330,12 @@ open class PatchOption<T>(
|
|||||||
fun <P : Patch<*>> P.longArrayPatchOption(
|
fun <P : Patch<*>> P.longArrayPatchOption(
|
||||||
key: String,
|
key: String,
|
||||||
default: Array<Long>? = null,
|
default: Array<Long>? = null,
|
||||||
|
values: Set<Array<Long>> = emptySet(),
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
required: Boolean = false,
|
required: Boolean = false,
|
||||||
validator: (Array<Long>?) -> Boolean = { true }
|
validator: PatchOption<Array<Long>?>.(Array<Long>?) -> Boolean = { true }
|
||||||
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
|
) = PatchOption(key, default, values, title, description, required, validator).also { registerOption(it) }
|
||||||
|
|
||||||
private fun <P : Patch<*>> P.registerOption(option: PatchOption<*>) = option.also { options.register(it) }
|
private fun <P : Patch<*>> P.registerOption(option: PatchOption<*>) = option.also { options.register(it) }
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatc
|
|||||||
import org.junit.jupiter.api.assertDoesNotThrow
|
import org.junit.jupiter.api.assertDoesNotThrow
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
internal class PatchOptionsTest {
|
internal class PatchOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
@ -46,6 +47,36 @@ internal class PatchOptionsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
@Test
|
||||||
|
fun `should allow setting value from values`() =
|
||||||
|
with(OptionsTestPatch.options["choices"] as PatchOption<String>) {
|
||||||
|
value = values.last()
|
||||||
|
assertTrue(value == "valid")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should allow setting custom value`() {
|
||||||
|
assertDoesNotThrow {
|
||||||
|
OptionsTestPatch.options["choices"] = "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should not allow setting custom value with validation`() =
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
with(OptionsTestPatch.options["validated"] as PatchOption<String>) {
|
||||||
|
// Getter validation
|
||||||
|
assertThrows<PatchOptionException.ValueValidationException> { value }
|
||||||
|
|
||||||
|
// setter validation on incorrect value
|
||||||
|
assertThrows<PatchOptionException.ValueValidationException> { value = "invalid" }
|
||||||
|
|
||||||
|
// Setter validation on correct value
|
||||||
|
assertDoesNotThrow { value = "valid" }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
private object OptionsTestPatch : BytecodePatch() {
|
private object OptionsTestPatch : BytecodePatch() {
|
||||||
private var stringOption by stringPatchOption("string", "default")
|
private var stringOption by stringPatchOption("string", "default")
|
||||||
private var booleanOption by booleanPatchOption("bool", true)
|
private var booleanOption by booleanPatchOption("bool", true)
|
||||||
@ -53,6 +84,9 @@ internal class PatchOptionsTest {
|
|||||||
private var nullDefaultRequiredOption by stringPatchOption("null", null, required = true)
|
private var nullDefaultRequiredOption by stringPatchOption("null", null, required = true)
|
||||||
|
|
||||||
val stringArrayOption = stringArrayPatchOption("array", arrayOf("1", "2"))
|
val stringArrayOption = stringArrayPatchOption("array", arrayOf("1", "2"))
|
||||||
|
val stringOptionWithChoices = stringPatchOption("choices", "value", values = setOf("valid"))
|
||||||
|
|
||||||
|
val validatedOption = stringPatchOption("validated", "default") { it == "valid" }
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext) {}
|
override fun execute(context: BytecodeContext) {}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user