-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathirpg.html
200 lines (168 loc) · 4.49 KB
/
irpg.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
<!DOCTYPE html>
<html>
<head>
<title>IdleRPG</title>
<link rel="stylesheet" href="./assets/irpg.css" />
<link rel="stylesheet" href="./assets/style.css" />
</head>
<body>
<div class="content">
<h1 class="title">IdleRPG Status</h1>
<div id="users">
<h2>Users</h2>
<i>Updated every 5 minutes.</i>
<p>Thanks to Bag for the snazy user view
</div>
<script type="view" id="user-view">
<div class="user">
<span class="alignment">{alignment}</span>
<span class="level">{level}</span>
<div>
<h3>{username} ({cp})</h3>
<h4>{class}</h4>
</div>
</div>
</script>
</div>
<br >
<canvas width="1502" height="1502" id="canvas"></canvas>
<script type="text/javascript" language="javascript">
// Box width
var bw = 1500;
var width=50;
// Box height
var bh = 1500;
var height = 50;
// Padding
var p = 0;
var items = {
"a": "Mattt's Omniscience Grand Crown",
"b": "Juliet's Glorious Ring of Sparkliness",
"c": "Res0's Protectorate Plate Mail",
"d": "Dwyn's Storm Magic Amulet",
"e": "Drdink's Cane of Blind Rage",
"f": "Mrquick's Magical Boots of Swiftness",
"g": "Jeff's Cluehammer of Doom"
};
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var view = document.getElementById('user-view').innerHTML;
function renderUser(data)
{
var newView = ''+view;
for (let attr in data){
newView = newView.replace('{'+attr+'}', data[attr]);
}
return newView;
}
function render(data)
{
html = document.getElementById('users').innerHTML;
data.sort(function (a, b) {
let aL = parseInt(a['level']);
let bL = parseInt(b['level']);
if (aL == bL) {
return getUserCp(b) - getUserCp(a);
}
return bL - aL;
});
for(let user of data){
user.cp = getUserCp(user);
html += renderUser(user);
}
document.getElementById('users').innerHTML = html;
}
function getUserCp(user){
const stats = ['helm','tunic','amulet','gloves','ring','leggings','charm','boots','shield','weapon'];
let cp = 0;
for(let stat of stats){
cp += parseInt(user[stat]);
}
// alignment
if(user.alignment == 'e'){
cp = cp * 0.9; // -10%
}
if(user.alignment == 'g'){
cp = cp * 1.1; // +10%
}
return Math.round(cp,0);
}
var offsetX,offsetY;
function reOffset(){
var BB=canvas.getBoundingClientRect();
offsetX=BB.left;
offsetY=BB.top;
}
function drawBoard(){
for(var x = 0; x <= bw; x += (bw/width)) {
context.moveTo(0.5 + x + p, p);
context.lineTo(0.5 + x + p, bh + p);
}
for (var y = 0; y <= bh; y += (bh/height)) {
context.moveTo(p, 0.5 + y + p);
context.lineTo(bw + p, 0.5 + y + p);
}
context.strokeStyle = "black";
context.stroke();
}
shapes = []
function drawPlayer(s) {
context.beginPath();
context.arc(s.x, s.y, 8, 0, 2 * Math.PI, false);
context.fillStyle = 'black';
context.fill();
}
function getPlayerData(path) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
data = JSON.parse(xhr.responseText);
render(data);
for(var i = 0; i < data.length; i++) {
var s = {
name: data[i]['username'],
x: data[i]['x_pos'] * 3,
y: data[i]['y_pos'] * 3,
color: "black",
level: data[i]['level'],
quest: data[i]['on_quest']
}
shapes.push(s);
}
}
}
};
xhr.open("GET", path, true);
xhr.send();
}
function handleMouseMove(e){
mouseX=parseInt(e.clientX-offsetX);
mouseY=parseInt(e.clientY-offsetY);
// clear the canvas
context.clearRect(0,0,canvas.width,canvas.height);
context.fillStyle='black';
context.font="14px Times";
context.fillText("(" + parseInt(mouseX/3) + ", " + parseInt(mouseY/3) + ")",4,15);
for(var i=0;i<shapes.length;i++){
var s=shapes[i];
drawPlayer(s);
// is the mouse inside the defined shape
//if(context.isPointInPath(mouseX,mouseY,"evenodd")){
context.fillStyle='black';
context.font="18px Times";
context.fillText(s.name,s.x+10,s.y+10);
//}
}
drawBoard();
}
drawBoard();
document.addEventListener('mousemove', handleMouseMove, false);
document.addEventListener('scroll', reOffset, false);
document.addEventListener('resize', reOffset, false);
reOffset();
getPlayerData("https://graymalk.in/irpg.json");
</script>
</body>
</html>