-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasicrp.html
147 lines (125 loc) · 4.96 KB
/
basicrp.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/general.css">
</head>
<body>
<div id="Character">
<p id="rpg"></p>
<input type="submit" value="Rules" id="show_rules" class="click" onclick="showRules()">
<p id="rules" class="text"></p>
<p id="form" class="text">Skill: </p><input type="text" id="skill" value="55" class="num">
<input type="submit" value="Roll" id="update" onclick="drawData()" class="click">
</div>
<br>
<h3 id="error"></h3>
<div class="chart-container">
<canvas id="chart"></canvas>
</div>
<script>
drawData();
async function drawData()
{
if(window.chartObject!= undefined)
window.chartObject.destroy();
document.getElementById('error').innerHTML = '';
let req = await fetch('api.php?basicrp',
{
method: "post",
headers: new Headers({
"Content-Type": "application/json"
}),
body: JSON.stringify({
skill: document.getElementById('skill').value
})
});
json_data = await req.json();
if(json_data.error)
{
document.getElementById('error').innerHTML = json_data.error;
}
else
{
document.getElementById('rpg').innerHTML = json_data.rpg;
document.getElementById('rules').innerHTML = json_data.rules;
document.getElementById('rules').style.display = 'none';
var ctx = document.getElementById('chart').getContext('2d');
window.chartObject = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Fails', 'Special success', 'Success on difficult', 'Normal success'],
datasets: [
{
borderColor: 'black',
data: [],
backgroundColor: ['rgb(190, 0, 0)', 'rgba(0, 190, 0, 0.7)', 'rgba(0, 160, 0, 0.8)', 'rgb(0, 120, 0)']
}]
},
options: {
scales: {
yAxes: [{
ticks: {
suggestedMin: 0,
suggestedMax: json_data.yaxes,
},
gridLines: {
display: false
},
ticks: {
display: false
}
}],
xAxes: [{
gridLines: {
display: false
},
ticks: {
display: false
}
}]
}
}
});
let over = [];
let special = [];
let difficult = [];
let normal = [];
for(var i in json_data.roll)
{
if(json_data.roll[i] > json_data.difficulty)
{
over.push(json_data.roll[i]);
}
else if(json_data.roll[i] <= json_data.difficulty/5)
{
special.push(json_data.roll[i]);
}
else if(json_data.roll[i] <= json_data.difficulty/2)
{
difficult.push(json_data.roll[i]);
}
else
{
normal.push(json_data.roll[i]);
}
}
window.chartObject.data.datasets[0].data.push(over.length, special.length, difficult.length, normal.length);
window.chartObject.update();
}
}
function showRules()
{
if(document.getElementById('rules').style.display === 'none')
{
document.getElementById('rules').style.display = 'block';
}
else
{
document.getElementById('rules').style.display = 'none';
}
}
</script>
</body>
</html>