Skip to content

Commit

Permalink
fix publishing, add initial update stuff, other bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed May 10, 2024
1 parent 19abcb1 commit bdfe453
Show file tree
Hide file tree
Showing 25 changed files with 477 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ val modMajor = project.properties["mod_major_version"]
val modMinor = project.properties["mod_minor_version"]

version = "$modMajor$modMinor"
group = "org.polyfrost"
group = "org.polyfrost.oneconfig"

This comment has been minimized.

Copy link
@Wyvest

Wyvest May 10, 2024

Member

this is not right


allprojects {
apply(plugin = rootProject.libs.plugins.licenser.get().pluginId)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod_name=OneConfig
mod_id=oneconfig
mod_major_version=1.0.0-alpha
mod_minor_version=-LOCAL
mod_minor_version=1
polyfrost.defaults.loom=2
org.gradle.daemon=true
org.gradle.parallel=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pgt = "0.5.1"
shadow = "8.1.1"
licenser = "2.0.1"

polyui = "1.1.6"
polyui = "1.1.63"

log4j-api = "2.0-beta9" # used because this is the version that 1.8.9 supports, so we have to compile against the same (annoying)
log4j-impl = "2.23.1" # unvulnerable version
Expand Down
4 changes: 3 additions & 1 deletion modules/config-impl/api/config-impl.api
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ public final class org/polyfrost/oneconfig/api/config/v1/ConfigManager {
public fun gatherAll (Ljava/lang/String;)Ljava/util/Collection;
public fun get (Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/config/v1/Tree;
public fun getFolder ()Ljava/nio/file/Path;
public static fun internal ()Lorg/polyfrost/oneconfig/api/config/v1/ConfigManager;
public static fun openProfile (Ljava/lang/String;)V
public fun register (Ljava/lang/Object;Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/config/v1/Tree;
public fun register (Lorg/polyfrost/oneconfig/api/config/v1/Tree;)Lorg/polyfrost/oneconfig/api/config/v1/Tree;
public static fun registerCollector (Lorg/polyfrost/oneconfig/api/config/v1/collect/PropertyCollector;)V
public fun save (Ljava/lang/String;)Z
public fun save (Lorg/polyfrost/oneconfig/api/config/v1/Tree;)Z
public fun saveAll ()V
public fun trees ()Ljava/util/Collection;
}

public class org/polyfrost/oneconfig/api/config/v1/ConfigVisualizer {
public static final field Companion Lorg/polyfrost/oneconfig/api/config/v1/ConfigVisualizer$Companion;
public static final field INSTANCE Lorg/polyfrost/oneconfig/api/config/v1/ConfigVisualizer;
public fun <init> ()V
protected fun create (Lorg/polyfrost/oneconfig/api/config/v1/Tree;Ljava/lang/String;)Lorg/polyfrost/polyui/component/Drawable;
public static synthetic fun create$default (Lorg/polyfrost/oneconfig/api/config/v1/ConfigVisualizer;Lorg/polyfrost/oneconfig/api/config/v1/Tree;Ljava/lang/String;ILjava/lang/Object;)Lorg/polyfrost/polyui/component/Drawable;
Expand All @@ -62,7 +65,6 @@ public class org/polyfrost/oneconfig/api/config/v1/ConfigVisualizer {
}

public final class org/polyfrost/oneconfig/api/config/v1/ConfigVisualizer$Companion {
public final fun getINSTANCE ()Lorg/polyfrost/oneconfig/api/config/v1/ConfigVisualizer;
public final fun strv (Ljava/lang/String;)Ljava/lang/String;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private ConfigManager(Path onto, FileSerializer<?>... serializers) {
* Returns a reference to the internal config manager, which is mounted onto the ./OneConfig directory.
*/
@ApiStatus.Internal
static ConfigManager internal() {
public static ConfigManager internal() {
return internal;
}

Expand Down Expand Up @@ -153,6 +153,10 @@ public boolean save(Tree t) {
return backend.save(t);
}

public void saveAll() {
backend.saveAll();
}

public Path getFolder() {
return backend.folder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.polyfrost.polyui.unit.Vec2
import org.polyfrost.polyui.unit.seconds
import org.polyfrost.polyui.utils.LinkedList
import org.polyfrost.polyui.utils.image
import org.polyfrost.polyui.utils.mapToArray
import org.polyfrost.polyui.utils.rgba
import kotlin.math.PI

Expand Down Expand Up @@ -109,13 +110,13 @@ open class ConfigVisualizer {
Group(
alignment = alignCV,
children =
subcategories.map { (header, options) ->
subcategories.mapToArray { (header, options) ->
Group(
Text(header, fontSize = 22f),
*options.toTypedArray(),
alignment = alignCV,
)
}.toTypedArray(),
},
)
}
}
Expand Down Expand Up @@ -149,14 +150,13 @@ open class ConfigVisualizer {

protected open fun createHeaders(categories: Map<String, Drawable>): Drawable? {
return Group(
children =
categories.map { (category, options) ->
children = categories.mapToArray { (category, options) ->
Button(text = category).events {
Event.Mouse.Clicked(0) then {
parent[0] = options
}
}
}.toTypedArray(),
},
)
}

Expand Down Expand Up @@ -252,6 +252,7 @@ open class ConfigVisualizer {
}

companion object {
@JvmField
val INSTANCE = ConfigVisualizer()
protected val visCache = HashMap<Class<*>, Visualizer>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.polyfrost.polyui.component.events
import org.polyfrost.polyui.component.impl.*
import org.polyfrost.polyui.event.Event
import org.polyfrost.polyui.unit.Vec2
import org.polyfrost.polyui.utils.mapToArray

/**
* Visualizers are procedures that take a property, and return a drawable that represents it.
Expand Down Expand Up @@ -70,10 +71,10 @@ fun interface Visualizer {
return Dropdown(
padding = 24f,
initial = index,
entries = prop.type.enumConstants.map {
entries = prop.type.enumConstants.mapToArray {
it as Enum<*>
null to (it::class.java.fields[0].get(it) as? String ?: it.name)
}.toTypedArray(),
},
)
} else {
require(
Expand All @@ -83,7 +84,7 @@ fun interface Visualizer {
return Dropdown(
padding = 24f,
initial = prop.getAs(),
entries = options.map { null to it }.toTypedArray(),
entries = options.mapToArray { null to it },
)
}
}
Expand Down Expand Up @@ -133,10 +134,10 @@ fun interface Visualizer {
require(options.isEmpty()) { "Radio button ${prop.id} cannot have options when used with enums" }
val r =
Radiobutton(
entries = prop.type.enumConstants.map {
entries = prop.type.enumConstants.mapToArray {
it as Enum<*>
null to (it::class.java.fields[0].get(it) as? String ?: it.name)
}.toTypedArray(),
},
initial = prop.type.enumConstants.indexOf(prop.get()),
optionLateralPadding = 20f,
).events {
Expand All @@ -152,7 +153,7 @@ fun interface Visualizer {
) { "Radio buttons ${prop.id} can only be used with enum or integer types (type=${prop.type}" }
require(options.size >= 2) { "Radio button ${prop.id} must have at least two options" }
return Radiobutton(
entries = options.map { null to it }.toTypedArray(),
entries = options.mapToArray { null to it },
initial = prop.getAs(),
optionLateralPadding = 20f,
).events {
Expand Down
4 changes: 4 additions & 0 deletions modules/hud/api/hud.api
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public final class org/polyfrost/oneconfig/api/hud/v1/TextHud$DateTime : org/pol
public fun updateFrequency ()J
}

public final class org/polyfrost/oneconfig/api/hud/v1/internal/HudVisualizer : org/polyfrost/oneconfig/api/config/v1/ConfigVisualizer {
public fun <init> ()V
}

public final class org/polyfrost/oneconfig/api/hud/v1/internal/Hud_utilsKt {
public static final fun build (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;)Lorg/polyfrost/polyui/component/impl/Block;
public static final fun buildNew (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;)Lorg/polyfrost/polyui/component/impl/Block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import org.polyfrost.oneconfig.api.config.v1.ConfigManager
import org.polyfrost.oneconfig.api.config.v1.Properties.ktProperty
import org.polyfrost.oneconfig.api.config.v1.Properties.simple
import org.polyfrost.oneconfig.api.config.v1.Tree
import org.polyfrost.oneconfig.utils.v1.StringUtils
import org.polyfrost.polyui.color.PolyColor
import org.polyfrost.polyui.component.Drawable
import org.polyfrost.polyui.unit.Vec2
import kotlin.io.path.exists
import kotlin.random.Random

/**
* HUD (Heads Up Display) is a component that is rendered on top of the screen. They are used for displaying information to the user, such as the time, or the player's health.
Expand Down Expand Up @@ -71,9 +72,11 @@ abstract class Hud<T : Drawable> : Cloneable, Config("null", null, "null", null)
fun make(with: Tree? = null): Hud<T> {
if (tree != null) throw IllegalArgumentException("HUD already exists -> can only clone from root HUD object")
val out = clone()
val tree = ConfigManager.collect(out, with?.id ?: "huds/${StringUtils.randomString("0123456789", 4)}-${id()}")
val id = with?.id ?: genRid()
val tree = ConfigManager.collect(out, id)
tree.title = out.title()
tree.addMetadata("category", out.category())
tree.addMetadata("frontendIgnore", true)
tree["x"] = ktProperty(out.hud::x)
tree["y"] = ktProperty(out.hud::y)
tree["skewX"] = ktProperty(out.hud::skewX)
Expand All @@ -92,6 +95,21 @@ abstract class Hud<T : Drawable> : Cloneable, Config("null", null, "null", null)
return out
}

private fun genRid(): String {
var p = "huds/${Random.Default.nextInt(0, 100)}-${id()}"
val folder = ConfigManager.active().folder
var i = 0
while (folder.resolve(p).exists()) {
p = "huds/${Random.Default.nextInt(0, 999)}-${id()}"
when (i++) {
100 -> HudManager.LOGGER.warn("they all say that it gets better")
500 -> HudManager.LOGGER.warn("yeah they all say that it gets better;; it gets better the more you grow")
999 -> throw IllegalStateException("... but what if i dont?")
}
}
return p
}

protected open fun addSpecifics(tree: Tree) {}

@Transient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ object HudManager {
),
Text("oneconfig.hudeditor.title", fontSize = 24f).setFont { medium }.onClick {
ColorPicker(rgba(32, 53, 41).toAnimatable().ref(), mutableListOf(), mutableListOf(), polyUI)
true
},
hudsPage,
size = Vec2(500f, 1048f),
Expand All @@ -129,8 +130,8 @@ object HudManager {
Image("assets/oneconfig/ico/right-arrow.svg".image()).setAlpha(0.1f),
size = Vec2(32f, 1048f),
alignment = alignC,
).named("CloseArea").withStates().setPalette(
Colors.Palette(
).named("CloseArea").withStates().also {
it.palette = Colors.Palette(
TRANSPARENT,
PolyColor.Gradient(
rgba(100, 100, 100, 0.4f),
Expand All @@ -143,8 +144,8 @@ object HudManager {
type = PolyColor.Gradient.Type.LeftToRight,
),
TRANSPARENT,
),
).events {
)
}.events {
Event.Mouse.Entered then {
Fade(this[0], 1f, false, Animations.EaseInOutQuad.create(0.08.seconds)).add()
}
Expand Down Expand Up @@ -218,6 +219,7 @@ object HudManager {

private fun editorClose() {
toggleHudPicker()
ConfigManager.active().saveAll()
panelExists = false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2024 Polyfrost.
* <https://polyfrost.org> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.api.hud.v1.internal

import org.polyfrost.oneconfig.api.config.v1.ConfigVisualizer

class HudVisualizer : ConfigVisualizer() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.polyfrost.polyui.unit.by
import org.polyfrost.polyui.unit.seconds
import org.polyfrost.polyui.utils.LinkedList
import org.polyfrost.polyui.utils.image
import org.polyfrost.polyui.utils.mapToArray
import org.polyfrost.polyui.utils.radii
import kotlin.math.PI
import kotlin.math.atan2
Expand All @@ -61,15 +62,15 @@ fun HudsPage(huds: LinkedList<Hud<out Drawable>>): Drawable {
),
if (huds.isNotEmpty()) {
Group(
children = huds.map {
children = huds.mapToArray {
val preview = it.buildNew()
val size = Vec2(if (preview.width > 200f) 452f else 215f, if (preview.height > 70f) 0f else 80f)
Block(
preview,
alignment = alignC,
size = size,
).withBoarder().withStates()
}.toTypedArray(),
},
visibleSize = Vec2(452f, 800f),
)
} else {
Expand Down
Loading

0 comments on commit bdfe453

Please sign in to comment.