Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memes theme #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ li.right {
width: 80%;
height: 80%;
}
.back img.gif {
object-fit: cover;
}

.centerer {
display: inline-block;
Expand Down Expand Up @@ -547,6 +550,10 @@ img.screenshot {
margin-right: 5px;
}

.theme-icon.gif {
width: 24px;
}

.btn-go-wrapper {
margin-top: 20px;
margin-bottom: 10px;
Expand Down
3 changes: 2 additions & 1 deletion assets/elm/BoardView.elm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ card model dimension row col ( cardId, card ) =
[ class "back" ]
[ div [ class "centerer" ] []
, img
[ src ("/images/" ++ model.game.theme ++ "/" ++ (toString card.value) ++ ".svg")
[ src ("/images/" ++ model.game.theme.name ++ "/" ++ (toString card.value) ++ "." ++ model.game.theme.extension)
, class model.game.theme.extension
]
[]
]
Expand Down
2 changes: 1 addition & 1 deletion assets/elm/Game.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ init : Params -> ( Model, Cmd Msg )
init { id, playerId, host, isSsl, playerName, themes, locale } =
let
game =
Game "" (CardData [] [] [] []) [] 0 0 "eighties" False "public"
Game "" (CardData [] [] [] []) [] 0 0 {name = "eighties", extension = "svg"} False "public"

payload =
JE.object
Expand Down
12 changes: 9 additions & 3 deletions assets/elm/GameList.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import Json.Encode as JE
import Json.Decode as JD exposing (field)
import Dict exposing (Dict)

import Types.Theme exposing (ThemeData)
import Types.Game exposing (themeDataEncoder)


-- Submodules

Expand All @@ -34,7 +37,7 @@ type alias GameId =

type alias Game =
{ id : GameId
, theme : String
, theme : ThemeData
, size : String
, players : List Player
}
Expand Down Expand Up @@ -111,7 +114,7 @@ games model =
a [ class "game-list__game", href <| "/" ++ model.locale ++ "/games/" ++ game.id ]
[ div
[ class "game__visual" ]
[ img [ src <| "/images/" ++ game.theme ++ "/1.svg" ] []
[ img [ src <| "/images/" ++ game.theme.name ++ "/1." ++ game.theme.extension ] []
, div []
[ strong [] [ text game.size ]
]
Expand Down Expand Up @@ -174,7 +177,10 @@ gameDecoder : JD.Decoder Game
gameDecoder =
JD.map4 Game
(field "id" JD.string)
(field "theme" JD.string)
(field "theme" (JD.map2 ThemeData
(field "name" (JD.string))
(field "extension" (JD.string))
))
(field "size" JD.string)
(field "players" (JD.list playerDecoder))

Expand Down
9 changes: 6 additions & 3 deletions assets/elm/GameSettings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,15 @@ themeButton model =
in
div []
[ div [ class <| "btn btn-default btn-lg btn-game-setting " ++ (levelCls model.theme.difficulty), onClick ShowThemeSelector ]
[ img [ class "theme-icon", src <| "/images/" ++ model.theme.name ++ "/1.svg" ]
[ img [ class "theme-icon", src <| "/images/" ++ model.theme.name ++ "/1." ++ model.theme.extension
, class model.theme.extension
]
[]
, i [ class "fa fa-caret-down" ]
[]
]
, input [ type_ "hidden", name "game[theme]", value model.theme.name ] []
, input [ type_ "hidden", name "game[theme][name]", value model.theme.name ] []
, input [ type_ "hidden", name "game[theme][extension]", value model.theme.extension ] []
]


Expand Down Expand Up @@ -452,7 +455,7 @@ themeView theme =
""
in
label [ class <| "btn btn-default btn-theme " ++ (levelCls theme.difficulty), onClick <| SelectTheme theme.name ]
[ img [ src <| "/images/" ++ theme.name ++ "/1.svg", width 50, height 50 ] []
[ img [ src <| "/images/" ++ theme.name ++ "/1." ++ theme.extension, width 50, height 50 ] []
, div [ class "theme-title" ]
[ text theme.title
, sup [ class "text-danger", style [ ( "font-weight", "bold" ) ] ] [ text newBadgeText ]
Expand Down
4 changes: 2 additions & 2 deletions assets/elm/ThemeSelectorView.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Types.Msg exposing (..)
themeSelectorView : Model -> Html Msg
themeSelectorView model =
div [ class "theme-selector" ]
(List.map (themeButton model.game.theme) model.themes)
(List.map (themeButton model.game.theme.name) model.themes)


themeButton : String -> Theme -> Html Msg
Expand All @@ -34,7 +34,7 @@ themeButton activeTheme theme =
else
""
in
label [ class <| "btn btn-default btn-theme " ++ (levelCls theme.difficulty) ++ activeClass, onClick <| ChangeTheme theme.name ]
label [ class <| "btn btn-default btn-theme " ++ (levelCls theme.difficulty) ++ activeClass, onClick <| ChangeTheme theme.name theme.extension ]
[ img [ src <| "/images/" ++ theme.name ++ "/1.svg", width 50, height 50 ] []
, div [ class "theme-title" ]
[ text theme.title
Expand Down
17 changes: 14 additions & 3 deletions assets/elm/Types/Game.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Dict exposing (Dict)

import Types.Player exposing (..)
import Types.Card exposing (..)
import Types.Theme exposing (ThemeData)


type alias GameId =
Expand All @@ -25,14 +26,21 @@ cardDataEncoder cardData =
, ( "values", (List.map JE.int cardData.values) |> JE.list )
]

themeDataEncoder : ThemeData -> JE.Value
themeDataEncoder themeData =
JE.object
[( "name", (JE.string themeData.name) )
, ( "extension", (JE.string themeData.extension) )
]


type alias Game =
{ id : GameId
, cards : CardData
, players : List Player
, flips : Int
, turn : Int
, theme : String
, theme : ThemeData
, random : Bool
, visibility : String
}
Expand All @@ -45,7 +53,7 @@ gameEncoder game =
, ( "players", (List.map playerEncoder game.players) |> JE.list )
, ( "flips", game.flips |> JE.int )
, ( "turn", game.turn |> JE.int )
, ( "theme", game.theme |> JE.string )
, ( "theme", game.theme |> themeDataEncoder )
]


Expand All @@ -64,7 +72,10 @@ gameDecoder =
(field "players" (JD.list playerDecoder))
(field "flips" JD.int)
(field "turn" JD.int)
(field "theme" JD.string)
(field "theme" (JD.map2 ThemeData
(field "name" (JD.string))
(field "extension" (JD.string))
))
(field "random" JD.bool)
(field "visibility" JD.string)

Expand Down
2 changes: 1 addition & 1 deletion assets/elm/Types/Msg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Msg
| SendCompressedGame JE.Value
-- | UpdatePlayer String
| FlipCard Int
| ChangeTheme String
| ChangeTheme String String
| CopyUrl
| SelectGameUrlInput
| Replay
Expand Down
7 changes: 6 additions & 1 deletion assets/elm/Types/Theme.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ type alias Theme =
, title : String
, difficulty : Int
, new : Bool
, extension : String
}

type alias ThemeData =
{ name : String
, extension : String
}

defaultTheme : Theme
defaultTheme =
Theme "eighties" "80's" 0 False
Theme "eighties" "80's" 0 False "svg"
10 changes: 7 additions & 3 deletions assets/elm/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Types.Game exposing (..)
import Types.Model exposing (..)
import Types.Msg exposing (..)
import Types.Player exposing (..)

import Types.Theme exposing (ThemeData)

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
Expand Down Expand Up @@ -125,13 +125,17 @@ update msg model =
else
model ! []

ChangeTheme theme ->
ChangeTheme themeName themeExtension ->
let
game =
model.game

newTheme : ThemeData
newTheme =
{ name = themeName, extension = themeExtension }

game_ =
{ game | theme = theme }
{ game | theme = newTheme }
in
{ model | game = game_ } ! []

Expand Down
2 changes: 1 addition & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ $(function(){
$(".elm-game-selector").each(
function(i, el){
var defaultSettings = {
theme: "eighties",
theme: { name: "eighties", extension: "svg"},
size: 6,
players: 2,
visibility: "public"
Expand Down
Binary file added assets/static/images/memes/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/10.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/11.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/12.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/13.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/14.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/15.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/16.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/17.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/18.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/19.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/20.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/21.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/22.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/23.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/24.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/25.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/26.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/27.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/28.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/29.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/30.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/32.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/memes/33.gif
Binary file added assets/static/images/memes/34.gif
Binary file added assets/static/images/memes/35.gif
Binary file added assets/static/images/memes/36.gif
Binary file added assets/static/images/memes/37.gif
Binary file added assets/static/images/memes/38.gif
Binary file added assets/static/images/memes/39.gif
Binary file added assets/static/images/memes/4.gif
Binary file added assets/static/images/memes/40.gif
Binary file added assets/static/images/memes/5.gif
Binary file added assets/static/images/memes/6.gif
Binary file added assets/static/images/memes/7.gif
Binary file added assets/static/images/memes/8.gif
Binary file added assets/static/images/memes/9.gif
14 changes: 7 additions & 7 deletions lib/pairs_one/game.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule PairsOne.Game do
defstruct id: "",
cards: %{cleared: [], flipped: [], seen: [], values: []},
players: [],
theme: "eighties",
theme: %{ name: "eighties", extension: "svg"},
flips: 2,
turn: -1,
visibility: "public",
Expand Down Expand Up @@ -40,7 +40,7 @@ defmodule PairsOne.Game do
def create(%{
"board_size" => board_size,
"players_number" => players_number,
"theme" => theme_name,
"theme" => theme,
"visibility" => visibility,
"random" => random
}) do
Expand All @@ -64,9 +64,9 @@ defmodule PairsOne.Game do

game = %PairsOne.Game{
id: id,
cards: cards(board_size, Theme.cards_number(theme_name)),
cards: cards(board_size, Theme.cards_number(theme["name"])),
players: players,
theme: theme_name,
theme: theme,
visibility: visibility,
random: random,
turn: turn
Expand All @@ -89,13 +89,13 @@ defmodule PairsOne.Game do
@doc """
Given new params, reset completed game
"""
def replay(game, %{"theme" => theme_name}) do
def replay(game, %{"theme" => theme_data}) do
players =
Enum.map(game["players"], fn player ->
%{player | "score" => 0, "turns" => 0, "inaccurateTurns" => 0}
end)

theme = Theme.get(theme_name)
theme = Theme.get(theme_data.name)

cards =
game["cards"]["values"]
Expand All @@ -104,7 +104,7 @@ defmodule PairsOne.Game do
|> round
|> cards(theme.cards)

game = %{game | "cards" => cards, "players" => players, "theme" => theme_name}
game = %{game | "cards" => cards, "players" => players, "theme" => theme_data.name}

save!(game["id"], game)
end
Expand Down
16 changes: 14 additions & 2 deletions lib/pairs_one/theme.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ defmodule PairsOne.Theme do
difficulty: 0,
new: false
},
memes: %{
title: "Memes",
cards: 40,
difficulty: 0,
new: true,
extension: "gif"
},
ecology: %{
title: "Ecology",
cards: 50,
Expand Down Expand Up @@ -88,7 +95,7 @@ defmodule PairsOne.Theme do
Given theme name, returns number of cards in that theme
"""
def cards_number(name) when is_binary(name) do
@themes[String.to_atom(name)].cards
themes()[String.to_atom(name)].cards
end

@doc """
Expand All @@ -103,12 +110,17 @@ defmodule PairsOne.Theme do
"""
def themes do
@themes
|> Enum.map(fn {name, theme} ->
extension = (theme |> Map.get(:extension)) || "svg"
new_theme = theme |> Map.put(:extension, extension)
{name, new_theme}
end)
end

@doc """
Themes as a list
"""
def list do
@themes |> Enum.map(fn {theme, data} -> Map.merge(data, %{name: theme}) end)
themes() |> Enum.map(fn {theme, data} -> Map.merge(data, %{name: theme}) end)
end
end
2 changes: 1 addition & 1 deletion lib/pairs_one_web/controllers/game_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule PairsOneWeb.GameController do
else
game =
%{
"theme" => "eighties",
"theme" => %{"name" => "eighties", "extension" => "svg"},
"board_size" => "6",
"players_number" => "2",
"visibility" => "public",
Expand Down
9 changes: 6 additions & 3 deletions lib/pairs_one_web/templates/page/index.de.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
Spielen Sie alleine, um Ihre Genauigkeit zu verbessern!
<br/>
<input type="hidden" name="_csrf_token" value="<%= get_csrf_token() %>">
<input type="hidden" name="game[theme]" value="eighties">
<input type="hidden" name="game[theme][name]" value="eighties">
Copy link
Owner

@mxgrn mxgrn Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ufh, how suboptimal, these files.

<input type="hidden" name="game[theme][extension]" value="svg">
<input type="hidden" name="game[board_size]" value="6">
<input type="hidden" name="game[players_number]" value="1">
<input type="hidden" name="game[visibility]" value="private">
Expand Down Expand Up @@ -55,7 +56,8 @@
Senden Sie einfach einen Link an Ihren Online-Freund, um zu beginnen!
<br/>
<input type="hidden" name="_csrf_token" value="<%= get_csrf_token() %>">
<input type="hidden" name="game[theme]" value="eighties">
<input type="hidden" name="game[theme][name]" value="eighties">
<input type="hidden" name="game[theme][extension]" value="svg">
<input type="hidden" name="game[board_size]" value="6">
<input type="hidden" name="game[players_number]" value="2">
<input type="hidden" name="game[visibility]" value="private">
Expand All @@ -75,7 +77,8 @@
Spielen Sie mit Ihrem Freund auf demselben Gerät!
<br/>
<input type="hidden" name="_csrf_token" value="<%= get_csrf_token() %>">
<input type="hidden" name="game[theme]" value="eighties">
<input type="hidden" name="game[theme][name]" value="eighties">
<input type="hidden" name="game[theme][extension]" value="svg">
<input type="hidden" name="game[board_size]" value="6">
<input type="hidden" name="game[players_number]" value="2">
<input type="hidden" name="game[visibility]" value="local">
Expand Down
Loading