-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
212 lines (165 loc) · 6.02 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html>
<head>
<title>Simulated Dice</title>
<script type="text/javascript" src="./jquery-1.3.2.js"></script>
<script type="text/javascript" src="./dice.js"></script>
<script type="text/javascript">
// <![CDATA[
function createUUID() {
// THIS IS NOT A REAL UUID!!!
var s = [];
var hexDigits = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (var i = 0; i < 8; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[12] = "4";
s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1);
return s.join("");
}
var arolls;
var dice;
var roll_result;
var mods;
var min;
var max;
reset = function(){
each_roll = new Array();
dice = new Array();
roll_result = new Array();
mods = 0;
min = 0;
max = 0;
}
$(function(){
reset();
var form = $("#rolling_form");
var result = $("#result");
var input_roll = $("#txt_roll");
$("#do_roll").click(function(){
r = new roll($("#txt_roll"));
r.roll();
console.log(r);
var uuid = createUUID();
$("span:hidden").show();
result.prepend("<div class=\"result_wrapper\"><div class=\"result\" id=\"" + uuid + "\"><h3>" + r.name + "</h3></div><br style=\"clear:both;\" /></div>");
var result_container = $("#" + uuid);
console.log(r.groups);
for (var a in r.groups) {
var group = r.groups[a];
result_container.append($("<h4>").html(group.name));
result_container.append($("<p>"));
var result_group = result_container
.children("p:last-child");
for(var b in group.result()) {
var d = group.dice[b];
if(group.dice.length >1) {
var item = $("<span class=\"d" + d.sides + "\">")
.hide().html(d.result);
result_group.append(item);
}
if(b == (group.dice.length -1)) {
eq = $("<span class=\"operator\">").hide().html("=");
item = $("<span class=\"total\">")
.hide()
.html(group.sum());
if(group.dice.length > 1) {
result_group.append(eq);
}
result_group.append(item);
}
}
}
for (var a in r.mods) {
var mod = r.mods[a];
result_container.append($("<h4>").html("mod"));
result_container.append($("<p>"));
var result_group = result_container
.children("p:last-child");
var item = $("<span>")
.hide().html(mod.replace("(","").replace(")",""));
result_group.append(item);
}
/*
if(r.mods.length > 0) {
var sub_total = $("<p>")
.append($("<span class=\"sub total\">")
.hide().html(r.subtotal()));
result_container.append(sub_total);
}
*/
var grand_total = $("<p>")
.append($("<h4>").html("Total"))
.append($("<span class=\"grand total\">")
.hide().html(r.sum()));
result_container.append(grand_total);
lis = $("#" + uuid + " span");
function outer(){
var a = -1;
function inner() {
if(a === lis.length){return;}
a++;
var animateSpeed = 0;
if($("#animate:checked").length > 0) animateSpeed = 300;
lis.eq(a).fadeIn(animateSpeed, function(){
if($(this).hasClass("operator")) {
fader();
} else {
$(this).animate({opacity:1.0}, animateSpeed, function(){
fader();
});
}
});
}
return inner;
}
var fader = outer();
fader();
reset();
});
$("#d20").click(function(){
$("#txt_roll").val("1d20");
$("#do_roll").click();
});
$("#do_buttonize").click(function() {
var values = new Array(2);
values = $("#txt_roll").val().split("|");
console.log(values);
console.log(values[1]);
if(values[1] === null || values[1] === undefined) values[1] = values[0];
console.log(values);
var button_title = values[0];
var button_value = values[1];
var button = $("<span>")
.attr("data-roll", button_value)
.addClass("d20 buttonized")
.html(button_title)
.click(function(){
console.log("click");
var roll = $(this).attr('data-roll');
console.log(roll);
$("#txt_roll").val(roll);
$("#do_roll").click();
});
$("#simulator").after(button);
});
});
// ]]>
</script>
<style type="text/css" media="screen">
@import url('./reset.css');
@import url('./dice.css');
</style>
</head>
<body>
<div id="container">
<label for="animate"><input type="checkbox" id="animate" name="chkAnimate" /> Animation</label>
<fieldset id="simulator">
<input id="txt_roll" name="roll" />
<button id="do_roll">Roll!</button>
<button id="do_buttonize">Buttonize!</button>
</fieldset>
<div id="result"></div>
</div>
</body>
</html>