Commit 07eb9cbe authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

Display correct shape in play and conductor pages

Now only display the shape that the user is playing on the play
page (instead of the various sliders)

Also fixed a off-by one bug in the conductor shape assignments
parent e4dddd0b
defmodule Grains.Presence do defmodule Grains.Presence do
alias Grains.Type
@moduledoc """ @moduledoc """
Provides presence tracking to channels and processes. Provides presence tracking to channels and processes.
...@@ -73,16 +76,11 @@ defmodule Grains.Presence do ...@@ -73,16 +76,11 @@ defmodule Grains.Presence do
original presence data. original presence data.
""" """
@nr_types 4
def select_type(uuid) do
{i, _} = Integer.parse(uuid, 16)
Integer.mod(i, @nr_types)
end
def fetch(_topic, entries) do def fetch(_topic, entries) do
for {key, %{metas: metas}} <- entries, into: %{} do for {key, %{metas: metas}} <- entries, into: %{} do
{key, %{metas: metas, type: select_type(key)}} {key, %{metas: metas, type: Type.select_type(key)}}
end end
end end
......
defmodule Grains.Token do defmodule Grains.Token do
import Plug.Conn import Plug.Conn
alias Grains.Type
def init(opts) do def init(opts) do
opts opts
end end
def call(conn, _opts) do def call(conn, _opts) do
uuid = get_session(conn, :user_uuid) || UUID.uuid4(:hex) uuid = get_session(conn, :user_uuid) || UUID.uuid4(:hex)
token = Phoenix.Token.sign(conn, "user socket", uuid ) token = Phoenix.Token.sign(conn, "user socket", uuid )
type = Type.select_type(uuid)
IO.puts "User Type: #{type}"
conn conn
|> assign(:user_token, token) |> assign(:user_token, token)
|> assign(:user_type, type)
|> put_session(:user_uuid, uuid) |> put_session(:user_uuid, uuid)
|> configure_session(renew: true) |> configure_session(renew: true)
......
/* This file is for your main application css. */ /* This file is for your main application css. */
.interfacePanel { .interfacePanel {
display: block; display: none;
height: 300px; height: 300px;
} }
......
...@@ -51,7 +51,7 @@ let AccelerationPanel = { ...@@ -51,7 +51,7 @@ let AccelerationPanel = {
label: s, label: s,
}); });
a.add(this.sliders[s]); // a.add(this.sliders[s]);
}); });
a.background = 'black'; a.background = 'black';
......
...@@ -57,7 +57,7 @@ let OrientationPanel = { ...@@ -57,7 +57,7 @@ let OrientationPanel = {
}); });
console.log(s); console.log(s);
a.add(this.sliders[s]); // a.add(this.sliders[s]);
}); });
a.background = 'black'; a.background = 'black';
......
...@@ -246,7 +246,7 @@ Boid.prototype.render_triangle = function() { ...@@ -246,7 +246,7 @@ Boid.prototype.render_triangle = function() {
} }
Boid.prototype.render_star = function() { Boid.prototype.render_star = function() {
this.star(0, 0, this.radius, this.radius / 2, 7); this.star(0, 0, this.radius, this.radius / 2, 5);
} }
// For each instrument, there is a master class that has a number of boids // For each instrument, there is a master class that has a number of boids
...@@ -345,7 +345,7 @@ let PresenceSketch = { ...@@ -345,7 +345,7 @@ let PresenceSketch = {
masters: {}, // holds the four main instruments masters: {}, // holds the four main instruments
types: {1: 'circle', 2: 'square', 3: 'triangle', 4: 'star'}, types: {0: 'circle', 1: 'square', 2: 'triangle', 3: 'star'},
set_velocity(name, dx, dy) { set_velocity(name, dx, dy) {
PresenceSketch.boids[name].set_velocity(dx, dy); PresenceSketch.boids[name].set_velocity(dx, dy);
......
<h1>Play</h1> <h1>Play</h1>
<p>Orientation</p> <%= if assigns[:user_type] == 0 do %>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-circle">
<circle cx="50" cy="50" r="50" class="svg-circle" />
</svg>
<% end %>
<%= if assigns[:user_type] == 1 do %>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-square">
<rect width="100" height="100" class="svg-square" />
</svg>
<% end %>
<%= if assigns[:user_type] == 2 do %>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-triangle">
<polygon points="0,0 100,0 50,100" />
</svg>
<% end %>
<%= if assigns[:user_type] == 3 do %>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
class="svg-star">
<polygon points="50,5 20,99 95,39 5,39 80,99" />
</svg>
<% end %>
<div id="orientationPanel" class="interfacePanel"></div> <div id="orientationPanel" class="interfacePanel"></div>
Acceleration
<div id="accelerationPanel" class="interfacePanel"></div> <div id="accelerationPanel" class="interfacePanel"></div>
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
</div> <!-- /container --> </div> <!-- /container -->
<script>window.userToken = "<%= assigns[:user_token] %>"</script> <script>window.userToken = "<%= assigns[:user_token] %>"</script>
<script>window.userType = "<%= assigns[:user_type] %>"</script>
<script src="<%= static_path(@conn, "/js/app.js") %>"></script> <script src="<%= static_path(@conn, "/js/app.js") %>"></script>
</body> </body>
</html> </html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment