<commit_before>package org.hexworks.zircon.internal.component.impl

import org.hexworks.cobalt.databinding.api.createPropertyFrom
import org.hexworks.cobalt.databinding.api.extensions.onChange
import org.hexworks.cobalt.databinding.api.property.Property
import org.hexworks.cobalt.datatypes.Maybe
import org.hexworks.cobalt.datatypes.extensions.map
import org.hexworks.cobalt.datatypes.factory.IdentifierFactory
import org.hexworks.cobalt.logging.api.LoggerFactory
import org.hexworks.zircon.api.builder.graphics.LayerBuilder
import org.hexworks.zircon.api.builder.graphics.TileGraphicsBuilder
import org.hexworks.zircon.api.component.Component
import org.hexworks.zircon.api.component.ComponentStyleSet
import org.hexworks.zircon.api.component.Visibility
import org.hexworks.zircon.api.component.data.ComponentMetadata
import org.hexworks.zircon.api.component.renderer.ComponentRenderingStrategy
import org.hexworks.zircon.api.data.Position
import org.hexworks.zircon.api.data.Size
import org.hexworks.zircon.api.data.Snapshot
import org.hexworks.zircon.api.graphics.Layer
import org.hexworks.zircon.api.graphics.TileGraphics
import org.hexworks.zircon.api.uievent.*
import org.hexworks.zircon.internal.Zircon
import org.hexworks.zircon.internal.component.InternalComponent
import org.hexworks.zircon.internal.component.InternalContainer
import org.hexworks.zircon.internal.event.ZirconEvent
import org.hexworks.zircon.internal.event.ZirconScope
import org.hexworks.zircon.internal.uievent.UIEventProcessor
import org.hexworks.zircon.internal.uievent.impl.DefaultUIEventProcessor

