Skip to content

Commit d2b8617

Browse files
committed
Try to fix removed draws not being cleared if inventory didn't fully refresh
1 parent d6890a4 commit d2b8617

File tree

7 files changed

+69
-24
lines changed

7 files changed

+69
-24
lines changed

build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
id("com.mineinabyss.conventions.copyjar")
1010
id("com.mineinabyss.conventions.publication")
1111
id("com.mineinabyss.conventions.testing")
12-
id("org.jetbrains.compose") version "1.0.1-rc2"
12+
id("org.jetbrains.compose") version "1.1.1"
1313
}
1414

1515
tasks.withType<KotlinCompile> {
@@ -35,6 +35,7 @@ dependencies {
3535
compileOnly(kotlin("stdlib-jdk8"))
3636
compileOnly(Deps.kotlinx.coroutines)
3737
compileOnly(Deps.kotlin.reflect)
38+
compileOnly(Deps.minecraft.anvilgui)
3839
// TODO update to jitpack in idofront
3940
compileOnly("com.github.okkero:Skedule:v1.2.6")
4041

@@ -43,5 +44,8 @@ dependencies {
4344
exclude("org.jetbrains.kotlin")
4445
exclude("org.jetbrains.kotlinx")
4546
}
47+
api(compose.foundation)
48+
49+
// api(compose.foundation)
4650
implementation("com.mineinabyss:idofront:$idofrontVersion")
4751
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
kotlin.code.style=official
22
group=com.mineinabyss
3-
version=0.3
3+
version=0.4-alpha
44
kotlinVersion=1.6.10
55
serverVersion=1.17.1-R0.1-SNAPSHOT
66
idofrontConventions=1.6.10-55

src/main/kotlin/com/mineinabyss/guiy/components/Item.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ fun Item(itemStack: ItemStack, modifier: Modifier = Modifier) {
1717
},
1818
renderer = { node ->
1919
val inv = canvas
20-
for(x in 0 until node.width)
21-
for(y in 0 until node.height)
20+
for (x in 0 until node.width)
21+
for (y in 0 until node.height)
2222
set(inv, x, y, itemStack)
2323
},
2424
modifier = Modifier.sizeIn(minWidth = 1, minHeight = 1).then(modifier)

src/main/kotlin/com/mineinabyss/guiy/components/canvases/Inventory.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mineinabyss.guiy.components.canvases
22

3+
import androidx.compose.foundation.layout.Row
34
import androidx.compose.runtime.*
45
import com.mineinabyss.guiy.guiyPlugin
56
import com.mineinabyss.guiy.inventory.GuiyInventoryHolder
@@ -91,6 +92,7 @@ fun GuiyOwner.Inventory(
9192
}
9293
}
9394

95+
inventory.clear() //TODO check if this works
9496
CompositionLocalProvider(LocalInventory provides inventory) {
9597
Layout(
9698
measurePolicy = StaticMeasurePolicy,

src/main/kotlin/com/mineinabyss/guiy/components/canvases/InventoryScope.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.mineinabyss.guiy.navigation
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.LaunchedEffect
5+
import androidx.compose.runtime.mutableStateListOf
6+
import androidx.compose.runtime.remember
7+
import com.mineinabyss.guiy.guiyPlugin
8+
import com.okkero.skedule.schedule
9+
import org.bukkit.entity.Player
10+
11+
12+
class Navigator<T>(val default: () -> T) {
13+
private val screen: T? get() = screens.lastOrNull()
14+
private val screens = mutableStateListOf<T>()
15+
private val universal = mutableStateListOf<UniversalScreens>()
16+
17+
init {
18+
open(default())
19+
}
20+
21+
fun back() = universal.removeLastOrNull() ?: screens.removeLastOrNull()
22+
fun open(screen: T) = screens.add(screen)
23+
fun open(screen: UniversalScreens) = universal.add(screen)
24+
25+
fun reset() {
26+
screens.clear()
27+
open(default())
28+
}
29+
30+
/**
31+
* Entrypoint for handling composition based on screen.
32+
*
33+
* Includes universal defaults like an Anvil screen.
34+
*/
35+
@Composable
36+
fun withScreen(players: Set<Player>, onEmpty: () -> Unit, run: @Composable (T) -> Unit) {
37+
if (universal.isNotEmpty()) {
38+
when (val screen = universal.first()) {
39+
is UniversalScreens.Anvil -> LaunchedEffect(screen) {
40+
guiyPlugin.schedule {
41+
screen.builder.open(players.first()).inventory
42+
}
43+
}
44+
}
45+
} else screen?.let { run(it) } ?: onEmpty()
46+
}
47+
}
48+
49+
@Composable
50+
fun <T> rememberNavigation(default: () -> T) = remember {
51+
Navigator(default)
52+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.mineinabyss.guiy.navigation
2+
3+
import net.wesjd.anvilgui.AnvilGUI
4+
5+
sealed class UniversalScreens {
6+
class Anvil(val builder: AnvilGUI.Builder): UniversalScreens()
7+
}

0 commit comments

Comments
 (0)