package com.pixelized.desktop.lwa.ui.screen.campaign.map

import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import com.pixelized.desktop.lwa.ui.composable.scene.Scene
import com.pixelized.desktop.lwa.ui.composable.scene.camera.Camera
import com.pixelized.desktop.lwa.ui.composable.scene.drawables.SceneLayer
import com.pixelized.shared.lwa.model.map.Map

class MapSceneFactory {

    suspend fun convertToScene(
        map: Map,
        image: suspend (String) -> ImageBitmap,
    ): Scene {
        return Scene(
            size = IntSize(
                width = map.size.width,
                height = map.size.height,
            ),
            layers = map.resources.map { resource ->
                SceneLayer(
                    id = resource.id,
                    name = resource.name,
                    texture = image(resource.uri),
                )
            },
            elements = emptyList(),
        )
    }

    fun convertToCamera(
        camera: Map.Camera
    ) : Camera {
        return Camera(
            initialZoom = camera.zoom,
            initialOffset = IntOffset(
                x = camera.offsetX,
                y = camera.offsetY,
            )
        )
    }
}