@Suppress("UNCHECKED_CAST")
abstract class DefaultComponent(
        componentMetadata: ComponentMetadata,
        override val graphics: TileGraphics = TileGraphicsBuilder
                .newBuilder()
                .withTileset(componentMetadata.tileset)
                .withSize(componentMetadata.size)
                .build(),
        private val renderer: ComponentRenderingStrategy<out Component>,
        private val layer: Layer = LayerBuilder.newBuilder()
                .withOffset(componentMetadata.position)
                .withTileGraphics(graphics)
                .build(),
        private val uiEventProcessor: DefaultUIEventProcessor = UIEventProcessor.createDefault())
    : InternalComponent,
        Layer by layer,
        UIEventProcessor by uiEventProcessor,
        ComponentEventSource by uiEventProcessor {

    // identifiable
    final override val id = IdentifierFactory.randomIdentifier()

    // component
    final override val contentPosition: Position
        get() = renderer.calculateContentPosition()

    final override val absolutePosition: Position
        get() = position + parent.map { it.absolutePosition }.orElse(Position.zero())

    final override val contentSize: Size
        get() = renderer.calculateContentSize(size)

    final override val componentStyleSetProperty: Property<ComponentStyleSet> = createPropertyFrom(ComponentStyleSet.defaultStyleSet())

    final override var componentStyleSet: ComponentStyleSet by componentStyleSetProperty.asDelegate()


    private var parent = Maybe.empty<InternalContainer>()

    final override val visibilityProperty: Property<Visibility> = createPropertyFrom(Visibility.Visible)

    final override var visibility: Visibility by visibilityProperty.asDelegate()


    init {
        visibilityProperty.onChange()
        {
            render()
        }

        componentStyleSetProperty.onChange()
        {
            render()
        }
    }

    final override fun createSnapshot(): Snapshot {
        return graphics.createSnapshot().let { snapshot ->
            Snapshot.create(
                    cells = snapshot.cells.map { it.withPosition(it.position + absolutePosition) },
                    tileset = snapshot.tileset)
        }<commit_msg>#fix for introduce ComponentStyleSet Property for components<commit_after>package org.hexworks.zircon.internal.component.impl

import org.hexworks.cobalt.databinding.api.createPropertyFrom
import org.hexworks.cobalt.databinding.api.extensions.onChange
import org.hexworks.cobalt.databinding.api.property.Property
import org.hexworks.cobalt.datatypes.Maybe
import org.hexworks.cobalt.datatypes.extensions.map
import org.hexworks.cobalt.datatypes.factory.IdentifierFactory
import org.hexworks.cobalt.logging.api.LoggerFactory
import org.hexworks.zircon.api.builder.graphics.LayerBuilder
import org.hexworks.zircon.api.builder.graphics.TileGraphicsBuilder
import org.hexworks.zircon.api.component.Component
import org.hexworks.zircon.api.component.ComponentStyleSet
import org.hexworks.zircon.api.component.Visibility
import org.hexworks.zircon.api.component.data.ComponentMetadata
import org.hexworks.zircon.api.component.renderer.ComponentRenderingStrategy
import org.hexworks.zircon.api.data.Position
import org.hexworks.zircon.api.data.Size
import org.hexworks.zircon.api.data.Snapshot
import org.hexworks.zircon.api.graphics.Layer
import org.hexworks.zircon.api.graphics.TileGraphics
import org.hexworks.zircon.api.uievent.*
import org.hexworks.zircon.internal.Zircon
import org.hexworks.zircon.internal.component.InternalComponent
import org.hexworks.zircon.internal.component.InternalContainer
import org.hexworks.zircon.internal.event.ZirconEvent
import org.hexworks.zircon.internal.event.ZirconScope
import org.hexworks.zircon.internal.uievent.UIEventProcessor
import org.hexworks.zircon.internal.uievent.impl.DefaultUIEventProcessor

@Suppress("UNCHECKED_CAST")
abstract class DefaultComponent(
        componentMetadata: ComponentMetadata,
        override val graphics: TileGraphics = TileGraphicsBuilder
                .newBuilder()
                .withTileset(componentMetadata.tileset)
                .withSize(componentMetadata.size)
                .build(),
        private val renderer: ComponentRenderingStrategy<out Component>,
        private val layer: Layer = LayerBuilder.newBuilder()
                .withOffset(componentMetadata.position)
                .withTileGraphics(graphics)
                .build(),
        private val uiEventProcessor: DefaultUIEventProcessor = UIEventProcessor.createDefault())
    : InternalComponent,
        Layer by layer,
        UIEventProcessor by uiEventProcessor,
        ComponentEventSource by uiEventProcessor {

    // identifiable
    final override val id = IdentifierFactory.randomIdentifier()

    // component
    final override val contentPosition: Position
        get() = renderer.calculateContentPosition()

    final override val absolutePosition: Position
        get() = position + parent.map { it.absolutePosition }.orElse(Position.zero())

    final override val contentSize: Size
        get() = renderer.calculateContentSize(size)

    final override val componentStyleSetProperty: Property<ComponentStyleSet> = createPropertyFrom(componentMetadata.componentStyleSet)

    final override var componentStyleSet: ComponentStyleSet by componentStyleSetProperty.asDelegate()


    private var parent = Maybe.empty<InternalContainer>()

    final override val visibilityProperty: Property<Visibility> = createPropertyFrom(Visibility.Visible)

    final override var visibility: Visibility by visibilityProperty.asDelegate()


    init {
        visibilityProperty.onChange()
        {
            render()
        }

        componentStyleSetProperty.onChange()
        {
            render()
        }
    }

    final override fun createSnapshot(): Snapshot {
        return graphics.createSnapshot().let { snapshot ->
            Snapshot.create(
                    cells = snapshot.cells.map { it.withPosition(it.position + absolutePosition) },
                    tileset = snapshot.tileset)
        }
{'fraction_non_alphanumeric': 0.08166170570726025, 'fraction_numerical': 0.0, 'mean_word_length': 3.7498463429625075, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1094951', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1979, 'n_words': 366}