-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
192 lines (136 loc) · 5.82 KB
/
map.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
183
184
185
186
187
188
189
190
191
192
// Available places from where the player is
//remove this to make script work again
//let currentPlace = "cave"
import { start } from "./char.js"
let hour = start.HOUR
console.log(hour)
let allPlaces = ["fields", "cave", "hills", "shed", "coast", "forest"]
let availablePlaces = []
let unavailablePlaces = []
//checks if current place already exists in localstorage
onOpen()
function onOpen() {
if (localStorage.getItem("currentPlace") === null) {
let currentPlace = start.PLACE
updateMapSpot(currentPlace)
}
else {
let currentPlace = localStorage.getItem("currentPlace")
updateMapSpot(currentPlace)
}
}
//Hover to show text
document.getElementById("mapPointer").onmouseover = function () {
document.getElementById('mapText').innerHTML = "You are here"
}
document.getElementById("mapPointer").onmouseleave = function () {
document.getElementById('mapText').innerHTML = "Click on map to move to new location"
}
function updateMapSpot(currentPlace) {
switch (currentPlace) {
case "cave":
// saves spot in local storage
localStorage.setItem("currentPlace", currentPlace)
availablePlaces = ["hills", "shed", "fields", "forest"]
unavailablePlaces = allPlaces.filter(x => !availablePlaces.includes(x))
document.getElementById('mapPointer').style.marginTop = '80px'
document.getElementById('mapPointer').style.marginLeft = '220px'
for (let i = 0; i < unavailablePlaces.length; i++) {
document.getElementById(unavailablePlaces[i]).style.filter = 'none'
}
for (let j = 0; j < availablePlaces.length; j++) {
document.getElementById(availablePlaces[j]).style.filter = 'invert(100%)'
document.getElementById(availablePlaces[j]).onclick = function () {
updateMapSpot(this.id)
}
}
break;
case "coast":
// saves spot in local storage
localStorage.setItem("currentPlace", currentPlace)
availablePlaces = ["fields", "forest"]
unavailablePlaces = allPlaces.filter(x => !availablePlaces.includes(x))
document.getElementById('mapPointer').style.marginTop = '240px'
document.getElementById('mapPointer').style.marginLeft = '130px'
for (let i = 0; i < unavailablePlaces.length; i++) {
document.getElementById(unavailablePlaces[i]).style.filter = 'none'
}
for (let j = 0; j < availablePlaces.length; j++) {
document.getElementById(availablePlaces[j]).style.filter = 'invert(100%)'
document.getElementById(availablePlaces[j]).onclick = function () {
updateMapSpot(this.id)
}
}
break;
case "forest":
// saves spot in local storage
localStorage.setItem("currentPlace", currentPlace)
availablePlaces = ["fields", "cave", "coast"]
unavailablePlaces = allPlaces.filter(x => !availablePlaces.includes(x))
document.getElementById('mapPointer').style.marginTop = '140px'
document.getElementById('mapPointer').style.marginLeft = '130px'
for (let i = 0; i < unavailablePlaces.length; i++) {
document.getElementById(unavailablePlaces[i]).style.filter = 'none'
}
for (let j = 0; j < availablePlaces.length; j++) {
document.getElementById(availablePlaces[j]).style.filter = 'invert(100%)'
document.getElementById(availablePlaces[j]).onclick = function () {
updateMapSpot(this.id)
}
}
break;
case "fields":
// saves spot in local storage
localStorage.setItem("currentPlace", currentPlace)
availablePlaces = ["shed", "cave", "coast", "forest"]
unavailablePlaces = allPlaces.filter(x => !availablePlaces.includes(x))
document.getElementById('mapPointer').style.marginTop = '180px'
document.getElementById('mapPointer').style.marginLeft = '230px'
for (let i = 0; i < unavailablePlaces.length; i++) {
document.getElementById(unavailablePlaces[i]).style.filter = 'none'
}
for (let j = 0; j < availablePlaces.length; j++) {
document.getElementById(availablePlaces[j]).style.filter = 'invert(100%)'
document.getElementById(availablePlaces[j]).onclick = function () {
updateMapSpot(this.id)
}
}
break;
case "hills":
// saves spot in local storage
localStorage.setItem("currentPlace", currentPlace)
availablePlaces = ["shed", "cave"]
unavailablePlaces = allPlaces.filter(x => !availablePlaces.includes(x))
document.getElementById('mapPointer').style.marginTop = '10px'
document.getElementById('mapPointer').style.marginLeft = '290px'
for (let i = 0; i < unavailablePlaces.length; i++) {
document.getElementById(unavailablePlaces[i]).style.filter = 'none'
}
for (let j = 0; j < availablePlaces.length; j++) {
document.getElementById(availablePlaces[j]).style.filter = 'invert(100%)'
document.getElementById(availablePlaces[j]).onclick = function () {
updateMapSpot(this.id)
}
}
break;
case "shed":
// saves spot in local storage
localStorage.setItem("currentPlace", currentPlace)
availablePlaces = ["fields", "cave", "hills"]
unavailablePlaces = allPlaces.filter(x => !availablePlaces.includes(x))
document.getElementById('mapPointer').style.marginTop = '120px'
document.getElementById('mapPointer').style.marginLeft = '340px'
for (let i = 0; i < unavailablePlaces.length; i++) {
document.getElementById(unavailablePlaces[i]).style.filter = 'none'
}
for (let j = 0; j < availablePlaces.length; j++) {
document.getElementById(availablePlaces[j]).style.filter = 'invert(100%)'
document.getElementById(availablePlaces[j]).onclick = function () {
updateMapSpot(this.id)
}
}
break;
default:
availablePlaces = ["fields", "cave", "hills"]
}
}