-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
47 lines (43 loc) · 1.69 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wandering Journey</title>
<link rel="icon" href="src/img/logo.png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div id="elm-app-is-loaded-here"></div>
<script src="wanderingJourney.js"></script>
<script>
//Local Storage info: https://stackoverflow.com/questions/33697444/local-storage-or-other-data-persistence-in-elm
let storageKey = "wanderingJourneyPlayerData"
let storageData = localStorage.getItem(storageKey)
if(storageData == null) storageData = "" //If there is null data, turn it to an empty string
let data = [null, null, null]
$.getJSON('cards.json').done(function(cardJson){
data[0] = cardJson
checkIfReceivedAll()
})
$.getJSON('items.json').done(function(itemJson){
data[1] = itemJson
checkIfReceivedAll()
})
$.getJSON('achievements.json').done(function(achievementJson){
data[2] = achievementJson
checkIfReceivedAll()
})
function checkIfReceivedAll(){
if (data.filter(e => e != null).length >= 3){
const app = Elm.Main.init({
flags: [JSON.stringify(data[0]).slice(0,-1)+","+JSON.stringify(data[1]).substr(1).slice(0,-1)+","+JSON.stringify(data[2]).substr(1),storageData], //guide.elm-lang.org/interop/flags.html, also added both jsons into one
node: document.getElementById('elm-app-is-loaded-here')
});
app.ports.savePlayerData.subscribe(function(value) {
localStorage.setItem(storageKey, JSON.stringify(value));
});
}
}
</script>
</body>
</html>