-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnd-dice-standard.html
117 lines (104 loc) · 3.33 KB
/
dnd-dice-standard.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
<!--
Copyright 2014 Roger Tawa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../paper-button/paper-button.html">
<!--
`<dnd-dice-standard>` shows a grid of `<paper-button>`s that can roll the
standard D&D dice. Included are buttons to increment and decrement
the dice modifier. Normally, `<dnd-dice-standard>` is used together with
a `<dnd-dice-result>` element.
### Styling
The `<paper-button>` elements can be styled using standard mechanisms.
For example:
#my-dnd-dice-standard paper-button {
/* styles for paper-button */
}
@demo
-->
<dom-module id="dnd-dice-standard">
<template>
<style include="iron-flex iron-flex-alignment">
:host {
display: inline-block;
}
[row]+[row] {
margin-top: 0.5em;
}
paper-button {
text-transform: none;
margin: 0px;
min-width: 1em;
}
[die] {
width: 5em;
}
[die]+[die] {
margin-left: 0.5em;
}
div[die] {
display: inline-block;
}
[mod] {
width: 4em;
}
[mod]+[mod] {
margin-left: 0.5em;
}
</style>
<div class="horizontal layout" row>
<paper-button raised noink die on-tap="_fireDie">d4</paper-button>
<paper-button raised noink die on-tap="_fireDie">d6</paper-button>
</div>
<div class="horizontal layout" row>
<paper-button raised noink die on-tap="_fireDie">d8</paper-button>
<paper-button raised noink die on-tap="_fireDie">d10</paper-button>
</div>
<div class="horizontal layout" row>
<paper-button raised noink die on-tap="_fireDie">d12</paper-button>
<paper-button raised noink die on-tap="_fireDie">d20</paper-button>
</div>
<div class="horizontal layout" row>
<paper-button raised noink die on-tap="_fireDie">d100</paper-button>
<div die class="horizontal layout">
<paper-button raised noink mod plus on-tap="_fireMod">+</paper-button>
<paper-button raised noink mod minus on-tap="_fireMod">-</paper-button>
</div>
</div>
</template>
<script>
(function() {
var _lastClickTime = 0;
var _lastDie = undefined;
var _lastCount = 1;
Polymer({
is: 'dnd-dice-standard',
_fireDie: function(e) {
var sender = e.currentTarget;
if ((e.timeStamp - _lastClickTime < 400) &&
(_lastDie == sender.innerText)) {
++_lastCount;
} else {
_lastDie = sender.innerText;
_lastCount = 1;
}
this.fire('die', _lastCount + sender.innerText);
_lastClickTime = e.timeStamp;
},
_fireMod: function(e) {
this.fire(e.currentTarget.innerText == '+' ? 'inc' : 'dec');
}
});
})();
</script>
</dom-module>