<commit_before>
module Spawn exposing (Effect(..),
                       Msg(..),
                       Model,
                       init,
                       update,
                       view)

import Html exposing (Html, div, h5, p, figure, a, img, text)
import Html.Attributes exposing (class, src)
import Html.Lazy exposing (lazy)
import Effects exposing (Effects)
import Keyboard.Extra as Keyboard
import Json.Encode exposing (encode)

-- Local imports

import Command exposing (SpawnCommand, initSpawnCommand, encodeSpawnCommand)
import GoldEvent exposing (GoldEvent, goldEventGold)

-- Actions

type Effect =
    WsSendMsg String

type Msg =
    KeyboardMsg Keyboard.Model |
    GoldEv GoldEvent

-- Model

type alias Model = {
    entityType : String,
    gold : Int
}

init : Effects Model Effect
init =
    Effects.return {
        entityType = "",
        gold = 0
    }

-- Update

update : Msg -> Model -> Effects Model Effect
update msg model =
    case msg of

        KeyboardMsg keyboardModel ->
            onKeyboardMsg keyboardModel model

        GoldEv goldEvent ->
            onGoldEvent goldEvent model

onKeyboardMsg : Keyboard.Model -> Model -> Effects Model Effect
onKeyboardMsg keyboardModel model =
    case entityType keyboardModel of

        Just entity ->
            let
                spawnCmdJson = initSpawnCommand entity
                                |> encodeSpawnCommand
                                |> encode 0
            in
                Effects.init {model | entityType = entity} [
                    WsSendMsg spawnCmdJson
                ]

        Nothing ->
            Effects.return model

onGoldEvent : GoldEvent -> Model -> Effects Model Effect
onGoldEvent goldEvent model =
    let
        gold = goldEventGold goldEvent
    in
        Effects.return {model | gold = gold}

entityType : Keyboard.Model -> Maybe String
entityType keyboardModel =
    if Keyboard.isPressed Keyboard.CharA keyboardModel then
        Just "champion"

    else if Keyboard.isPressed Keyboard.CharS keyboardModel then
        Just "demon"

    else if Keyboard.isPressed Keyboard.CharD keyboardModel then
        Just "roman_guard"

    else if Keyboard.isPressed Keyboard.CharW keyboardModel then
        Just "chaos_rider"

    else
        Nothing

-- View

view : Model -> Html Msg
view model =
    lazy spawnTile model

spawnTile : Model -> Html Msg
spawnTile model =
    div [class "tile is-vertical is-2 box is-overlay spawn-content"] [

        -- Heading
        div [class "columns"] [
            spawnTitle,
            goldColumn model
        ],

        -- Entities
        div [class "columns"] [
            championColumn,
            demonColumn
        ],

        div [class "columns"] [
            romanGuardColumn,
            chaosRiderColumn
        ]
    ]

spawnTitle : Html Msg
spawnTitle =<commit_msg>Added Column<commit_after>
module Spawn exposing (Effect(..),
                       Msg(..),
                       Model,
                       init,
                       update,
                       view)

import Html exposing (Html, div, h5, p, figure, a, img, text)
import Html.Attributes exposing (class, src)
import Html.Lazy exposing (lazy)
import Effects exposing (Effects)
import Keyboard.Extra as Keyboard
import Json.Encode exposing (encode)

-- Local imports

import Command exposing (SpawnCommand, initSpawnCommand, encodeSpawnCommand)
import GoldEvent exposing (GoldEvent, goldEventGold)

-- Actions

type Effect =
    WsSendMsg String

type Msg =
    KeyboardMsg Keyboard.Model |
    GoldEv GoldEvent

-- Model

type alias Model = {
    entityType : String,
    gold : Int
}

init : Effects Model Effect
init =
    Effects.return {
        entityType = "",
        gold = 0
    }

-- Update

update : Msg -> Model -> Effects Model Effect
update msg model =
    case msg of

        KeyboardMsg keyboardModel ->
            onKeyboardMsg keyboardModel model

        GoldEv goldEvent ->
            onGoldEvent goldEvent model

onKeyboardMsg : Keyboard.Model -> Model -> Effects Model Effect
onKeyboardMsg keyboardModel model =
    case entityType keyboardModel of

        Just entity ->
            let
                spawnCmdJson = initSpawnCommand entity
                                |> encodeSpawnCommand
                                |> encode 0
            in
                Effects.init {model | entityType = entity} [
                    WsSendMsg spawnCmdJson
                ]

        Nothing ->
            Effects.return model

onGoldEvent : GoldEvent -> Model -> Effects Model Effect
onGoldEvent goldEvent model =
    let
        gold = goldEventGold goldEvent
    in
        Effects.return {model | gold = gold}

entityType : Keyboard.Model -> Maybe String
entityType keyboardModel =
    if Keyboard.isPressed Keyboard.CharA keyboardModel then
        Just "champion"

    else if Keyboard.isPressed Keyboard.CharS keyboardModel then
        Just "demon"

    else if Keyboard.isPressed Keyboard.CharD keyboardModel then
        Just "roman_guard"

    else if Keyboard.isPressed Keyboard.CharW keyboardModel then
        Just "chaos_rider"

    else
        Nothing

-- View

view : Model -> Html Msg
view model =
    lazy spawnTile model

spawnTile : Model -> Html Msg
spawnTile model =
    div [class "tile is-vertical is-2 box is-overlay spawn-content"] [

        -- Heading
        div [class "columns"] [
            spawnTitleColumn,
            goldColumn model
        ],

        -- Entities
        div [class "columns"] [
            championColumn,
            demonColumn
        ],

        div [class "columns"] [
            romanGuardColumn,
            chaosRiderColumn
        ]
    ]

spawnTitleColumn : Html Msg
spawnTitleColumn =
{'fraction_non_alphanumeric': 0.06614718614718615, 'fraction_numerical': 0.0013852813852813853, 'mean_word_length': 1.8481262327416172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1542504', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1516, 'n_words': 483}