-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: value system, Kotlin 2.0.21
- Loading branch information
Showing
248 changed files
with
2,444 additions
and
3,272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/main/java/net/ccbluex/liquidbounce/config/Configurable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* FDPClient Hacked Client | ||
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge by LiquidBounce. | ||
* https://github.com/SkidderMC/FDPClient/ | ||
*/ | ||
package net.ccbluex.liquidbounce.config | ||
|
||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonObject | ||
import net.ccbluex.liquidbounce.utils.io.json | ||
import net.minecraft.client.gui.FontRenderer | ||
import java.awt.Color | ||
|
||
/** | ||
* A container of the values | ||
*/ | ||
open class Configurable( | ||
name: String | ||
) : Value<MutableList<Value<*>>>( | ||
name, mutableListOf() | ||
) { | ||
|
||
val values: List<Value<*>> | ||
get() = this.get() | ||
|
||
fun addValue(value: Value<*>) = apply { | ||
get().add(value) | ||
} | ||
|
||
fun addValues(values: Collection<Value<*>>) = apply { | ||
get().addAll(values) | ||
} | ||
|
||
operator fun <T, V : Value<T>> V.unaryPlus() = apply(::addValue) | ||
|
||
override fun toJson(): JsonElement = json { | ||
for (value in values) { | ||
if (value.excluded) { | ||
continue | ||
} | ||
|
||
value.name to value.toJson() | ||
} | ||
} | ||
|
||
override fun fromJsonF(element: JsonElement): MutableList<Value<*>>? { | ||
element as JsonObject | ||
|
||
val values = get() | ||
// Set all sub values from the JSON object | ||
for ((valueName, value) in element.entrySet()) { | ||
values.find { it.name.equals(valueName, true) }?.fromJson(value) | ||
} | ||
|
||
return values | ||
} | ||
|
||
override fun toText(): String { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun fromTextF(text: String): MutableList<Value<*>>? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
fun int( | ||
name: String, value: Int, range: IntRange, suffix: String? = null, isSupported: (() -> Boolean)? = null | ||
) = +IntValue(name, value, range, suffix).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun float( | ||
name: String, value: Float, range: ClosedFloatingPointRange<Float> = 0f..Float.MAX_VALUE, suffix: String? = null, isSupported: (() -> Boolean)? = null | ||
) = +FloatValue(name, value, range, suffix).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun choices( | ||
name: String, values: Array<String>, value: String, isSupported: (() -> Boolean)? = null | ||
) = +ListValue(name, values, value).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun block( | ||
name: String, value: Int, isSupported: (() -> Boolean)? = null | ||
) = +BlockValue(name, value).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun font( | ||
name: String, value: FontRenderer, isSupported: (() -> Boolean)? = null | ||
) = +FontValue(name, value).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun text( | ||
name: String, value: String, isSupported: (() -> Boolean)? = null | ||
) = +TextValue(name, value).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun boolean( | ||
name: String, value: Boolean, isSupported: (() -> Boolean)? = null | ||
) = +BoolValue(name, value).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun intRange( | ||
name: String, value: IntRange, range: IntRange, suffix: String? = null, isSupported: (() -> Boolean)? = null | ||
) = +IntRangeValue(name, value, range, suffix).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun floatRange( | ||
name: String, value: ClosedFloatingPointRange<Float>, range: ClosedFloatingPointRange<Float> = 0f..Float.MAX_VALUE, | ||
suffix: String? = null, isSupported: (() -> Boolean)? = null | ||
) = +FloatRangeValue(name, value, range, suffix).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun color( | ||
name: String, value: Color, rainbow: Boolean = false, showPicker: Boolean = false, isSupported: (() -> Boolean)? = null | ||
) = +ColorValue(name, value, rainbow, showPicker).apply { | ||
if (isSupported != null) setSupport { isSupported.invoke() } | ||
} | ||
|
||
fun color( | ||
name: String, value: Int, rainbow: Boolean = false, showPicker: Boolean = false, isSupported: (() -> Boolean)? = null | ||
) = color(name, Color(value, true), rainbow, showPicker, isSupported) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.