|
23 | 23 | commercialOnly: false, |
24 | 24 | noAttr: false, |
25 | 25 | perspective: "any", |
| 26 | + license: "any", |
| 27 | + format: "any", |
26 | 28 | sort: "name", |
27 | 29 | }; |
28 | 30 | const state = { ...DEFAULTS }; |
| 31 | + // Licence families and format groups come from the build (license-vocabulary.json, format-vocabulary.json). |
| 32 | + const LICENSE_FAMILIES = data.filters?.licenseFamilies || {}; |
| 33 | + const FORMAT_GROUPS = data.filters?.formatGroups || {}; |
29 | 34 |
|
30 | 35 | const categoryLabels = data.categories || {}; |
31 | 36 | const repo = data.site?.repo || "https://github.com/TMHSDigital/Free-Game-Dev-Assets"; |
|
116 | 121 | pick("cat", "category", ["all", ...Object.keys(categoryLabels)]); |
117 | 122 | pick("sort", "sort", Object.keys(SORTS)); |
118 | 123 | pick("view", "perspective", ["any", ...Object.keys(PERSPECTIVE_LABELS)]); |
| 124 | + pick("licence", "license", ["any", ...Object.keys(LICENSE_FAMILIES)]); |
| 125 | + pick("format", "format", ["any", ...Object.keys(FORMAT_GROUPS)]); |
119 | 126 | if (p.has("q")) state.q = p.get("q"); |
120 | 127 | const bool = (key, field) => { |
121 | 128 | const v = p.get(key); |
|
136 | 143 | if (state.q.trim()) p.set("q", state.q.trim()); |
137 | 144 | if (state.sort !== DEFAULTS.sort) p.set("sort", state.sort); |
138 | 145 | if (state.perspective !== DEFAULTS.perspective) p.set("view", state.perspective); |
| 146 | + if (state.license !== DEFAULTS.license) p.set("licence", state.license); |
| 147 | + if (state.format !== DEFAULTS.format) p.set("format", state.format); |
139 | 148 | const bool = (key, field) => { |
140 | 149 | if (state[field] !== DEFAULTS[field]) p.set(key, state[field] ? "1" : "0"); |
141 | 150 | }; |
|
168 | 177 | if (state.noAttr && entry.attribution_required !== false) return false; |
169 | 178 | if (state.perspective !== "any" && entry.camera_perspective !== state.perspective) |
170 | 179 | return false; |
| 180 | + if (state.license !== "any" && entry.licenseFamily !== state.license) return false; |
| 181 | + if (state.format !== "any") { |
| 182 | + const wanted = FORMAT_GROUPS[state.format]?.formats || []; |
| 183 | + if (!(entry.formats || []).some((f) => wanted.includes(f))) return false; |
| 184 | + } |
171 | 185 | return true; |
172 | 186 | } |
173 | 187 |
|
|
385 | 399 | key: "perspective", |
386 | 400 | label: `view: ${PERSPECTIVE_LABELS[state.perspective] || state.perspective}`, |
387 | 401 | }); |
| 402 | + if (state.license !== DEFAULTS.license) |
| 403 | + chips.push({ key: "license", label: `licence: ${LICENSE_FAMILIES[state.license] || state.license}` }); |
| 404 | + if (state.format !== DEFAULTS.format) |
| 405 | + chips.push({ key: "format", label: `format: ${FORMAT_GROUPS[state.format]?.label || state.format}` }); |
388 | 406 | if (!state.active) chips.push({ key: "active", label: "hiding active" }); |
389 | 407 | if (!state.review) chips.push({ key: "review", label: "hiding needs-review" }); |
390 | 408 | if (state.deprecated) chips.push({ key: "deprecated", label: "showing deprecated" }); |
|
683 | 701 | apply(); |
684 | 702 | }); |
685 | 703 |
|
| 704 | + const selects = [ |
| 705 | + ["#license-family", "license", LICENSE_FAMILIES], |
| 706 | + ["#format-group", "format", Object.fromEntries(Object.entries(FORMAT_GROUPS).map(([k, g]) => [k, g.label]))], |
| 707 | + ]; |
| 708 | + for (const [sel, field, choices] of selects) { |
| 709 | + const el = $(sel); |
| 710 | + el.insertAdjacentHTML( |
| 711 | + "beforeend", |
| 712 | + Object.entries(choices) |
| 713 | + .map(([value, label]) => `<option value="${escapeHtml(value)}">${escapeHtml(label)}</option>`) |
| 714 | + .join("") |
| 715 | + ); |
| 716 | + el.value = state[field]; |
| 717 | + el.addEventListener("change", (e) => { |
| 718 | + state[field] = e.target.value; |
| 719 | + apply(); |
| 720 | + }); |
| 721 | + } |
| 722 | + |
686 | 723 | const sort = $("#sort"); |
687 | 724 | sort.value = state.sort; |
688 | 725 | sort.addEventListener("change", (e) => { |
|
789 | 826 | $("#filter-no-attr").checked = state.noAttr; |
790 | 827 | $("#sort").value = state.sort; |
791 | 828 | $("#perspective").value = state.perspective; |
| 829 | + $("#license-family").value = state.license; |
| 830 | + $("#format-group").value = state.format; |
792 | 831 | } |
793 | 832 |
|
794 | 833 | /* --------------------------------------------------------------- init */ |
|
0 commit comments