summaryrefslogtreecommitdiff
path: root/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-10-26 21:38:22 -0700
committerElizabeth Hunt <me@liz.coffee>2025-10-26 21:39:58 -0700
commita8e5e723b7e1891c9b352261a3ee4c3d3563e8cf (patch)
tree853df79c877d37d7e5d25f52b301aedcc3d5db55 /composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game
parent395aa7d1c312e495517701be11c21425d9a5838e (diff)
downloadabstraction-engine-kt-main.tar.gz
abstraction-engine-kt-main.zip
Checkpoint twoHEADmain
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game')
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt4
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt4
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/ImageCache.kt9
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt15
4 files changed, 18 insertions, 14 deletions
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt
index 18349c3..1f79dfc 100644
--- a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt
@@ -1,5 +1,3 @@
package coffee.liz.abstractionengine.game
-class AbstractionEngine {
-
-} \ No newline at end of file
+class AbstractionEngine
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt
index 0c3a007..20ea74c 100644
--- a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt
@@ -14,7 +14,7 @@ import kotlin.time.Duration.Companion.nanoseconds
@Composable
fun Game(
world: World,
- content: @Composable () -> Unit
+ content: @Composable () -> Unit,
) {
var frameCount by remember { mutableStateOf(0) }
@@ -36,7 +36,7 @@ fun GameCanvas(
world: World,
renderSystem: Renderer,
backgroundColor: Color = Color.Transparent,
- modifier: Modifier = Modifier
+ modifier: Modifier = Modifier,
) {
Canvas(modifier = modifier) {
// Clear background
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/ImageCache.kt b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/ImageCache.kt
index 0722535..1d64730 100644
--- a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/ImageCache.kt
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/ImageCache.kt
@@ -9,13 +9,14 @@ import androidx.compose.ui.graphics.ImageBitmap
class ImageCache {
private val images = mutableMapOf<String, ImageBitmap>()
- fun loadImage(path: String, image: ImageBitmap) {
+ fun loadImage(
+ path: String,
+ image: ImageBitmap,
+ ) {
images[path] = image
}
- fun getImage(path: String): ImageBitmap? {
- return images[path]
- }
+ fun getImage(path: String): ImageBitmap? = images[path]
fun clear() {
images.clear()
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt
index 57511f3..8e28944 100644
--- a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt
@@ -21,12 +21,14 @@ import kotlin.time.Duration
* Depends on AnimationSystem to ensure animations are updated before rendering.
*/
class Renderer(
- private val imageCache: ImageCache
+ private val imageCache: ImageCache,
) : System {
-
override val dependencies: Set<KClass<out System>> = setOf(AnimationSystem::class)
- override fun update(world: World, duration: Duration) {
+ override fun update(
+ world: World,
+ duration: Duration,
+ ) {
// Rendering happens in render() method, not here
}
@@ -34,7 +36,10 @@ class Renderer(
* Renders all entities with sprites to the given DrawScope.
* This should be called from a Compose Canvas during the draw phase.
*/
- fun render(world: World, drawScope: DrawScope) {
+ fun render(
+ world: World,
+ drawScope: DrawScope,
+ ) {
// Query all entities that can be rendered
world.query(Position::class, SpriteSheet::class, Animator::class).forEach { entity ->
val position = entity.get(Position::class) ?: return@forEach
@@ -57,7 +62,7 @@ class Renderer(
srcOffset = IntOffset(frameRect.x, frameRect.y),
srcSize = IntSize(frameRect.width, frameRect.height),
dstOffset = IntOffset(position.x.toInt(), position.y.toInt()),
- dstSize = IntSize(frameRect.width, frameRect.height)
+ dstSize = IntSize(frameRect.width, frameRect.height),
)
}
}