summaryrefslogtreecommitdiff
path: root/views/join.ejs
blob: 2da5f03602523f8706e442ba67bde873c3539e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<%- include('header', { title: game.title_name, refresh: game.status == 0 ? 15 : 0 }) %>
<script>
function confirm_delete(status) {
	let warning = "Are you sure you want to DELETE this game?";
	if (window.confirm(warning))
		window.open("/delete/<%= game.game_id %>");
}
</script>

<a href="/info/<%= game.title_id %>"><img class="logo" src="/<%= game.title_id %>/cover.jpg"></a>

<p>
Owner: <%= game.owner_name %>
<br>
Private: <%= game.private ? "yes" : "no" %>
<br>
Scenario: <%= game.scenario %>
<br>
Description: <%= game.description || "No description." %>

<br clear=left>

<p>
<table>
<tr>
<%
	roles.forEach((role) => {
		%><th><%= role %><%
	});
%>
<tr>
<%
	roles.forEach((role) => {
		if (game.active == role || game.active == "Both" || game.active == "All") {
			%><td style="min-width:9em" class="your_turn"><%
		} else {
			%><td style="min-width:9em"><%
		}
		let p = players.find(p => p.role == role);
		if (game.status == 0) {
			if (p) {
				if ((p.user_id == user.user_id) || (game.owner_id == user.user_id)) {
					%><a style="color:red;text-decoration:none" href="/part/<%= game.game_id %>/<%= p.user_id %>/<%= p.role %>">&#x274c;</a> <%
					%><%= p.name %><%
				} else {
					%><%= p.name %><%
				}
			} else {
				%><a href="/join/<%= game.game_id %>/<%= role %>">Join</a><%
			}
		} else {
			if (p) {
				if (p.user_id == user.user_id) {
					%><a href="/play/<%= game.game_id %>/<%= p.role %>">Play</a><%
				} else {
					%><%= p.name %><%
				}
			} else {
				%><i>Empty</i><%
			}
		}
	});
	if (game.status > 0 && !players.some(p => p.user_id == user.user_id)) {
		%>
		<tr><td colspan="<%= roles.length %>"><a href="/play/<%= game.game_id %>/Observer">View</a>
		<%
	}
%>
</table>

<p>
<%
	if (game.status == 0) {
		if (players.length == roles.length) {
			if (game.owner_id == user.user_id) {
				%><form action="/start/<%= game.game_id %>"><button type="submit">Start!</button></form><%
			} else {
				%>Waiting for <%= game.owner_name %> to start the game.<%
			}
		} else {
			%>Waiting for players to join the game.<%
		}
	}
	if (game.status == 2 && players.some(p => p.user_id == user.user_id)) {
		%><form action="/rematch/<%= game.game_id %>"><button type="submit">Rematch</button></form><%
	}
	if (game.owner_id == user.user_id && (game.status == 0 || solo)) {
		%><p><br><button onclick="confirm_delete()">Delete</button><%
	}
%>