Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ app.post('/create',async function(req,res) {
while(rooms[code]) {
code = Math.floor(100000 + Math.random() * 900000).toString();
}
rooms[code] = {t1: data.time, t2: data.time, m1: true, p: true, t: 0};
let buffer = parseInt(data.buffer) || 0
rooms[code] = {t1: data.time,
t2: data.time,
buffer: buffer,
activeBuffer: buffer,
increment: parseInt(data.increment) || 0,
m1: true,
p: true,
t: 0
};

res.send(code);
} catch(e) {
Expand Down Expand Up @@ -66,8 +75,16 @@ app.post('/switch',async function(req, res) {
}
var room = rooms[data.code];
if(data.s == 0) {
//apply increment
if (room.m1) {
room.t1 += room.increment;
} else {
room.t2 += room.increment;
}
//switch
room.m1 = !room.m1;
//reset buffer TODO: (Should this also happen on unpause?)
room.activeBuffer = room.buffer;
} else if(data.s == 1) {
//pause
room.p = false;
Expand All @@ -81,6 +98,13 @@ app.post('/switch',async function(req, res) {
//reduce room timer value
function roomTick(delta, room) {
if(room.p) return;
if (room.activeBuffer > 0) {
room.activeBuffer -= delta;
delta = -1* room.activeBuffer;
if (delta < 0) {
return;
}
}
if(room.m1 && room.t1 > 0) {
room.t1 -= delta;
} else if(room.t2 > 0) {
Expand Down
85 changes: 46 additions & 39 deletions index.html → client/index.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Chess Timer Online</title>
<style>
body {
font-size: 300%;
text-align: center;
}
button {
font-size: 120%;
}
input {
font-size: 120%;
}
</style>
</head>
<body>
<div id="joinDiv">
<h1>Chess Timer Online</h1>
<input id="code" placeholder="Code"/>
<button id="join" onclick="join()">Join</button>
<br/>
<br/>
<input id="time" placeholder="Time (Minutes)"/>
<button id="create" onclick="create()">Create</button>
</div>
<div id="roomDiv" style="display:none">
<h3 id="codeH"></h3>
<br/>
<button id="switchButton" onclick="swap()">Switch</button>
<button id="pauseButton" onclick="pause()">Start/Stop</button>
<h1 id="t1" style="color:blue"></h1>
<br/>
<h1 id="t2" style="color:green"></h1>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="./client/js/index.js"></script>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Chess Timer Online</title>
<style>
body {
font-size: 300%;
text-align: center;
}
button {
font-size: 120%;
}
input {
font-size: 120%;
}
</style>
</head>
<body>
<div id="joinDiv">
<h1>Chess Timer Online</h1>
<input id="code" placeholder="Code" size=15/>
<button id="join" onclick="join()">Join</button>
<br/>
<br/>
<input id="time" placeholder="Time (Minutes)" size=15/>
<button id="create" onclick="create()">Create</button>
<div id="timeSettings" style="padding-top: 50px">
<strong>Advanced Time Settings</strong>
<div id="row">
<input id="timeBuffer" placeholder="Buffer (Seconds)" size=15/>
<input id="timeIncrement" placeholder="Increment (Seconds)" size=15/>
</div>
</div>
</div>
<div id="roomDiv" style="display:none">
<h3 id="codeH"></h3>
<br/>
<button id="switchButton" onclick="swap()">Switch</button>
<button id="pauseButton" onclick="pause()">Start/Stop</button>
<h1 id="t1" style="color:blue"></h1>
<br/>
<h1 id="t2" style="color:green"></h1>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="./client/js/index.js"></script>
</body>
</html>
Loading