-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
143 lines (129 loc) · 4.48 KB
/
main.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
let root = document.body
let fishlist = list
let collected_fish = new Set()
let sel_season = ""
let sel_weather = ""
let hide_collected = false
let include_any = true
function update_list() {
fishlist = list.filter(item => {
if (hide_collected) {
return !collected_fish.has(item.name)
}
return true
}).filter((item) => {
if (sel_season) {
return item.seasons.includes(sel_season) || (item.seasons.includes("Any season") && include_any)
}
return true
}).filter((item) => {
if (sel_weather) {
return item.weather === sel_weather || (item.weather === "Any weather" && include_any)
}
return true
})
}
function reset() {
sel_season = "";
sel_weather = "";
fishlist = list;
}
let seasonButton = {
view: (vnode) => {
return m("button", {onclick: () => {
if (sel_season === vnode.attrs.season) {
sel_season = ""
} else {
sel_season = vnode.attrs.season
}
update_list()
},
selected: sel_season === vnode.attrs.season,
}, vnode.attrs.season)
}
}
let weatherButton = {
view: (vnode) => {
return m("button", {onclick: () => {
if (sel_weather === vnode.attrs.weather) {
sel_weather = ""
} else {
sel_weather = vnode.attrs.weather
}
update_list()
},
selected: sel_weather === vnode.attrs.weather,
}, vnode.attrs.weather)
}
}
let controls = {
view: (vnode) => {
return m(".controls", [
m(".filter-group", [
m(seasonButton, {season: "Spring"}),
m(seasonButton, {season: "Summer"}),
m(seasonButton, {season: "Fall"}),
m(seasonButton, {season: "Winter"}),
]),
m(".filter-group", [
m(weatherButton, {weather: "Sunny"}),
m(weatherButton, {weather: "Rain"}),
]),
m("input", {type: "checkbox", checked: hide_collected, onclick: () => {
hide_collected = !hide_collected
update_list()
}}),
m("label", "hide collected"),
m("input", {type: "checkbox", checked: include_any, onclick: () => {
include_any = !include_any
update_list()
}}),
m("label", "include any when filtering"),
m("button.reset", {onclick: reset}, "reset filters"),
])
}
}
let infobox = {
view: (vnode) => {
return m(".fish-box", {checked: collected_fish.has(vnode.attrs.fish.name), onclick: (e) => {
if (collected_fish.has(vnode.attrs.fish.name)) {
collected_fish.delete(vnode.attrs.fish.name)
} else {
collected_fish.add(vnode.attrs.fish.name)
}
localStorage.setItem("collected_fish", JSON.stringify(Array.from(collected_fish)))
if (hide_collected) {
update_list()
}
}}, [
m("div.checkbox"),
m("img", {src: vnode.attrs.fish.img}),
m(".fish-name", vnode.attrs.fish.name),
m(".fish-time", vnode.attrs.fish.time),
m(".fish-seasons", vnode.attrs.fish.seasons.join(", ")),
m(".fish-location", vnode.attrs.fish.location),
m(".fish-weather", vnode.attrs.fish.weather),
])
}
}
let App = {
view: () => {
return [
m(controls),
m(".list", fishlist.map((obj) => {
return m(infobox, {fish: obj})
})),
m("p", "Images and info from ", m("a", {href: "https://stardewcommunitywiki.com/Stardew_Valley_Wiki"}, "the Stardew Valley Wiki"), ". All rights reserved."),
m("img", {src: "https://app.piratepx.com/ship?p=7e2e5912-9d50-48ee-888d-a51d91b45cd7"}),
]
}
}
window.onload = () => {
stored_coll_fish = window.localStorage.getItem("collected_fish")
if (stored_coll_fish) {
JSON.parse(window.localStorage.getItem("collected_fish")).forEach(element => {
collected_fish.add(element)
})
}
m.mount(root, App)
}