-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
157 lines (150 loc) Β· 4.15 KB
/
index.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>π² d20 - let's roll</title>
<link rel="stylesheet" href="bulma.min.css">
<style type="text/css">
.die {
width: 80px;
}
.mod {
width: 80px;
}
.label {
padding: 5px;
}
.diebox {
text-align: center;
border: 1px solid #000;
padding: 5px 5px;
margin-right: 5px;
margin-bottom: 5px;
min-width: 40px;
height: 40px;
}
.modbox {
border: 1px solid hsl(141, 71%, 48%);
}
.results {
border: 1px solid hsl(217, 71%, 53%);
}
.noborder {
border: 0;
}
.button {
margin: 0 5px;
}
.is-flex {
flex-wrap: wrap;
}
</style>
</head>
<body>
<div id="app">
<section class="hero is-success">
<div class="hero-body">
<div class="container">
<h1 class="title">π² d20</h1>
<h2 class="subtitle">let's roll</h2>
</div>
</div>
</section>
<section class="section">
<div class="container">
<dice :sides="4"></dice>
<dice :sides="6"></dice>
<dice :sides="8"></dice>
<dice :sides="10"></dice>
<dice :sides="12"></dice>
<dice :sides="20"></dice>
</div>
</section>
</div>
<script src="[email protected]"></script>
<script type="text/x-template" id="dice-template">
<div class="dice box">
<div class="columns">
<div class="column is-flex">
<input class="input is-info die" type="number" pattern="[0-9]*" novalidate name="count" v-model="count" placeholder="0" min="0" :max="max">
<div class="label">
<strong>
x <span class="text-light">d{{ sides }}</span>
</strong>
</div>
<input class="mod input is-success" type="number" pattern="[0-9]*" novalidate name="modifier" v-model="mod" placeholder="+0" :max="max">
<button @click="roll" class="button is-primary">Roll</button>
</div>
</div>
<div class="columns">
<div class="column" v-if="error">
<article class="message is-danger">
<div class="message-body">
{{ error }}
</div>
</article>
</div>
<div class="column is-flex" v-if="results.length > 0">
<div class="diebox" v-for="r in results">
{{ r }}
</div>
<div class="diebox modbox" v-if="mod">
<template v-if="mod > 0">+</template>{{ mod }}
</div>
<span class="diebox noborder"> = </span>
<div class="diebox results">
{{ sum }}
</div>
</div>
</div>
</div>
</script>
<script type="text/javascript">
Vue.component('dice', {
template: "#dice-template",
props: ['sides'],
computed: {
sum() {
if (this.results.length) {
return this.results.reduce(function(t, n){
return t+n;
}) + Number(this.mod);
}
return 0;
},
},
methods: {
roll(e){
this.error = null;
let fresh = [];
// simple validation
if (parseInt(this.count) > this.max) { this.error = "too many"; return; }
for (let i = 0; i < parseInt(this.count); i++) {
fresh.push(this.rollDie());
}
this.results = fresh;
},
rollDie(){
return Math.floor(
Math.random() * Math.floor(this.numOfSides)
) + 1;
},
},
data(){
return {
results: [],
count: 1,
error: null,
max: 500,
numOfSides: parseInt(this.sides),
mod: null,
};
},
});
new Vue({
el: '#app',
});
</script>
</body>
</html>