-
Notifications
You must be signed in to change notification settings - Fork 0
/
layton.js
182 lines (142 loc) · 4.11 KB
/
layton.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
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
var hints = [false, false, false];
function openTab(hint, number){
hideTabContent();
if(hints[number-1]){
//show hint text
document.getElementById(hint).innerHTML = '<div class="unlocked bonus">' + hintText[number-1] + '</div>';
//remove class locked
document.getElementById(hint).classList.remove("locked");
//make it visible
document.getElementById(hint).style.display = "block";
} else {
//Tab locked, show unlock Prompt
document.getElementById(hint).innerHTML = `
<div id="locked${hint}" class="locked">
<p>Unlock a new Hint?</p>
<br style="clear: both;">
<div>
<button type="button" class="unlock ok" onclick="unlock()">Ok!</button>
<button type="button" class="unlock no" onclick="back()">No!</button>
</div>
</div>
`;
//add class locked
document.getElementById(hint).classList.add("locked");
//let "locked" take care of display
document.getElementById(hint).removeAttribute("style")
}
//Deactivate every Tablink
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++)
tablinks[i].className = tablinks[i].className.replace(" active", "");
//Activate tablink
tablink = document.getElementById("TabHint" + number);
tablink.className += " active";
}
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
function checkParams(){
//hide all tablinks
hideTabBar();
//hide code enter tab
codeRequest = document.getElementById("Code");
codeRequest.style.display = "none";
//hide back button
backButton = document.getElementById("back");
backButton.style.display = "none";
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
loadHints();
}
function codeKeyListener(e){
if(e.key == "Enter"){
loadHints();
}
}
function loadEnterCode(){
//show code input field
codeRequest = document.getElementById("Code");
codeRequest.style.display = "block";
codeRequest.addEventListener('keypress', codeKeyListener);
}
function hideEnterCode(){
codeRequest = document.getElementById("Code");
codeRequest.style.display = "none";
codeRequest.removeEventListener('keypress', codeKeyListener);
}
function setCode(){
urlParams.set("v", document.getElementById("setCode"));
loadHints();
}
function hideTabContent(){
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
}
function loadHints(){
//check for params
if(urlParams.has('v')){
code = urlParams.get("v");
urlParams.delete("v");
}
else
code = document.getElementById("codeField").value;
if(loadHintsByCode(code)){
showNextHintTab();
hideEnterCode();
showBackButton();
//Remove Code from CodePrompt
document.getElementById("codeField").value = "";
openTab('Hint1',1);
} else{
//Invalid Code
urlParams.delete("v");
loadEnterCode();
}
}
function showNextHintTab(){
for(i = 0; i < hints.length; i++){
if(!hints[i]){
//Name should be "locked"
tablinks = document.getElementsByClassName("tablinks");
tablinks[i].style.display= "block";
break;
}
}
}
function hideTabBar(){
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.display = "none";
}
}
function showBackButton(){
backButton = document.getElementById("back");
backButton.style.display = "block";
}
function back(){
resetSite();
}
function resetSite(){
hints = [false, false, false];
hintText = []
hideTabContent();
hideTabBar();
loadEnterCode();
}
function unlock(){
var i;
for(i = 0; i < hints.length; i++){
if(!hints[i]){
hints[i] = true;
break;
}
}
//change name from "locked" back to "Hint(i+1)"
showNextHintTab();
openTab("Hint" + (i+1), (i+1));
}