package ru.dbotthepony.kstarbound.world.api

import ru.dbotthepony.kstarbound.defs.tile.NO_DUNGEON_ID
import ru.dbotthepony.kstarbound.network.LegacyNetworkCellState

data class ImmutableCell(
	override val foreground: ImmutableTileState = AbstractTileState.EMPTY,
	override val background: ImmutableTileState = AbstractTileState.EMPTY,
	override val liquid: ImmutableLiquidState = AbstractLiquidState.EMPTY,

	override val dungeonId: Int = NO_DUNGEON_ID,
	override val blockBiome: Int = 0,
	override val envBiome: Int = 0,
	override val biomeTransition: Boolean = false,
) : AbstractCell() {
	override fun immutable(): ImmutableCell {
		return this
	}

	private val legacyNet by lazy { super.toLegacyNet() }

	override fun toLegacyNet(): LegacyNetworkCellState {
		return legacyNet
	}

	override fun tile(background: Boolean): ImmutableTileState {
		if (background)
			return this.background
		else
			return this.foreground
	}

	override fun mutable(): MutableCell {
		return MutableCell(foreground.mutable(), background.mutable(), liquid.mutable(), dungeonId, blockBiome, envBiome, biomeTransition)
	}
}
