forked from rslashplace2/rslashplace2.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
quests.js
77 lines (75 loc) · 2.54 KB
/
quests.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
/* eslint-disable jsdoc/require-jsdoc */
/* eslint-disable @typescript-eslint/no-this-alias */
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
// Contains routines for user exploration
let quests = null
const stages = {
// generic
notStarted: 0,
// seeCommunityPosts
closebtnClicked: 1,
postJumpButtonClicked: 2
}
if (!localStorage.quests) {
const DEFAULT_QUESTS = {
seeCommunityPosts: { stage: stages.notStarted }
}
quests = DEFAULT_QUESTS
localStorage.quests = JSON.stringify(quests)
}
else {
quests = JSON.parse(localStorage.quests)
}
function syncLocalStorage(target) {
const handler = {
get(obj, prop) {
if (typeof obj[prop] === "object" && obj[prop] !== null) {
return new Proxy(obj[prop], handler)
}
return obj[prop]
},
set(obj, key, value) {
obj[key] = value
localStorage.quests = JSON.stringify(quests)
return true
}
}
return new Proxy(target, handler)
}
quests = syncLocalStorage(quests)
if (quests.seeCommunityPosts.stage <= stages.notStarted) {
closebtn.classList.add("please-click")
const closeClicked = () => {
closebtn.classList.remove("please-click")
quests.seeCommunityPosts.stage = stages.closebtnClicked
AUDIOS.bell.run()
confetti({
particleCount: 100,
spread: 70,
origin: { y: 0.6 },
})
closebtn.removeEventListener("click", closeClicked)
}
closebtn.addEventListener("click", closeClicked)
}
if (quests.seeCommunityPosts.stage <= stages.closebtnClicked) {
postsFrame.addEventListener("load", function(e) {
const postJumpButton = postsFrame.contentDocument.querySelector("#postJumpButton")
postJumpButton.classList.add("please-click")
const postJumpClicked = () => {
postJumpButton.classList.remove("please-click")
quests.seeCommunityPosts.stage = stages.postJumpButtonClicked
AUDIOS.celebration.run()
confetti({
particleCount: 100,
spread: 100,
origin: { y: 0.6 },
})
questsDescription.textContent = "You have visited the community posts menu. Here you share canvas arts, make public announcements and chat with the community!"
questsDialog.showModal()
postJumpButton.removeEventListener("click", postJumpClicked)
}
postJumpButton.addEventListener("click", postJumpClicked)
})
}