Skip to content

Commit 3d0e09d

Browse files
authored
Build: Use Standalone UniversalCraft for example
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. GitHub: #151
1 parent 9308d17 commit 3d0e09d

20 files changed

Lines changed: 63 additions & 288 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ you MUST call Window#mouseClick. This is also all handled by Elementa's WindowSc
247247
## All together
248248

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

252254
```kotlin
253255
val window = Window()

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
// Depending on LWJGL3 instead of 2 so we can choose opengl bindings only
5656
compileOnly("org.lwjgl:lwjgl-opengl:3.3.1")
5757
// Depending on 1.8.9 for all of these because that's the oldest version we support
58-
compileOnly(libs.versions.universalcraft.map { "gg.essential:universalcraft-1.8.9-forge:$it" }) {
58+
compileOnly(libs.universalcraft.forge10809) {
5959
attributes { attribute(common, true) }
6060
}
6161
compileOnly("com.google.code.gson:gson:2.2.4")

example/1.12.2-1.8.9.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/1.15.2-1.12.2.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/build.gradle.kts

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,17 @@
1-
import gg.essential.gradle.util.*
2-
31
plugins {
42
kotlin("jvm")
5-
id("gg.essential.multi-version")
6-
id("gg.essential.defaults")
3+
application
4+
id("gg.essential.defaults.repo")
75
}
86

9-
java.withSourcesJar()
10-
loom.noServerRunConfigs()
11-
127
dependencies {
13-
implementation(libs.kotlin.stdlib.jdk8)
14-
implementation(libs.kotlin.reflect)
15-
compileOnly(libs.jetbrains.annotations)
16-
17-
modApi(libs.versions.universalcraft.map { "gg.essential:universalcraft-$platform:$it" }) {
18-
exclude(group = "org.jetbrains.kotlin")
19-
}
8+
implementation(libs.universalcraft.standalone)
9+
implementation(project(":"))
10+
implementation(project(":unstable:layoutdsl"))
11+
}
2012

21-
implementation(project(":example:common"))
13+
kotlin.jvmToolchain(8)
2214

23-
if (platform.isFabric) {
24-
val fabricApiVersion = when(platform.mcVersion) {
25-
11404 -> "0.4.3+build.247-1.14"
26-
11502 -> "0.5.1+build.294-1.15"
27-
11601 -> "0.14.0+build.371-1.16"
28-
11602 -> "0.17.1+build.394-1.16"
29-
11701 -> "0.38.1+1.17"
30-
11801 -> "0.46.4+1.18"
31-
else -> throw GradleException("Unsupported platform $platform")
32-
}
33-
val fabricApiModules = mutableListOf(
34-
"api-base",
35-
"networking-v0",
36-
"keybindings-v0",
37-
"resource-loader-v0",
38-
"lifecycle-events-v1",
39-
)
40-
if (platform.mcVersion >= 11600) {
41-
fabricApiModules.add("key-binding-api-v1")
42-
}
43-
fabricApiModules.forEach { module ->
44-
// Using this combo to add it to our deps but not to our maven publication cause it's only for the example
45-
modLocalRuntime(modCompileOnly(fabricApi.module("fabric-$module", fabricApiVersion))!!)
46-
}
47-
}
15+
application {
16+
mainClass.set("gg.essential.elementa.example.MainKt")
4817
}

example/common/build.gradle.kts

Lines changed: 0 additions & 23 deletions
This file was deleted.

example/mainProject

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/root.gradle.kts

Lines changed: 0 additions & 24 deletions
This file was deleted.

example/src/main/java/com/example/examplemod/ExampleMod.java

Lines changed: 0 additions & 72 deletions
This file was deleted.

example/common/src/main/kotlin/com/example/examplemod/ComponentsGui.kt renamed to example/src/main/kotlin/gg/essential/elementa/example/ComponentsGui.kt

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.examplemod
1+
package gg.essential.elementa.example
22

33
import gg.essential.elementa.ElementaVersion
44
import gg.essential.elementa.WindowScreen
@@ -10,6 +10,8 @@ import gg.essential.elementa.components.inspector.Inspector
1010
import gg.essential.elementa.constraints.*
1111
import gg.essential.elementa.dsl.*
1212
import gg.essential.elementa.effects.OutlineEffect
13+
import gg.essential.elementa.layoutdsl.Modifier
14+
import gg.essential.elementa.layoutdsl.gradient
1315
import gg.essential.elementa.markdown.MarkdownComponent
1416
import java.awt.Color
1517
import java.net.URL
@@ -167,38 +169,38 @@ class ComponentsGui : WindowScreen(ElementaVersion.V2) {
167169
} childOf window
168170

169171
ComponentType("UIImage") {
170-
UIImage.ofURL(URL("https://i.imgur.com/Pc6iMw3.png")).constrain {
172+
UIImage.ofURL(exampleImageUrl).constrain {
171173
x = 2.pixels()
172174
y = SiblingConstraint() + 5.pixels()
173175

174176
width = 100.pixels()
175177
height = 50.pixels()
176178
} childOf this
177179

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

182-
width = 150.pixels()
184+
width = 100.pixels()
183185
height = ImageAspectConstraint()
184186
} childOf this
185187
} childOf window
186188

187189
ComponentType("BlurHashImage") {
188-
BlurHashImage("L4ESU,OD1e#:=GwwJSAr1M,r|]Ar").constrain {
190+
BlurHashImage(exampleBlurHash).constrain {
189191
x = 2.pixels()
190192
y = SiblingConstraint() + 5.pixels()
191193

192-
width = 100.pixels()
193-
height = 50.pixels()
194+
width = 50.pixels()
195+
height = 60.pixels()
194196
} childOf this
195197

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

200-
width = 100.pixels()
201-
height = 50.pixels()
202+
width = 50.pixels()
203+
height = 60.pixels()
202204
} childOf this
203205
} childOf window
204206

@@ -307,6 +309,9 @@ class ComponentsGui : WindowScreen(ElementaVersion.V2) {
307309
x = 10.pixels(true)
308310
y = 10.pixels(true)
309311
} childOf window
312+
313+
// Fancy background
314+
Modifier.gradient(top = Color(0x091323), Color.BLACK).applyToComponent(window)
310315
}
311316

312317
class ComponentType(componentName: String, initBlock: ComponentType.() -> Unit) : UIContainer() {
@@ -335,4 +340,11 @@ class ComponentsGui : WindowScreen(ElementaVersion.V2) {
335340
private const val OUTLINE_WIDTH = 2f
336341
}
337342
}
343+
344+
companion object {
345+
// AdinaVoicu, CC0, via Wikimedia Commons
346+
// https://commons.wikimedia.org/wiki/File:Tabby_cat_with_blue_eyes-3336579.jpg
347+
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")
348+
val exampleBlurHash = "K8HnZ@.7|,4TIr?H01My5Y"
349+
}
338350
}

0 commit comments

Comments
 (0)