4 | <%= @inner_content %>
5 |
6 |
--------------------------------------------------------------------------------
/lib/leafblower.ex:
--------------------------------------------------------------------------------
1 | defmodule Leafblower do
2 | @moduledoc """
3 | Leafblower keeps the contexts that define your domain
4 | and business logic.
5 |
6 | Contexts are also responsible for managing your data, regardless
7 | if it comes from the database, an external API or others.
8 | """
9 | end
10 |
--------------------------------------------------------------------------------
/lib/leafblower_web/views/layout_view.ex:
--------------------------------------------------------------------------------
1 | defmodule LeafblowerWeb.LayoutView do
2 | use LeafblowerWeb, :view
3 |
4 | # Phoenix LiveDashboard is available only in development by default,
5 | # so we instruct Elixir to not warn if the dashboard route is missing.
6 | @compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}}
7 | end
8 |
--------------------------------------------------------------------------------
/rel/env.bat.eex:
--------------------------------------------------------------------------------
1 | @echo off
2 | rem Set the release to work across nodes. If using the long name format like
3 | rem the one below (my_app@127.0.0.1), you need to also uncomment the
4 | rem RELEASE_DISTRIBUTION variable below. Must be "sname", "name" or "none".
5 | rem set RELEASE_DISTRIBUTION=name
6 | rem set RELEASE_NODE=<%= @release.name %>@127.0.0.1
7 |
--------------------------------------------------------------------------------
/test/leafblower_web/views/layout_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule LeafblowerWeb.LayoutViewTest do
2 | use LeafblowerWeb.ConnCase, async: true
3 |
4 | # When testing helpers, you may want to import Phoenix.HTML and
5 | # use functions such as safe_to_string() to convert the helper
6 | # result into an HTML string.
7 | # import Phoenix.HTML
8 | end
9 |
--------------------------------------------------------------------------------
/priv/repo/seeds.exs:
--------------------------------------------------------------------------------
1 | # Script for populating the database. You can run it as:
2 | #
3 | # mix run priv/repo/seeds.exs
4 | #
5 | # Inside the script, you can read and write to any of your
6 | # repositories directly:
7 | #
8 | # Leafblower.Repo.insert!(%Leafblower.SomeSchema{})
9 | #
10 | # We recommend using the bang functions (`insert!`, `update!`
11 | # and so on) as they will fail if something goes wrong.
12 |
--------------------------------------------------------------------------------
/rel/vm.args.eex:
--------------------------------------------------------------------------------
1 | ## Customize flags given to the VM: https://erlang.org/doc/man/erl.html
2 | ## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here
3 |
4 | ## Number of dirty schedulers doing IO work (file, sockets, and others)
5 | ##+SDio 5
6 |
7 | ## Increase number of concurrent ports/sockets
8 | ##+Q 65536
9 |
10 | ## Tweak GC to run more often
11 | ##-env ERL_FULLSWEEP_AFTER 10
12 |
--------------------------------------------------------------------------------
/rel/remote.vm.args.eex:
--------------------------------------------------------------------------------
1 | ## Customize flags given to the VM: https://erlang.org/doc/man/erl.html
2 | ## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here
3 |
4 | ## Number of dirty schedulers doing IO work (file, sockets, and others)
5 | ##+SDio 5
6 |
7 | ## Increase number of concurrent ports/sockets
8 | ##+Q 65536
9 |
10 | ## Tweak GC to run more often
11 | ##-env ERL_FULLSWEEP_AFTER 10
12 |
--------------------------------------------------------------------------------
/lib/leafblower_web/templates/layout/live.html.heex:
--------------------------------------------------------------------------------
1 |
2 |
18 | <%= link to: "/" do %>
19 | Leafblower
20 | <% end %>
21 |
22 |
23 |
24 | <%= @inner_content %>
25 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/lib/leafblower/application.ex:
--------------------------------------------------------------------------------
1 | defmodule Leafblower.Application do
2 | # See https://hexdocs.pm/elixir/Application.html
3 | # for more information on OTP Applications
4 | @moduledoc false
5 |
6 | use Application
7 |
8 | @impl true
9 | def start(_type, _args) do
10 | topologies = Application.get_env(:libcluster, :topologies) || []
11 |
12 | children = [
13 | # Start the Telemetry supervisor
14 | LeafblowerWeb.Telemetry,
15 | # {Horde.Registry, [name: Leafblower.GameRegistry, keys: :unique, members: :auto]},
16 | {Cluster.Supervisor, [topologies, [name: Leafblower.ClusterSupervisor]]},
17 | Leafblower.GameSupervisor,
18 | Leafblower.ProcessRegistry,
19 | # Start the PubSub system
20 | {Phoenix.PubSub, name: Leafblower.PubSub},
21 | # Start the Endpoint (http/https)
22 | LeafblowerWeb.Endpoint
23 | ]
24 |
25 | # See https://hexdocs.pm/elixir/Supervisor.html
26 | # for other strategies and supported options
27 | opts = [strategy: :one_for_one, name: Leafblower.Supervisor]
28 | Supervisor.start_link(children, opts)
29 | end
30 |
31 | # Tell Phoenix to update the endpoint configuration
32 | # whenever the application is updated.
33 | @impl true
34 | def config_change(changed, _new, removed) do
35 | LeafblowerWeb.Endpoint.config_change(changed, removed)
36 | :ok
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Leafblower
2 |
3 |
4 |
5 |
6 |
7 | Play Cards Against Humanity online with friends!
8 |
9 | Head over to https://leafblower.fly.dev/ to test it out.
10 |
11 | **Features**
12 | - In-game chat. So you can talk 💩 all you want
13 | - Mobile friendly
14 |
15 | # Development
16 |
17 | This project requires the following to run
18 |
19 | erlang 23.2.1
20 | elixir 1.12
21 |
22 | If you have [asdf](https://github.com/asdf-vm/asdf) installed, simply run `asdf install`
23 |
24 | To run this project locally simply run
25 |
26 | mix deps.get
27 | mix phx.server
28 |
29 | ## Code organization
30 |
31 | | File | What it does |
32 | | --------- | --------------- |
33 | | [game_live](./lib/leafblower_web/controllers/game_live.ex) | This is what you see when you start playing the game |
34 | | [game_statem](./lib/leafblower/game_statem.ex) | Handles the game state and logic |
35 | | [game_supervisor](./lib/leafblower/game_supervisor.ex) | Spawns the `game_statem` and `game_ticker` process |
36 | | [deck](./lib/leafblower/deck.ex) | Handles all operations to the deck like drawing cards from it |
37 | | [cards_against.json](./priv/cards_against.json) | Stores all the cards used in the game. Taken from [JSON Against Humanity](https://github.com/crhallberg/json-against-humanity) |
38 |
39 | # FAQ
40 |
41 | - Where did you get the card packs? I got it from [JSON Against Humanity](https://github.com/crhallberg/json-against-humanity)
42 |
--------------------------------------------------------------------------------
/test/support/data_case.ex:
--------------------------------------------------------------------------------
1 | defmodule Leafblower.DataCase do
2 | @moduledoc """
3 | This module defines the setup for tests requiring
4 | access to the application's data layer.
5 |
6 | You may define functions here to be used as helpers in
7 | your tests.
8 |
9 | Finally, if the test case interacts with the database,
10 | we enable the SQL sandbox, so changes done to the database
11 | are reverted at the end of every test. If you are using
12 | PostgreSQL, you can even run database tests asynchronously
13 | by setting `use Leafblower.DataCase, async: true`, although
14 | this option is not recommended for other databases.
15 | """
16 |
17 | use ExUnit.CaseTemplate
18 |
19 | using do
20 | quote do
21 | alias Leafblower.Repo
22 |
23 | import Ecto
24 | import Ecto.Changeset
25 | import Ecto.Query
26 | import Leafblower.DataCase
27 | end
28 | end
29 |
30 | @doc """
31 | A helper that transforms changeset errors into a map of messages.
32 |
33 | assert {:error, changeset} = Accounts.create_user(%{password: "short"})
34 | assert "password is too short" in errors_on(changeset).password
35 | assert %{password: ["password is too short"]} = errors_on(changeset)
36 |
37 | """
38 | def errors_on(changeset) do
39 | Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
40 | Regex.replace(~r"%{(\w+)}", message, fn _, key ->
41 | opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
42 | end)
43 | end)
44 | end
45 | end
46 |
--------------------------------------------------------------------------------
/lib/leafblower_web/telemetry.ex:
--------------------------------------------------------------------------------
1 | defmodule LeafblowerWeb.Telemetry do
2 | use Supervisor
3 | import Telemetry.Metrics
4 |
5 | def start_link(arg) do
6 | Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
7 | end
8 |
9 | @impl true
10 | def init(_arg) do
11 | children = [
12 | # Telemetry poller will execute the given period measurements
13 | # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
14 | {:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
15 | # Add reporters as children of your supervision tree.
16 | # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
17 | ]
18 |
19 | Supervisor.init(children, strategy: :one_for_one)
20 | end
21 |
22 | def metrics do
23 | [
24 | # Phoenix Metrics
25 | summary("phoenix.endpoint.stop.duration",
26 | unit: {:native, :millisecond}
27 | ),
28 | summary("phoenix.router_dispatch.stop.duration",
29 | tags: [:route],
30 | unit: {:native, :millisecond}
31 | ),
32 |
33 | # VM Metrics
34 | summary("vm.memory.total", unit: {:byte, :kilobyte}),
35 | summary("vm.total_run_queue_lengths.total"),
36 | summary("vm.total_run_queue_lengths.cpu"),
37 | summary("vm.total_run_queue_lengths.io")
38 | ]
39 | end
40 |
41 | defp periodic_measurements do
42 | [
43 | # A module, function and arguments to be invoked periodically.
44 | # This function must call :telemetry.execute/3 and a metric must be added above.
45 | # {LeafblowerWeb, :count_users, []}
46 | ]
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/assets/js/chatHooks.js:
--------------------------------------------------------------------------------
1 | export const ChatInput = {
2 | mounted() {
3 | this.el.addEventListener("keydown", (e) => {
4 | if (e.key === "Enter" && !e.shiftKey) {
5 | e.preventDefault();
6 |
7 | document.querySelector("form").dispatchEvent(new Event("submit", {
8 | bubbles: true,
9 | cancelable: true
10 | }));
11 | }
12 | });
13 | }
14 | }
15 |
16 | /**
17 | * ChatList provides auto scrolling to the bottom of the list
18 | * Taken from https://github.com/elixirschool/live-view-chat/blob/master/assets/js/app.js#L22
19 | */
20 | export const ChatList = {
21 | mounted() {
22 | // Select the node that will be observed for mutations
23 | const targetNode = this.el;
24 |
25 | document.addEventListener("DOMContentLoaded", function () {
26 | targetNode.scrollTop = targetNode.scrollHeight
27 | });
28 |
29 | // Options for the observer (which mutations to observe)
30 | const config = { attributes: true, childList: true, subtree: true };
31 | // Callback function to execute when mutations are observed
32 | const callback = function (mutationsList, observer) {
33 | for (const mutation of mutationsList) {
34 | if (mutation.type == 'childList') {
35 | targetNode.scrollTop = targetNode.scrollHeight
36 | }
37 | }
38 | };
39 | // Create an observer instance linked to the callback function
40 | const observer = new MutationObserver(callback);
41 | // Start observing the target node for configured mutations
42 | observer.observe(targetNode, config);
43 | }
44 | }
--------------------------------------------------------------------------------
/lib/leafblower_web/endpoint.ex:
--------------------------------------------------------------------------------
1 | defmodule LeafblowerWeb.Endpoint do
2 | use Phoenix.Endpoint, otp_app: :leafblower
3 |
4 | # The session will be stored in the cookie and signed,
5 | # this means its contents can be read but not tampered with.
6 | # Set :encryption_salt if you would also like to encrypt it.
7 | @session_options [
8 | store: :cookie,
9 | key: "_leafblower_key",
10 | signing_salt: "a9omCiF9"
11 | ]
12 |
13 | socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
14 |
15 | # Serve at "/" the static files from "priv/static" directory.
16 | #
17 | # You should set gzip to true if you are running phx.digest
18 | # when deploying your static files in production.
19 | plug Plug.Static,
20 | at: "/",
21 | from: :leafblower,
22 | gzip: false,
23 | only: ~w(assets fonts images favicon.ico robots.txt)
24 |
25 | # Code reloading can be explicitly enabled under the
26 | # :code_reloader configuration of your endpoint.
27 | if code_reloading? do
28 | socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
29 | plug Phoenix.LiveReloader
30 | plug Phoenix.CodeReloader
31 | plug Phoenix.Ecto.CheckRepoStatus, otp_app: :leafblower
32 | end
33 |
34 | plug Phoenix.LiveDashboard.RequestLogger,
35 | param_key: "request_logger",
36 | cookie_key: "request_logger"
37 |
38 | plug Plug.RequestId
39 | plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
40 |
41 | plug Plug.Parsers,
42 | parsers: [:urlencoded, :multipart, :json],
43 | pass: ["*/*"],
44 | json_decoder: Phoenix.json_library()
45 |
46 | plug Plug.MethodOverride
47 | plug Plug.Head
48 | plug Plug.Session, @session_options
49 | plug LeafblowerWeb.Router
50 | end
51 |
--------------------------------------------------------------------------------
/lib/leafblower_web/views/error_helpers.ex:
--------------------------------------------------------------------------------
1 | defmodule LeafblowerWeb.ErrorHelpers do
2 | @moduledoc """
3 | Conveniences for translating and building error messages.
4 | """
5 |
6 | use Phoenix.HTML
7 |
8 | @doc """
9 | Generates tag for inlined form input errors.
10 | """
11 | def error_tag(form, field) do
12 | Enum.map(Keyword.get_values(form.errors, field), fn error ->
13 | content_tag(:span, translate_error(error),
14 | class: "invalid-feedback",
15 | phx_feedback_for: input_name(form, field)
16 | )
17 | end)
18 | end
19 |
20 | @doc """
21 | Translates an error message using gettext.
22 | """
23 | def translate_error({msg, opts}) do
24 | # When using gettext, we typically pass the strings we want
25 | # to translate as a static argument:
26 | #
27 | # # Translate "is invalid" in the "errors" domain
28 | # dgettext("errors", "is invalid")
29 | #
30 | # # Translate the number of files with plural rules
31 | # dngettext("errors", "1 file", "%{count} files", count)
32 | #
33 | # Because the error messages we show in our forms and APIs
34 | # are defined inside Ecto, we need to translate them dynamically.
35 | # This requires us to call the Gettext module passing our gettext
36 | # backend as first argument.
37 | #
38 | # Note we use the "errors" domain, which means translations
39 | # should be written to the errors.po file. The :count option is
40 | # set by Ecto and indicates we should also apply plural rules.
41 | if count = opts[:count] do
42 | Gettext.dngettext(LeafblowerWeb.Gettext, "errors", msg, msg, count, opts)
43 | else
44 | Gettext.dgettext(LeafblowerWeb.Gettext, "errors", msg, opts)
45 | end
46 | end
47 | end
48 |
--------------------------------------------------------------------------------
/config/config.exs:
--------------------------------------------------------------------------------
1 | # This file is responsible for configuring your application
2 | # and its dependencies with the aid of the Config module.
3 | #
4 | # This configuration file is loaded before any dependency and
5 | # is restricted to this project.
6 |
7 | # General application configuration
8 | import Config
9 |
10 | config :leafblower,
11 | game_inactivity_timeout: :timer.minutes(30)
12 |
13 | # Configures the endpoint
14 | config :leafblower, LeafblowerWeb.Endpoint,
15 | url: [host: "localhost"],
16 | render_errors: [view: LeafblowerWeb.ErrorView, accepts: ~w(html json), layout: false],
17 | pubsub_server: Leafblower.PubSub,
18 | live_view: [signing_salt: "6oygRDIO"]
19 |
20 | # Configures the mailer
21 | #
22 | # By default it uses the "Local" adapter which stores the emails
23 | # locally. You can see the emails in your browser, at "/dev/mailbox".
24 | #
25 | # For production it's recommended to configure a different adapter
26 | # at the `config/runtime.exs`.
27 | config :leafblower, Leafblower.Mailer, adapter: Swoosh.Adapters.Local
28 |
29 | # Swoosh API client is needed for adapters other than SMTP.
30 | config :swoosh, :api_client, false
31 |
32 | # Configure esbuild (the version is required)
33 | config :esbuild,
34 | version: "0.12.18",
35 | default: [
36 | args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
37 | cd: Path.expand("../assets", __DIR__),
38 | env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
39 | ]
40 |
41 | # Configures Elixir's Logger
42 | config :logger, :console,
43 | format: "$time $metadata[$level] $message\n",
44 | metadata: [:request_id]
45 |
46 | # Use Jason for JSON parsing in Phoenix
47 | config :phoenix, :json_library, Jason
48 |
49 | # Import environment specific config. This must remain at the bottom
50 | # of this file so it overrides the configuration defined above.
51 | import_config "#{config_env()}.exs"
52 |
--------------------------------------------------------------------------------
/lib/leafblower_web/router.ex:
--------------------------------------------------------------------------------
1 | defmodule LeafblowerWeb.Router do
2 | use LeafblowerWeb, :router
3 |
4 | pipeline :browser do
5 | plug :accepts, ["html"]
6 | plug :fetch_session
7 | plug :fetch_live_flash
8 | plug :put_root_layout, {LeafblowerWeb.LayoutView, :root}
9 | plug :protect_from_forgery
10 | plug :put_secure_browser_headers
11 | plug LeafblowerWeb.Plugs.Currentuser
12 | end
13 |
14 | pipeline :ingame do
15 | plug :put_root_layout, {LeafblowerWeb.LayoutView, :ingame}
16 | end
17 |
18 | pipeline :api do
19 | plug :accepts, ["json"]
20 | end
21 |
22 | scope "/", LeafblowerWeb do
23 | pipe_through :browser
24 |
25 | live "/", GameSplashLive, :index
26 | live "/join", GameSplashLive, :join_by_code
27 | live "/start", GameSplashLive, :start_game
28 | live "/:id", GameLive
29 | end
30 |
31 | # Other scopes may use custom stacks.
32 | # scope "/api", LeafblowerWeb do
33 | # pipe_through :api
34 | # end
35 |
36 | # Enables LiveDashboard only for development
37 | #
38 | # If you want to use the LiveDashboard in production, you should put
39 | # it behind authentication and allow only admins to access it.
40 | # If your application does not have an admins-only section yet,
41 | # you can use Plug.BasicAuth to set up some basic authentication
42 | # as long as you are also using SSL (which you should anyway).
43 | if Mix.env() in [:dev, :test] do
44 | import Phoenix.LiveDashboard.Router
45 |
46 | scope "/" do
47 | pipe_through :browser
48 | live_dashboard "/dashboard", metrics: LeafblowerWeb.Telemetry
49 | end
50 | end
51 |
52 | # Enables the Swoosh mailbox preview in development.
53 | #
54 | # Note that preview only shows emails that were sent by the same
55 | # node running the Phoenix server.
56 | if Mix.env() == :dev do
57 | scope "/dev" do
58 | pipe_through :browser
59 |
60 | forward "/mailbox", Plug.Swoosh.MailboxPreview
61 | end
62 | end
63 | end
64 |
--------------------------------------------------------------------------------
/assets/js/app.js:
--------------------------------------------------------------------------------
1 | // We import the CSS which is extracted to its own file by esbuild.
2 | // Remove this line if you add a your own CSS build pipeline (e.g postcss).
3 | import "../css/app.css"
4 |
5 | // If you want to use Phoenix channels, run `mix help phx.gen.channel`
6 | // to get started and then uncomment the line below.
7 | // import "./user_socket.js"
8 |
9 | // You can include dependencies in two ways.
10 | //
11 | // The simplest option is to put them in assets/vendor and
12 | // import them using relative paths:
13 | //
14 | // import "./vendor/some-package.js"
15 | //
16 | // Alternatively, you can `npm install some-package` and import
17 | // them using a path starting with the package name:
18 | //
19 | // import "some-package"
20 | //
21 |
22 | // Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
23 | import "phoenix_html"
24 | // Establish Phoenix Socket and LiveView configuration.
25 | import { Socket } from "phoenix"
26 | import { LiveSocket } from "phoenix_live_view"
27 | import topbar from "../vendor/topbar"
28 | import { ChatInput, ChatList } from "./chatHooks"
29 |
30 | let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
31 | let liveSocket = new LiveSocket("/live", Socket, {
32 | params: { _csrf_token: csrfToken },
33 | hooks: { ChatInput, ChatList }
34 | })
35 |
36 | // Show progress bar on live navigation and form submits
37 | topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" })
38 | window.addEventListener("phx:page-loading-start", info => topbar.show())
39 | window.addEventListener("phx:page-loading-stop", info => topbar.hide())
40 |
41 | // connect if there are any LiveViews on the page
42 | liveSocket.connect()
43 |
44 | // expose liveSocket on window for web console debug logs and latency simulation:
45 | // >> liveSocket.enableDebug()
46 | // >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
47 | // >> liveSocket.disableLatencySim()
48 | window.liveSocket = liveSocket
--------------------------------------------------------------------------------
/config/prod.exs:
--------------------------------------------------------------------------------
1 | import Config
2 |
3 | # For production, don't forget to configure the url host
4 | # to something meaningful, Phoenix uses this information
5 | # when generating URLs.
6 | #
7 | # Note we also include the path to a cache manifest
8 | # containing the digested version of static files. This
9 | # manifest is generated by the `mix phx.digest` task,
10 | # which you should run after static files are built and
11 | # before starting your production server.
12 | config :leafblower, LeafblowerWeb.Endpoint,
13 | cache_static_manifest: "priv/static/cache_manifest.json"
14 |
15 | # Do not print debug messages in production
16 | config :logger, level: :info
17 |
18 | # ## SSL Support
19 | #
20 | # To get SSL working, you will need to add the `https` key
21 | # to the previous section and set your `:url` port to 443:
22 | #
23 | # config :leafblower, LeafblowerWeb.Endpoint,
24 | # ...,
25 | # url: [host: "example.com", port: 443],
26 | # https: [
27 | # ...,
28 | # port: 443,
29 | # cipher_suite: :strong,
30 | # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
31 | # certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
32 | # ]
33 | #
34 | # The `cipher_suite` is set to `:strong` to support only the
35 | # latest and more secure SSL ciphers. This means old browsers
36 | # and clients may not be supported. You can set it to
37 | # `:compatible` for wider support.
38 | #
39 | # `:keyfile` and `:certfile` expect an absolute path to the key
40 | # and cert in disk or a relative path inside priv, for example
41 | # "priv/ssl/server.key". For all supported SSL configuration
42 | # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
43 | #
44 | # We also recommend setting `force_ssl` in your endpoint, ensuring
45 | # no data is ever sent via http, always redirecting to https:
46 | #
47 | # config :leafblower, LeafblowerWeb.Endpoint,
48 | # force_ssl: [hsts: true]
49 | #
50 | # Check `Plug.SSL` for all available options in `force_ssl`.
51 |
--------------------------------------------------------------------------------
/lib/leafblower_web/component/game_chat.ex:
--------------------------------------------------------------------------------
1 | defmodule LeafblowerWeb.Component.GameChat do
2 | use LeafblowerWeb, :live_component
3 |
4 | @impl true
5 | def mount(socket) do
6 | {:ok, assign(socket, changeset: cast_message())}
7 | end
8 |
9 | @impl true
10 | def handle_event("submit", %{"message" => params}, socket) do
11 | chat_publish(socket.assigns.game_id, socket.assigns.user_id, params["message"])
12 | {:noreply, assign(socket, changeset: cast_message())}
13 | end
14 |
15 | @impl true
16 | def handle_event("validate-message", %{"message" => params}, socket) do
17 | {:noreply,
18 | assign(socket,
19 | changeset:
20 | cast_message(params)
21 | |> Map.put(:action, :insert)
22 | )}
23 | end
24 |
25 | @impl true
26 | def render(assigns) do
27 | ~H"""
28 |
484 | """
485 | end
486 |
487 | defp get_white_cards(cards) do
488 | Deck.card(cards, :white)
489 | end
490 | end
491 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Attribution-NonCommercial-ShareAlike 4.0 International
2 |
3 | =======================================================================
4 |
5 | Creative Commons Corporation ("Creative Commons") is not a law firm and
6 | does not provide legal services or legal advice. Distribution of
7 | Creative Commons public licenses does not create a lawyer-client or
8 | other relationship. Creative Commons makes its licenses and related
9 | information available on an "as-is" basis. Creative Commons gives no
10 | warranties regarding its licenses, any material licensed under their
11 | terms and conditions, or any related information. Creative Commons
12 | disclaims all liability for damages resulting from their use to the
13 | fullest extent possible.
14 |
15 | Using Creative Commons Public Licenses
16 |
17 | Creative Commons public licenses provide a standard set of terms and
18 | conditions that creators and other rights holders may use to share
19 | original works of authorship and other material subject to copyright
20 | and certain other rights specified in the public license below. The
21 | following considerations are for informational purposes only, are not
22 | exhaustive, and do not form part of our licenses.
23 |
24 | Considerations for licensors: Our public licenses are
25 | intended for use by those authorized to give the public
26 | permission to use material in ways otherwise restricted by
27 | copyright and certain other rights. Our licenses are
28 | irrevocable. Licensors should read and understand the terms
29 | and conditions of the license they choose before applying it.
30 | Licensors should also secure all rights necessary before
31 | applying our licenses so that the public can reuse the
32 | material as expected. Licensors should clearly mark any
33 | material not subject to the license. This includes other CC-
34 | licensed material, or material used under an exception or
35 | limitation to copyright. More considerations for licensors:
36 | wiki.creativecommons.org/Considerations_for_licensors
37 |
38 | Considerations for the public: By using one of our public
39 | licenses, a licensor grants the public permission to use the
40 | licensed material under specified terms and conditions. If
41 | the licensor's permission is not necessary for any reason--for
42 | example, because of any applicable exception or limitation to
43 | copyright--then that use is not regulated by the license. Our
44 | licenses grant only permissions under copyright and certain
45 | other rights that a licensor has authority to grant. Use of
46 | the licensed material may still be restricted for other
47 | reasons, including because others have copyright or other
48 | rights in the material. A licensor may make special requests,
49 | such as asking that all changes be marked or described.
50 | Although not required by our licenses, you are encouraged to
51 | respect those requests where reasonable. More considerations
52 | for the public:
53 | wiki.creativecommons.org/Considerations_for_licensees
54 |
55 | =======================================================================
56 |
57 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
58 | Public License
59 |
60 | By exercising the Licensed Rights (defined below), You accept and agree
61 | to be bound by the terms and conditions of this Creative Commons
62 | Attribution-NonCommercial-ShareAlike 4.0 International Public License
63 | ("Public License"). To the extent this Public License may be
64 | interpreted as a contract, You are granted the Licensed Rights in
65 | consideration of Your acceptance of these terms and conditions, and the
66 | Licensor grants You such rights in consideration of benefits the
67 | Licensor receives from making the Licensed Material available under
68 | these terms and conditions.
69 |
70 |
71 | Section 1 -- Definitions.
72 |
73 | a. Adapted Material means material subject to Copyright and Similar
74 | Rights that is derived from or based upon the Licensed Material
75 | and in which the Licensed Material is translated, altered,
76 | arranged, transformed, or otherwise modified in a manner requiring
77 | permission under the Copyright and Similar Rights held by the
78 | Licensor. For purposes of this Public License, where the Licensed
79 | Material is a musical work, performance, or sound recording,
80 | Adapted Material is always produced where the Licensed Material is
81 | synched in timed relation with a moving image.
82 |
83 | b. Adapter's License means the license You apply to Your Copyright
84 | and Similar Rights in Your contributions to Adapted Material in
85 | accordance with the terms and conditions of this Public License.
86 |
87 | c. BY-NC-SA Compatible License means a license listed at
88 | creativecommons.org/compatiblelicenses, approved by Creative
89 | Commons as essentially the equivalent of this Public License.
90 |
91 | d. Copyright and Similar Rights means copyright and/or similar rights
92 | closely related to copyright including, without limitation,
93 | performance, broadcast, sound recording, and Sui Generis Database
94 | Rights, without regard to how the rights are labeled or
95 | categorized. For purposes of this Public License, the rights
96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
97 | Rights.
98 |
99 | e. Effective Technological Measures means those measures that, in the
100 | absence of proper authority, may not be circumvented under laws
101 | fulfilling obligations under Article 11 of the WIPO Copyright
102 | Treaty adopted on December 20, 1996, and/or similar international
103 | agreements.
104 |
105 | f. Exceptions and Limitations means fair use, fair dealing, and/or
106 | any other exception or limitation to Copyright and Similar Rights
107 | that applies to Your use of the Licensed Material.
108 |
109 | g. License Elements means the license attributes listed in the name
110 | of a Creative Commons Public License. The License Elements of this
111 | Public License are Attribution, NonCommercial, and ShareAlike.
112 |
113 | h. Licensed Material means the artistic or literary work, database,
114 | or other material to which the Licensor applied this Public
115 | License.
116 |
117 | i. Licensed Rights means the rights granted to You subject to the
118 | terms and conditions of this Public License, which are limited to
119 | all Copyright and Similar Rights that apply to Your use of the
120 | Licensed Material and that the Licensor has authority to license.
121 |
122 | j. Licensor means the individual(s) or entity(ies) granting rights
123 | under this Public License.
124 |
125 | k. NonCommercial means not primarily intended for or directed towards
126 | commercial advantage or monetary compensation. For purposes of
127 | this Public License, the exchange of the Licensed Material for
128 | other material subject to Copyright and Similar Rights by digital
129 | file-sharing or similar means is NonCommercial provided there is
130 | no payment of monetary compensation in connection with the
131 | exchange.
132 |
133 | l. Share means to provide material to the public by any means or
134 | process that requires permission under the Licensed Rights, such
135 | as reproduction, public display, public performance, distribution,
136 | dissemination, communication, or importation, and to make material
137 | available to the public including in ways that members of the
138 | public may access the material from a place and at a time
139 | individually chosen by them.
140 |
141 | m. Sui Generis Database Rights means rights other than copyright
142 | resulting from Directive 96/9/EC of the European Parliament and of
143 | the Council of 11 March 1996 on the legal protection of databases,
144 | as amended and/or succeeded, as well as other essentially
145 | equivalent rights anywhere in the world.
146 |
147 | n. You means the individual or entity exercising the Licensed Rights
148 | under this Public License. Your has a corresponding meaning.
149 |
150 |
151 | Section 2 -- Scope.
152 |
153 | a. License grant.
154 |
155 | 1. Subject to the terms and conditions of this Public License,
156 | the Licensor hereby grants You a worldwide, royalty-free,
157 | non-sublicensable, non-exclusive, irrevocable license to
158 | exercise the Licensed Rights in the Licensed Material to:
159 |
160 | a. reproduce and Share the Licensed Material, in whole or
161 | in part, for NonCommercial purposes only; and
162 |
163 | b. produce, reproduce, and Share Adapted Material for
164 | NonCommercial purposes only.
165 |
166 | 2. Exceptions and Limitations. For the avoidance of doubt, where
167 | Exceptions and Limitations apply to Your use, this Public
168 | License does not apply, and You do not need to comply with
169 | its terms and conditions.
170 |
171 | 3. Term. The term of this Public License is specified in Section
172 | 6(a).
173 |
174 | 4. Media and formats; technical modifications allowed. The
175 | Licensor authorizes You to exercise the Licensed Rights in
176 | all media and formats whether now known or hereafter created,
177 | and to make technical modifications necessary to do so. The
178 | Licensor waives and/or agrees not to assert any right or
179 | authority to forbid You from making technical modifications
180 | necessary to exercise the Licensed Rights, including
181 | technical modifications necessary to circumvent Effective
182 | Technological Measures. For purposes of this Public License,
183 | simply making modifications authorized by this Section 2(a)
184 | (4) never produces Adapted Material.
185 |
186 | 5. Downstream recipients.
187 |
188 | a. Offer from the Licensor -- Licensed Material. Every
189 | recipient of the Licensed Material automatically
190 | receives an offer from the Licensor to exercise the
191 | Licensed Rights under the terms and conditions of this
192 | Public License.
193 |
194 | b. Additional offer from the Licensor -- Adapted Material.
195 | Every recipient of Adapted Material from You
196 | automatically receives an offer from the Licensor to
197 | exercise the Licensed Rights in the Adapted Material
198 | under the conditions of the Adapter's License You apply.
199 |
200 | c. No downstream restrictions. You may not offer or impose
201 | any additional or different terms or conditions on, or
202 | apply any Effective Technological Measures to, the
203 | Licensed Material if doing so restricts exercise of the
204 | Licensed Rights by any recipient of the Licensed
205 | Material.
206 |
207 | 6. No endorsement. Nothing in this Public License constitutes or
208 | may be construed as permission to assert or imply that You
209 | are, or that Your use of the Licensed Material is, connected
210 | with, or sponsored, endorsed, or granted official status by,
211 | the Licensor or others designated to receive attribution as
212 | provided in Section 3(a)(1)(A)(i).
213 |
214 | b. Other rights.
215 |
216 | 1. Moral rights, such as the right of integrity, are not
217 | licensed under this Public License, nor are publicity,
218 | privacy, and/or other similar personality rights; however, to
219 | the extent possible, the Licensor waives and/or agrees not to
220 | assert any such rights held by the Licensor to the limited
221 | extent necessary to allow You to exercise the Licensed
222 | Rights, but not otherwise.
223 |
224 | 2. Patent and trademark rights are not licensed under this
225 | Public License.
226 |
227 | 3. To the extent possible, the Licensor waives any right to
228 | collect royalties from You for the exercise of the Licensed
229 | Rights, whether directly or through a collecting society
230 | under any voluntary or waivable statutory or compulsory
231 | licensing scheme. In all other cases the Licensor expressly
232 | reserves any right to collect such royalties, including when
233 | the Licensed Material is used other than for NonCommercial
234 | purposes.
235 |
236 |
237 | Section 3 -- License Conditions.
238 |
239 | Your exercise of the Licensed Rights is expressly made subject to the
240 | following conditions.
241 |
242 | a. Attribution.
243 |
244 | 1. If You Share the Licensed Material (including in modified
245 | form), You must:
246 |
247 | a. retain the following if it is supplied by the Licensor
248 | with the Licensed Material:
249 |
250 | i. identification of the creator(s) of the Licensed
251 | Material and any others designated to receive
252 | attribution, in any reasonable manner requested by
253 | the Licensor (including by pseudonym if
254 | designated);
255 |
256 | ii. a copyright notice;
257 |
258 | iii. a notice that refers to this Public License;
259 |
260 | iv. a notice that refers to the disclaimer of
261 | warranties;
262 |
263 | v. a URI or hyperlink to the Licensed Material to the
264 | extent reasonably practicable;
265 |
266 | b. indicate if You modified the Licensed Material and
267 | retain an indication of any previous modifications; and
268 |
269 | c. indicate the Licensed Material is licensed under this
270 | Public License, and include the text of, or the URI or
271 | hyperlink to, this Public License.
272 |
273 | 2. You may satisfy the conditions in Section 3(a)(1) in any
274 | reasonable manner based on the medium, means, and context in
275 | which You Share the Licensed Material. For example, it may be
276 | reasonable to satisfy the conditions by providing a URI or
277 | hyperlink to a resource that includes the required
278 | information.
279 | 3. If requested by the Licensor, You must remove any of the
280 | information required by Section 3(a)(1)(A) to the extent
281 | reasonably practicable.
282 |
283 | b. ShareAlike.
284 |
285 | In addition to the conditions in Section 3(a), if You Share
286 | Adapted Material You produce, the following conditions also apply.
287 |
288 | 1. The Adapter's License You apply must be a Creative Commons
289 | license with the same License Elements, this version or
290 | later, or a BY-NC-SA Compatible License.
291 |
292 | 2. You must include the text of, or the URI or hyperlink to, the
293 | Adapter's License You apply. You may satisfy this condition
294 | in any reasonable manner based on the medium, means, and
295 | context in which You Share Adapted Material.
296 |
297 | 3. You may not offer or impose any additional or different terms
298 | or conditions on, or apply any Effective Technological
299 | Measures to, Adapted Material that restrict exercise of the
300 | rights granted under the Adapter's License You apply.
301 |
302 |
303 | Section 4 -- Sui Generis Database Rights.
304 |
305 | Where the Licensed Rights include Sui Generis Database Rights that
306 | apply to Your use of the Licensed Material:
307 |
308 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
309 | to extract, reuse, reproduce, and Share all or a substantial
310 | portion of the contents of the database for NonCommercial purposes
311 | only;
312 |
313 | b. if You include all or a substantial portion of the database
314 | contents in a database in which You have Sui Generis Database
315 | Rights, then the database in which You have Sui Generis Database
316 | Rights (but not its individual contents) is Adapted Material,
317 | including for purposes of Section 3(b); and
318 |
319 | c. You must comply with the conditions in Section 3(a) if You Share
320 | all or a substantial portion of the contents of the database.
321 |
322 | For the avoidance of doubt, this Section 4 supplements and does not
323 | replace Your obligations under this Public License where the Licensed
324 | Rights include other Copyright and Similar Rights.
325 |
326 |
327 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
328 |
329 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
330 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
331 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
332 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
333 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
334 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
335 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
336 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
337 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
338 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
339 |
340 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
341 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
342 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
343 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
344 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
345 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
346 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
347 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
348 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
349 |
350 | c. The disclaimer of warranties and limitation of liability provided
351 | above shall be interpreted in a manner that, to the extent
352 | possible, most closely approximates an absolute disclaimer and
353 | waiver of all liability.
354 |
355 |
356 | Section 6 -- Term and Termination.
357 |
358 | a. This Public License applies for the term of the Copyright and
359 | Similar Rights licensed here. However, if You fail to comply with
360 | this Public License, then Your rights under this Public License
361 | terminate automatically.
362 |
363 | b. Where Your right to use the Licensed Material has terminated under
364 | Section 6(a), it reinstates:
365 |
366 | 1. automatically as of the date the violation is cured, provided
367 | it is cured within 30 days of Your discovery of the
368 | violation; or
369 |
370 | 2. upon express reinstatement by the Licensor.
371 |
372 | For the avoidance of doubt, this Section 6(b) does not affect any
373 | right the Licensor may have to seek remedies for Your violations
374 | of this Public License.
375 |
376 | c. For the avoidance of doubt, the Licensor may also offer the
377 | Licensed Material under separate terms or conditions or stop
378 | distributing the Licensed Material at any time; however, doing so
379 | will not terminate this Public License.
380 |
381 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
382 | License.
383 |
384 |
385 | Section 7 -- Other Terms and Conditions.
386 |
387 | a. The Licensor shall not be bound by any additional or different
388 | terms or conditions communicated by You unless expressly agreed.
389 |
390 | b. Any arrangements, understandings, or agreements regarding the
391 | Licensed Material not stated herein are separate from and
392 | independent of the terms and conditions of this Public License.
393 |
394 |
395 | Section 8 -- Interpretation.
396 |
397 | a. For the avoidance of doubt, this Public License does not, and
398 | shall not be interpreted to, reduce, limit, restrict, or impose
399 | conditions on any use of the Licensed Material that could lawfully
400 | be made without permission under this Public License.
401 |
402 | b. To the extent possible, if any provision of this Public License is
403 | deemed unenforceable, it shall be automatically reformed to the
404 | minimum extent necessary to make it enforceable. If the provision
405 | cannot be reformed, it shall be severed from this Public License
406 | without affecting the enforceability of the remaining terms and
407 | conditions.
408 |
409 | c. No term or condition of this Public License will be waived and no
410 | failure to comply consented to unless expressly agreed to by the
411 | Licensor.
412 |
413 | d. Nothing in this Public License constitutes or may be interpreted
414 | as a limitation upon, or waiver of, any privileges and immunities
415 | that apply to the Licensor or You, including from the legal
416 | processes of any jurisdiction or authority.
417 |
418 | =======================================================================
419 |
420 | Creative Commons is not a party to its public
421 | licenses. Notwithstanding, Creative Commons may elect to apply one of
422 | its public licenses to material it publishes and in those instances
423 | will be considered the “Licensor.” The text of the Creative Commons
424 | public licenses is dedicated to the public domain under the CC0 Public
425 | Domain Dedication. Except for the limited purpose of indicating that
426 | material is shared under a Creative Commons public license or as
427 | otherwise permitted by the Creative Commons policies published at
428 | creativecommons.org/policies, Creative Commons does not authorize the
429 | use of the trademark "Creative Commons" or any other trademark or logo
430 | of Creative Commons without its prior written consent including,
431 | without limitation, in connection with any unauthorized modifications
432 | to any of its public licenses or any other arrangements,
433 | understandings, or agreements concerning use of licensed material. For
434 | the avoidance of doubt, this paragraph does not form part of the
435 | public licenses.
436 |
437 | Creative Commons may be contacted at creativecommons.org.
438 |
--------------------------------------------------------------------------------