fix some tests

This commit is contained in:
Bixilon 2023-07-03 15:43:02 +02:00
parent 3a690ca02d
commit 0ff0ad6d64
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 34 additions and 4 deletions

View File

@ -222,7 +222,7 @@ testing {
options {
val options = this as TestNGOptions
options.preserveOrder = true
options.excludeGroups("input", "font", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "block", "physics", "light", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "world_renderer", "rendering")
options.excludeGroups("input", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "block", "physics", "light", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "world_renderer", "rendering")
}
}
}

11
doc/gui/ReadME.md Normal file
View File

@ -0,0 +1,11 @@
# GUI/HUD
Minosoft integrates a custom gui system that can be used to display pretty much anything in 2d space on the screen.
## Stages
GUI has 3 rendering stages:
- update mode (you can make changes async, prepare the next data, `tick`, ...)
- layout mode (called eventually every frame, all currently stored data is applied and put in the layout)
- rendering mode (the current layout will be rendered, might be called every frame if you do animations)

View File

@ -1,3 +1,16 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.gui.elements
import org.testng.annotations.Test
@ -6,6 +19,6 @@ import org.testng.annotations.Test
class ElementUpdateTest {
init {
TODO()
// TODO()
}
}

View File

@ -66,12 +66,14 @@ class TextElementTest {
fun `size if text changed`() {
val element = TextElement(GuiRenderTestUtil.create(), "bc\nbc", background = TextBackground(size = Vec4(1)), properties = TextRenderProperties(shadow = false))
element.text = "bcd\nbcd\nbcd"
element.update()
element.assetSize(Vec2(7.0f, 35.0f))
}
fun `size if background cleared`() {
val element = TextElement(GuiRenderTestUtil.create(), "bcd\nbcd\nbcd", background = TextBackground(size = Vec4(1)), properties = TextRenderProperties(shadow = false))
element.background = null
element.update()
element.assetSize(Vec2(5.0f, 33.0f))
}

View File

@ -21,6 +21,7 @@ import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.font.manager.FontManager
import de.bixilon.minosoft.gui.rendering.font.types.dummy.DummyFontType
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasManager
import de.bixilon.minosoft.gui.rendering.gui.atlas.CodeTexturePart
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.properties.GUIScreen
@ -48,6 +49,8 @@ object GuiRenderTestUtil {
renderer::screen.forceSet(DataObserver(GUIScreen(Vec2i(size), size)))
renderer::context.forceSet(createContext())
renderer::atlasManager.forceSet(AtlasManager(renderer.context))
renderer.atlasManager::class.java.getDeclaredField("elements").apply { isAccessible = true }.set(renderer.atlasManager, mutableMapOf<Any, Any>())
return renderer
}

View File

@ -35,6 +35,7 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec4.Vec4Util.EMPTY
import de.bixilon.minosoft.gui.rendering.util.vec.vec4.Vec4Util.spaceSize
import org.jetbrains.annotations.Contract
import kotlin.reflect.KProperty0
import kotlin.reflect.jvm.isAccessible
abstract class Element(val guiRenderer: GUIRenderer, initialCacheSize: Int = 1000) : InputElement, DragTarget, CachedElement, ParentedElement, UpdatableElement, Tickable {
override val context = guiRenderer.context
@ -166,7 +167,7 @@ abstract class Element(val guiRenderer: GUIRenderer, initialCacheSize: Int = 100
open fun onClose() = Unit
protected inline fun <T> KProperty0<T>.delegate(): GuiDelegate<T> = this.getDelegate().unsafeCast()
protected inline fun <T> KProperty0<T>.delegate(): GuiDelegate<T> = this.apply { isAccessible = true }.getDelegate().unsafeCast()
protected inline fun <T> KProperty0<T>.acknowledge(): T = delegate().acknowledge()
protected inline fun <T> KProperty0<T>.rendering(): T = delegate().rendering()
}

View File

@ -130,7 +130,7 @@ open class TextElement(
override fun forceRender(offset: Vec2, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
if (empty) return
val info = this.info
val properties = this::properties.rendering()
val properties = this::textProperties.rendering()
val initialOffset = Vec2(offset + this::margin.rendering().offset)
val textOffset = Vec2(initialOffset)