<commit_before>module Shufflepuck exposing (create)

import Html exposing (Html)
import Math.Vector3 exposing (Vec3, vec3)
import Task exposing (Task)
import Time exposing (Time)
import Tuple exposing (first)
import WebGL.Texture as Texture exposing (Texture, Error)
import App exposing (App, AppMsg, Focus, appToFocus)
import Body exposing (..)
import Camera exposing (..)
import Camera.Util as Camera
import Control exposing (CtrlMsg)
import Dispatch exposing (..)
import Ground exposing (Ground)
import Model exposing (Inputs)
import Orientation
import Body.Cube exposing (textureCube)


type alias Model =
    Maybe { body : Moving Body
          }


type Msg
    = TextureLoaded (Result Error Texture)


create : String -> String -> ( App, Cmd AppMsg )
create label path =
    App.create (init path)
        { label = always label
        , update = update
        , animate = animate
        , bodies = bodies
        , framing = framing
        , focus = focus
        , overlay = overlay
        }


init : String -> ( Model, Cmd (CtrlMsg Msg) )
init path =
    ( Nothing
    , Texture.load path
        |> Task.attempt (Self << TextureLoaded)
    )


update :
    CtrlMsg Msg
    -> Model
    -> ( Model, Cmd (CtrlMsg Msg) )
update msg model =
    let mapBody f =
            Maybe.map (\m -> { m | body = f m.body } ) model
    in
    case msg of
        Self (TextureLoaded textureResult) ->
            case textureResult of
                Ok texture ->
                    let
                        body =
                            { anchor = AnchorGround
                            , scale = vec3 1 1 1
                            , position = vec3 56 0 -35
                            , orientation = Orientation.initial
                            , appear = textureCube texture
                            , velocity = vec3 0 0 0
                            }
                    in
                        ( Just { body = body }, Cmd.none )

                Err msg ->
                    -- ( { model | message = "Error loading texture" }, Cmd.none )
                    ( model, Cmd.none )

        Ctrl (Control.Move dp) ->
            ( model, Cmd.none )

        Ctrl (Control.Drive ground inputs) ->
            ( model, Cmd.none )

        Effect _ ->
            ( model, Cmd.none )


animate : ground -> Time -> Model -> Model
animate ground dt model =
    model


bodies : Model -> List Body
bodies model_ =
    case model_ of
        Just model ->
            [ toBody model.body ]

        Nothing ->
            []


framing : Model -> Maybe Framing
framing model_ =
    case model_ of
        Just model ->
            Just (Camera.framing model.body)

        Nothing ->
            Nothing
    

focus : Model -> Maybe Focus
focus model =
    Maybe.map (.body >> appToFocus) model

overlay : Model -> Html msg
overlay _ =
    Html.div []
        [ Html.h2 []
              [ Html.text "Shufflepuck" ]
        , Html.text "An air hockey game."
        , Html.br [] []
        , Html.hr [] []
        ]<commit_msg>Shufflepuck: use table : Maybe Body<commit_after>module Shufflepuck exposing (create)

import Html exposing (Html)
import Math.Vector3 exposing (Vec3, vec3)
import Task exposing (Task)
import Time exposing (Time)
import Tuple exposing (first)
import WebGL.Texture as Texture exposing (Texture, Error)
import App exposing (App, AppMsg, Focus, appToFocus)
import Body exposing (..)
import Camera exposing (..)
import Camera.Util as Camera
import Control exposing (CtrlMsg)
import Dispatch exposing (..)
import Ground exposing (Ground)
import Model exposing (Inputs)
import Orientation
import Body.Cube exposing (textureCube)


type alias Model =
    { table : Maybe Body
    }


type Msg
    = TextureLoaded (Result Error Texture)


create : String -> String -> ( App, Cmd AppMsg )
create label path =
    App.create (init path)
        { label = always label
        , update = update
        , animate = animate
        , bodies = bodies
        , framing = framing
        , focus = focus
        , overlay = overlay
        }


init : String -> ( Model, Cmd (CtrlMsg Msg) )
init path =
    ( { table = Nothing
      }
    , Texture.load path
        |> Task.attempt (Self << TextureLoaded)
    )


update :
    CtrlMsg Msg
    -> Model
    -> ( Model, Cmd (CtrlMsg Msg) )
update msg model =
    case msg of
        Self (TextureLoaded textureResult) ->
            case textureResult of
                Ok texture ->
                    let
                        table =
                            { anchor = AnchorGround
                            , scale = vec3 1 0.1 3
                            , position = vec3 56 0 -35
                            , orientation = Orientation.initial
                            , appear = textureCube texture
                            , velocity = vec3 0 0 0
                            }
                    in
                        ( { table = Just table }, Cmd.none )

                Err msg ->
                    -- ( { model | message = "Error loading texture" }, Cmd.none )
                    ( model, Cmd.none )

        Ctrl (Control.Move dp) ->
            ( model, Cmd.none )

        Ctrl (Control.Drive ground inputs) ->
            ( model, Cmd.none )

        Effect _ ->
            ( model, Cmd.none )


animate : ground -> Time -> Model -> Model
animate ground dt model =
    model


bodies : Model -> List Body
bodies model =
    case model.table_ of
        Just table ->
            [ toBody table ]

        Nothing ->
            []
framing : Model -> Maybe Framing
framing model =
        Maybe.map Camera.framing model.table
    

focus : Model -> Maybe Focus
focus model =
    Maybe.map appToFocus model.table

overlay : Model -> Html msg
overlay _ =
    Html.div []
        [ Html.h2 []
              [ Html.text "Shufflepuck" ]
        , Html.text "An air hockey game."
        , Html.br [] []
        , Html.hr [] []
        ]
{'fraction_non_alphanumeric': 0.08909395973154362, 'fraction_numerical': 0.006208053691275168, 'mean_word_length': 1.503569928601428, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 50, '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': '2945574', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1574, 'n_words': 537}