-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
142 lines (131 loc) · 3.28 KB
/
ui.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const $ = (selector, context = document) => context.querySelector(selector);
const $$ = (selector, context = document) => Array.from(context.querySelectorAll(selector));
const app = new Vue({
el: '#level-counter',
data: {
players: [new Player(), new Player(), new Player()],
get selected() {
return this.l.selected[0];
},
set selected(player) {
this.l.selected[0] = player
},
roll: 6,
l: {
selected: [],
showLeft: false,
showRight: false,
},
playersColumns: [
{
name: 'id',
field: 'id',
},
{
name: 'name',
field: 'name',
label: 'Name',
align: 'left',
sortable: true,
},
{
name: 'level',
field: 'level',
label: 'Level',
align: 'right',
sortable: true,
},
{
name: 'force',
field: 'force',
label: 'Force',
align: 'right',
sortable: true,
},
],
},
created() {
this.select(this.players[0]);
this.rollDice();
},
methods: {
rollIcon() {
switch(this.roll) {
case 1:
return 'looks_one';
case 2:
return 'looks_two';
default:
return `looks_${this.roll}`;
}
},
addPlayer() {
const player = new Player();
this.players.push(player);
if (this.selected) return;
this.select(player);
},
select(player) {
this.selected = player;
this.$refs.players && (this.$refs.players.selected = player);
},
isActive(player) {
return this.selected === player
},
isEmpty() {
return this.players.length === 0;
},
previous() {
if (this.isEmpty()) return;
let index = this.players.indexOf(this.selected) - 1;
if (index < 0) index = this.players.length + index;
this.select(this.players[index]);
},
next() {
if (this.isEmpty()) return;
let index = this.players.indexOf(this.selected) + 1;
index %= this.players.length;
this.select(this.players[index]);
},
removePlayer(player) {
player = player || this.selected;
let index = this.players.indexOf(player);
this.players.splice(index, 1);
index = index % this.players.length;
this.select(this.players[index || 0]);
},
rollDice() {
this.roll = Math.floor(Math.random() * 6) + 1
},
inviteFriend() {
const quasar = this.$q;
host({
displayInvitation: (invitation) => {
return quasar.dialog({
title: 'Send this message to your friend :',
message: JSON.stringify(invitation)
});
},
provideResponse: () => quasar.dialog({
title: 'Put message from your friend :',
prompt: {
type: 'textarea',
},
}).then(JSON.parse)
}).catch(console.error)
},
joinFriend() {
const quasar = this.$q;
quasar.dialog({
title: 'Paste the message provided by your friend',
prompt: {
type: 'textarea',
}
}).then(JSON.parse)
.then(offer => join(offer, response => quasar.dialog({
title: 'Send this response to your friend :',
message: JSON.stringify(response)
})));
}
}
});