Cauldron2D.Net.Channel (Cauldron2D.Net v0.1.2)

Copy Markdown View Source

The Phoenix channel a game's browser players join, one per player, driven by Cauldron2D.Net.Session.

defmodule MyGame.Web.WorldChannel do
  use Cauldron2D.Net.Channel, game: MyGame.Client, topic: "world", audio: %{rate: 22_050, channels: 2}
end

:game implements Cauldron2D.Client.Game. The topic is "world:<id>" (:topic names another prefix); id is the arena, as its id writes, among the game's arenas/1 given the socket's assigns. The socket's assigns must carry :username; :settings (a map with :sfx and :music) and :sheet_url are read when present. The join params reach the game's join_props/1 as :params, and whatever it returns joins the world as props; a join param "audio" of %{"rate" => hertz, "channels" => 1 | 2} (8 000 to 48 000 Hz) is the PCM format the browser wants, as cauldron.js's audio option sends it; without one the format is the :audio option of use (default 44 100 Hz stereo), and false asks for no sound; what the session gets is Cauldron2D.Net.Audio's to say. A refusal is shown as the game's refusal_text/1 gives it, inspect/1 without one.

Frames from the world are pushed as "map" and "frame", a changed atlas as a new "sheet" and the "map" again, the audio as binary "pcm" pushes (the session's own stage and the world's shared music mixed, as Cauldron2D.Net.Audio's policy has it); "input" (held, aim and an optional strength), "levels", "music" (on, the music switched off or back on at its level) and "pause" (for a world of the player's own) from the browser reach the session. Leaving the channel leaves the world. Input messages arrive many times a second and are not logged.

Summary

Functions

The :audio option for Cauldron2D.Net.Session.join/5 from the join params: the format asked, :off for "audio": false, [] without a valid "audio".

Functions

audio(arg1)

@spec audio(map()) :: [{:audio, %{rate: pos_integer(), channels: 1 | 2} | :off}]

The :audio option for Cauldron2D.Net.Session.join/5 from the join params: the format asked, :off for "audio": false, [] without a valid "audio".