Skip to content

Commit

Permalink
Build: Use Standalone UniversalCraft for example
Browse files Browse the repository at this point in the history
This has the advantage that it's much faster to boot than full MC and
that one is no longer required to set up a Minecraft development
enviornment for multiple versions to build Elementa.

Also replaces the example image url because imgur was redirecting to its
html page instead of returning the image.
  • Loading branch information
Johni0702 committed Sep 5, 2024
1 parent ddd0c43 commit c964d72
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 288 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ you MUST call Window#mouseClick. This is also all handled by Elementa's WindowSc
## All together

This is a basic excerpt of code from an Elementa GUI. To see a more fleshed out
example, look to the [ExampleGui class](src/main/java/com/example/examplemod/ExampleGui.kt).
example, look to the [ExampleGui class](example/src/main/kotlin/gg/essential/elementa/example/ExampleGui.kt) and other
files in that sub-project.
You can run those examples via `./gradlew :example:run`.

```kotlin
val window = Window()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {
// Depending on LWJGL3 instead of 2 so we can choose opengl bindings only
compileOnly("org.lwjgl:lwjgl-opengl:3.3.1")
// Depending on 1.8.9 for all of these because that's the oldest version we support
compileOnly(libs.versions.universalcraft.map { "gg.essential:universalcraft-1.8.9-forge:$it" }) {
compileOnly(libs.universalcraft.forge10809) {
attributes { attribute(common, true) }
}
compileOnly("com.google.code.gson:gson:2.2.4")
Expand Down
8 changes: 0 additions & 8 deletions example/1.12.2-1.8.9.txt

This file was deleted.

14 changes: 0 additions & 14 deletions example/1.15.2-1.12.2.txt

This file was deleted.

49 changes: 9 additions & 40 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
import gg.essential.gradle.util.*

plugins {
kotlin("jvm")
id("gg.essential.multi-version")
id("gg.essential.defaults")
application
id("gg.essential.defaults.repo")
}

java.withSourcesJar()
loom.noServerRunConfigs()

dependencies {
implementation(libs.kotlin.stdlib.jdk8)
implementation(libs.kotlin.reflect)
compileOnly(libs.jetbrains.annotations)

modApi(libs.versions.universalcraft.map { "gg.essential:universalcraft-$platform:$it" }) {
exclude(group = "org.jetbrains.kotlin")
}
implementation(libs.universalcraft.standalone)
implementation(project(":"))
implementation(project(":unstable:layoutdsl"))
}

implementation(project(":example:common"))
kotlin.jvmToolchain(8)

if (platform.isFabric) {
val fabricApiVersion = when(platform.mcVersion) {
11404 -> "0.4.3+build.247-1.14"
11502 -> "0.5.1+build.294-1.15"
11601 -> "0.14.0+build.371-1.16"
11602 -> "0.17.1+build.394-1.16"
11701 -> "0.38.1+1.17"
11801 -> "0.46.4+1.18"
else -> throw GradleException("Unsupported platform $platform")
}
val fabricApiModules = mutableListOf(
"api-base",
"networking-v0",
"keybindings-v0",
"resource-loader-v0",
"lifecycle-events-v1",
)
if (platform.mcVersion >= 11600) {
fabricApiModules.add("key-binding-api-v1")
}
fabricApiModules.forEach { module ->
// Using this combo to add it to our deps but not to our maven publication cause it's only for the example
modLocalRuntime(modCompileOnly(fabricApi.module("fabric-$module", fabricApiVersion))!!)
}
}
application {
mainClass.set("gg.essential.elementa.example.MainKt")
}
23 changes: 0 additions & 23 deletions example/common/build.gradle.kts

This file was deleted.

1 change: 0 additions & 1 deletion example/mainProject

This file was deleted.

24 changes: 0 additions & 24 deletions example/root.gradle.kts

This file was deleted.

72 changes: 0 additions & 72 deletions example/src/main/java/com/example/examplemod/ExampleMod.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.examplemod
package gg.essential.elementa.example

import gg.essential.elementa.ElementaVersion
import gg.essential.elementa.WindowScreen
Expand All @@ -10,6 +10,8 @@ import gg.essential.elementa.components.inspector.Inspector
import gg.essential.elementa.constraints.*
import gg.essential.elementa.dsl.*
import gg.essential.elementa.effects.OutlineEffect
import gg.essential.elementa.layoutdsl.Modifier
import gg.essential.elementa.layoutdsl.gradient
import gg.essential.elementa.markdown.MarkdownComponent
import java.awt.Color
import java.net.URL
Expand Down Expand Up @@ -167,38 +169,38 @@ class ComponentsGui : WindowScreen(ElementaVersion.V2) {
} childOf window

ComponentType("UIImage") {
UIImage.ofURL(URL("https://i.imgur.com/Pc6iMw3.png")).constrain {
UIImage.ofURL(exampleImageUrl).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()

width = 100.pixels()
height = 50.pixels()
} childOf this

UIImage.ofURL(URL("https://i.imgur.com/Pc6iMw3.png")).constrain {
UIImage.ofURL(exampleImageUrl).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()

width = 150.pixels()
width = 100.pixels()
height = ImageAspectConstraint()
} childOf this
} childOf window

ComponentType("BlurHashImage") {
BlurHashImage("L4ESU,OD1e#:=GwwJSAr1M,r|]Ar").constrain {
BlurHashImage(exampleBlurHash).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()

width = 100.pixels()
height = 50.pixels()
width = 50.pixels()
height = 60.pixels()
} childOf this

BlurHashImage.ofURL("L4ESU,OD1e#:=GwwJSAr1M,r|]Ar", URL("https://i.imgur.com/Pc6iMw3.png")).constrain {
BlurHashImage.ofURL(exampleBlurHash, exampleImageUrl).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()

width = 100.pixels()
height = 50.pixels()
width = 50.pixels()
height = 60.pixels()
} childOf this
} childOf window

Expand Down Expand Up @@ -307,6 +309,9 @@ class ComponentsGui : WindowScreen(ElementaVersion.V2) {
x = 10.pixels(true)
y = 10.pixels(true)
} childOf window

// Fancy background
Modifier.gradient(top = Color(0x091323), Color.BLACK).applyToComponent(window)
}

class ComponentType(componentName: String, initBlock: ComponentType.() -> Unit) : UIContainer() {
Expand Down Expand Up @@ -335,4 +340,11 @@ class ComponentsGui : WindowScreen(ElementaVersion.V2) {
private const val OUTLINE_WIDTH = 2f
}
}

companion object {
// AdinaVoicu, CC0, via Wikimedia Commons
// https://commons.wikimedia.org/wiki/File:Tabby_cat_with_blue_eyes-3336579.jpg
val exampleImageUrl = URL("https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Tabby_cat_with_blue_eyes-3336579.jpg/200px-Tabby_cat_with_blue_eyes-3336579.jpg")
val exampleBlurHash = "K8HnZ@.7|,4TIr?H01My5Y"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.examplemod
package gg.essential.elementa.example

import gg.essential.elementa.ElementaVersion
import gg.essential.elementa.WindowScreen
Expand All @@ -8,6 +8,8 @@ import gg.essential.elementa.constraints.*
import gg.essential.elementa.constraints.animation.Animations
import gg.essential.elementa.dsl.*
import gg.essential.elementa.effects.ScissorEffect
import gg.essential.elementa.layoutdsl.Modifier
import gg.essential.elementa.layoutdsl.gradient
import java.awt.Color

/**
Expand Down Expand Up @@ -181,6 +183,9 @@ class ExampleGui : WindowScreen(ElementaVersion.V2) {
// constructing an instance of [ConstantColorConstraint].
color = Color.GREEN.darker().toConstraint()
} childOf createNoteButton

// Fancy background
Modifier.gradient(top = Color(0x091323), Color.BLACK).applyToComponent(window)
}

// Now, since we want to create a bunch of sticky notes, it makes sense
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.examplemod
package gg.essential.elementa.example

import gg.essential.elementa.ElementaVersion
import gg.essential.elementa.UIComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.example.examplemod
package gg.essential.elementa.example

import gg.essential.elementa.ElementaVersion
import gg.essential.elementa.WindowScreen
import gg.essential.elementa.components.*
import gg.essential.elementa.constraints.*
import gg.essential.elementa.constraints.animation.Animations
import gg.essential.elementa.dsl.*
import gg.essential.elementa.layoutdsl.Modifier
import gg.essential.elementa.layoutdsl.gradient
import gg.essential.universal.UMinecraft
import gg.essential.universal.UScreen
import java.awt.Color
Expand All @@ -14,7 +16,7 @@ import java.awt.Color
* List of buttons to open a specific example gui.
* See ExampleGui (singular) for a well-commented example gui.
*/
class ExamplesGui : WindowScreen(ElementaVersion.V2) {
class ExamplesGui : WindowScreen(ElementaVersion.V6) {
private val container by ScrollComponent().constrain {
y = 3.pixels()
width = 100.percent()
Expand Down Expand Up @@ -50,6 +52,9 @@ class ExamplesGui : WindowScreen(ElementaVersion.V2) {
y = CenterConstraint()
} childOf button
}

// Fancy background
Modifier.gradient(top = Color(0x091323), Color.BLACK).applyToComponent(window)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.examplemod;
package gg.essential.elementa.example;

import gg.essential.elementa.ElementaVersion;
import gg.essential.elementa.UIComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.examplemod
package gg.essential.elementa.example

import gg.essential.elementa.ElementaVersion
import gg.essential.elementa.WindowScreen
Expand Down
9 changes: 9 additions & 0 deletions example/src/main/kotlin/gg/essential/elementa/example/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package gg.essential.elementa.example

import gg.essential.universal.UScreen
import gg.essential.universal.standalone.runUniversalCraft

fun main() = runUniversalCraft("Elementa Example", 854, 480) { window ->
UScreen.displayScreen(ExamplesGui())
window.renderScreenUntilClosed()
}
Loading

0 comments on commit c964d72

Please sign in to comment.