-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmincraftOrigin.js
126 lines (105 loc) · 3.45 KB
/
mincraftOrigin.js
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
/* eslint-disable*/
const minecraftTime = {
ID: 'mcTime',
};
const realTime = {};
const timeUnit = {
seconds: 1,
minutes: 60,
hours: 3600,
days: 86400,
weeks: 604800,
months: 2628000,
years: 31556930,
};
const Timer = function (ID, time, timeUnit) {
this.ID = ID;
function setTime(timeType, timeLimit, timeInSecs) {
let setUnit = ~~((timeType % timeLimit) / timeInSecs); // Bitwise operation "~~" is used the same way as Math.floor
const zero = setUnit.toString().length;
if (zero < 2) {
setUnit = `0${setUnit}`;
}
return setUnit;
}
this.secs = setTime(timeUnit, timeUnit.minutes, timeUnit.seconds);
this.mins = setTime(timeUnit, timeUnit.hours, timeUnit.minutes);
this.hrs = setTime(timeUnit, timeUnit.days, timeUnit.hours);
this.formattedOutput = `${this.hrs} : ${this.mins} : ${this.secs}`;
this.setHTML = document.getElementById(
this.ID,
).innerHTML = this.formattedOutput;
this.reset = document.getElementById(this.ID).innerHTML = '00:00:00';
};
// var Timer = function(){
// startTimer
// StopTimer
// html ID
// Html Output
// }
// <------------------------------------------->
let dayNightTimer = null;
let dawn = false;
// Could this be turned into OOP?
function setTime(timeType, timeLimit, timeInSecs) {
let setUnit = ~~((timeType % timeLimit) / timeInSecs); // Bitwise operation "~~" is used the same way as Math.floor
const zero = setUnit.toString().length;
if (zero < 2) {
setUnit = `0${setUnit}`;
}
return setUnit;
}
function beginTimer() {
if (timerBtn.innerHTML == 'Start') {
console.log(timerBtn.innerHTML);
startTimer();
timerBtn.innerHTML = 'Reset';
} else if (timerBtn.innerHTML == 'Reset') {
console.log(timerBtn.innerHTML);
resetTimer();
timerBtn.innerHTML = 'Start';
}
}
function startTimer() {
const start = new Date().getTime();
if (dayNightTimer !== null) return;
dayNightTimer = window.setInterval(() => {
const time = new Date().getTime() - start;
if (dawn === true) {
console.log('Dawn');
console.log(start);
}
// Minecraft Time ** starts at 6 am**
// console.log(time);
const mcTime = Math.floor((time + 300000) / 100) / 10 * 72;
// mcTime = Math.floor(mcTime);
const secs = setTime(mcTime, timeUnit.minutes, timeUnit.seconds);
const mins = setTime(mcTime, timeUnit.hours, timeUnit.minutes);
const hrs = setTime(mcTime, timeUnit.days, timeUnit.hours);
document.getElementById('mcTime').innerHTML = `${hrs} : ${mins} : ${secs}`;
// Real Time
const realTime = Math.floor(time / 100) / 10;
const rsecs = setTime(realTime, timeUnit.minutes, timeUnit.seconds);
const rmins = setTime(realTime, timeUnit.hours, timeUnit.minutes);
const rhrs = setTime(realTime, timeUnit.days, timeUnit.hours);
document.getElementById(
'realTime',
).innerHTML = `${rhrs} : ${rmins} : ${rsecs}`;
dawn = false;
}, 100);
}
function resetTimer() {
clearInterval(dayNightTimer);
document.getElementById('mcTime').innerHTML = '00:00:00';
document.getElementById('realTime').innerHTML = '00:00:00';
dayNightTimer = null;
dawn = true;
}
const timerBtn = document.getElementById('timerBtn');
timerBtn.addEventListener('click', beginTimer, false);
/*
var startTimerBtn = document.getElementById("start");
startTimerBtn.addEventListener("click", startTimer, false);
var resetTimerBtn = document.getElementById("stop");
resetTimerBtn.addEventListener("click", resetTimer, false);
*/