Skip to content

Commit

Permalink
Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Nov 14, 2024
1 parent ecc7499 commit a8969f4
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,16 @@ class MMOCoreCompatibility : Compatibility {
): Function<HudPlayer, Number> {
val skill = MMOCore.plugin.skillManager.getSkill(args[0]) ?: throw RuntimeException("Unable to find that skill: ${args[0]}")
return Function { p ->
(p.bukkitPlayer.toMMOCore() ?: return@Function 0.0).boundSkills.entries.firstOrNull {
it.value.classSkill.skill.handler.id == skill.handler.id
}?.key ?: 0
val bar = p.bukkitPlayer.inventory.heldItemSlot
var i = 0
for ((index, entry) in (p.bukkitPlayer.toMMOCore() ?: return@Function 0.0).boundSkills.entries.withIndex()) {
if (entry.value.classSkill.skill.handler.id == skill.handler.id) {
i = entry.key
if (index >= bar) i++
break
}
}
i
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import org.bukkit.Bukkit
import org.bukkit.boss.BossBar
import org.bukkit.entity.Player
import java.util.*
import kotlin.collections.ArrayList

class HudPlayerBukkit(
private val player: Player,
private val audience: Audience
): HudPlayerImpl() {
) : HudPlayerImpl() {
override fun uuid(): UUID = player.uniqueId
override fun name(): String = player.name
override fun handle(): Any = player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import net.minecraft.server.MinecraftServer
import net.minecraft.server.bossevents.CustomBossEvent
import net.minecraft.server.level.ServerPlayer
import java.util.*
import kotlin.collections.ArrayList

class HudPlayerFabric(
server: MinecraftServer,
private val player: ServerPlayer,
private val audience: Audience
): HudPlayerImpl() {
) : HudPlayerImpl() {

init {
val event = ArrayList<CustomBossEvent>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.*

class HudPlayerVelocity(
private val player: Player,
): HudPlayerImpl() {
) : HudPlayerImpl() {
override fun uuid(): UUID = player.uniqueId
override fun name(): String = player.username
override fun handle(): Any = player
Expand Down
60 changes: 30 additions & 30 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,6 @@ val supportedVelocityVersions = listOf(
"3.4"
)

val legacyNmsVersion = listOf(
//"v1_17_R1",
//"v1_18_R1",
"v1_18_R2",
"v1_19_R1",
"v1_19_R2",
"v1_19_R3",
"v1_20_R1",
"v1_20_R2",
"v1_20_R3",
).map {
project("nms:$it")
}
val currentNmsVersion = listOf(
"v1_20_R4",
"v1_21_R1",
"v1_21_R2",
).map {
project("nms:$it")
}

val allNmsVersion = legacyNmsVersion + currentNmsVersion

allprojects {
apply(plugin = "java")
apply(plugin = "kotlin")
Expand Down Expand Up @@ -158,6 +135,31 @@ subprojects {
}
}

val legacyNmsVersion = listOf(
//"v1_17_R1",
//"v1_18_R1",
"v1_18_R2",
"v1_19_R1",
"v1_19_R2",
"v1_19_R3",
"v1_20_R1",
"v1_20_R2",
"v1_20_R3",
).map {
project("nms:$it")
}.onEach {
it.legacy()
}

val currentNmsVersion = listOf(
"v1_20_R4",
"v1_21_R1",
"v1_21_R2",
).map {
project("nms:$it")
}

val allNmsVersion = legacyNmsVersion + currentNmsVersion

fun Project.dependency(any: Any) = also {
if (any is Collection<*>) {
Expand Down Expand Up @@ -238,20 +240,18 @@ fun Project.modrinthPublish(depend: Jar, additionalJar: List<Jar>, loadersList:
}
}

val apiShare = project("api:standard-api").adventure().legacy()
val apiBukkit = project("api:bukkit-api").adventure().bukkit().dependency(apiShare).legacy()
val apiVelocity = project("api:velocity-api").velocity().dependency(apiShare).legacy()
val apiShare = project("api:standard-api").adventure()
val apiBukkit = project("api:bukkit-api").adventure().bukkit().dependency(apiShare)
val apiVelocity = project("api:velocity-api").velocity().dependency(apiShare)
val apiFabric = project("api:fabric-api").adventure().dependency(apiShare)

val api = listOf(
apiShare,
apiBukkit,
apiVelocity,
apiFabric
)

legacyNmsVersion.forEach {
it.legacy()
).onEach {
project -> project.legacy()
}

fun Project.api() = dependency(api)
Expand Down
8 changes: 8 additions & 0 deletions changelog/1.10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# BetterHud 1.10

## Fix
- Fix a problem that built core shader has comment.
- Fix mmocore_casting_slot placeholder.

## Add
- Add more uniform value in shaders json.
11 changes: 6 additions & 5 deletions dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.util.function.Consumer
import java.util.jar.JarFile

@Suppress("UNUSED")
class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
class BetterHudImpl(val bootstrap: BetterHudBootstrap) : BetterHud {

init {
if (!bootstrap.dataFolder().exists() && !bootstrap.isVelocity) loadAssets("default", bootstrap.dataFolder().apply {
Expand All @@ -36,10 +36,8 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
}
}

private var managers: List<BetterHudManager> = emptyList()

fun start() {
managers = listOf(
private val managers: List<BetterHudManager> by lazy {
listOf(
ConfigManagerImpl,
MinecraftManager,
CommandManager,
Expand All @@ -61,6 +59,9 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
ShaderManagerImpl,
PlayerManagerImpl,
)
}

fun start() {
managers.forEach {
it.start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CircleCompass(
override val path: String,
private val internalName: String,
section: YamlObject
): CompassImpl {
) : CompassImpl {
companion object {
private val defaultColorEquation = TEquation("255").run {
ColorEquation(
Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/image/HudImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HudImage(
val image: List<NamedLoadedImage>,
val type: ImageType,
setting: YamlObject
): HudConfiguration {
) : HudConfiguration {
val conditions = setting.toConditions()
val listener = setting.get("listener")?.asObject()?.let {
ListenerManagerImpl.getListener(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ object ShaderManagerImpl : BetterHudManager, ShaderManager {
if (replaceList.contains(deactivateMatcher.group("name"))) s = deactivateMatcher.replaceAll("")
else return@write
}
if (s.isEmpty()) return@write
if (s.isEmpty() || s.startsWith("//")) return@write
val tagMatcher = tagPattern.matcher(s)
if (tagMatcher.find()) {
val group = tagMatcher.group("name")
(tagBuilders[group]?.invoke() ?: tagSupplier[group])?.let {
it.forEach apply@ { methodString ->
if (methodString.isEmpty()) return@apply
if (methodString.isEmpty() || methodString.startsWith("//")) return@apply
val appendEnter = methodString.first() == '#'
if (appendEnter && (isEmpty() || last() != '\n')) append('\n')
append(methodString.replace(" ", ""))
Expand Down
7 changes: 4 additions & 3 deletions dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class PopupLayout(
if (hudImage.image.size > 1) hudImage.image.forEach {
val fileName = "$NAME_SPACE_ENCODED:${it.name}"

val height = Math.round(it.image.image.height * target.scale).toInt()
val height = (it.image.image.height * target.scale).roundToInt().toInt()
val scale = height.toDouble() / it.image.image.height
val xOffset = Math.round(it.image.xOffset * scale).toInt()
val xOffset = (it.image.xOffset * scale).roundToInt().toInt()
val ascent = pixel.y
val shaderGroup = ShaderGroup(imageShader, fileName, target.scale, ascent)

Expand Down Expand Up @@ -160,7 +160,8 @@ class PopupLayout(
"chars" to jsonArrayOf(char)
))
}
val comp = WidthComponent(Component.text().content(char).font(parent.imageKey), Math.round(it.image.image.width.toDouble() * target.scale).toInt()) + NEGATIVE_ONE_SPACE_COMPONENT
val comp = WidthComponent(Component.text().content(char).font(parent.imageKey), (it.image.image.width.toDouble() * target.scale).roundToInt()
.toInt()) + NEGATIVE_ONE_SPACE_COMPONENT
list.add(comp.toPixelComponent(pixel.x))
}

Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/shader/HudShader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class HudShader(
val outline: Boolean,
val opacity: Double,
val property: Int,
): Comparable<HudShader> {
) : Comparable<HudShader> {
companion object {
private val comparator = Comparator.comparing { s: HudShader ->
s.gui
Expand Down
1 change: 0 additions & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/util/Lists.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kr.toxicity.hud.util

import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executors
import kotlin.collections.ArrayList

fun <T> List<T>.split(splitSize: Int): List<List<T>> {
val result = ArrayList<List<T>>()
Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/yaml/YamlArrayImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.*
class YamlArrayImpl(
path: String,
private val list: List<*>
): YamlConfigurationImpl(path), YamlArray {
) : YamlConfigurationImpl(path), YamlArray {

@Suppress("UNCHECKED_CAST")
override fun get(): MutableList<Any> = Collections.unmodifiableList(list as MutableList<Any>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kr.toxicity.hud.api.yaml.YamlConfiguration

abstract class YamlConfigurationImpl(
private val path: String,
): YamlConfiguration {
) : YamlConfiguration {
override fun path(): String = path
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.io.Serializable
class YamlElementImpl(
path: String,
private val any: Any
): YamlConfigurationImpl(path), YamlElement {
) : YamlConfigurationImpl(path), YamlElement {
override fun get(): Any = any
override fun asString(): String = if (any is Serializable) any.toString() else throw RuntimeException("This is not a string: $any")
override fun asInt(): Int = (any as? Number)?.toInt().ifNull("This is not a int: $any")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.*
class YamlObjectImpl(
path: String,
private val map: MutableMap<*, *>
): YamlConfigurationImpl(path), YamlObject {
) : YamlConfigurationImpl(path), YamlObject {

override fun save(file: File) {
get().saveToYaml(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] },
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] }
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
],
"samplers": [
{ "name": "Sampler0" },
{ "name": "Sampler1" },
{ "name": "Sampler2" }
],
"uniforms": [
Expand All @@ -28,6 +29,7 @@
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] },
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] }
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
],
"samplers": [
{ "name": "Sampler0" },
{ "name": "Sampler1" },
{ "name": "Sampler2" }
],
"uniforms": [
Expand All @@ -28,6 +29,7 @@
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] },
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] }
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
]
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Feb 29 02:18:16 KST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit a8969f4

Please sign in to comment.