-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplatform_detail.js
More file actions
268 lines (235 loc) · 8.02 KB
/
Copy pathplatform_detail.js
File metadata and controls
268 lines (235 loc) · 8.02 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/**
* platform_detail.js
* Renders a single platform detail page.
* Depends on item_detail.js being loaded first.
*/
const SPEC_LABELS = {
cpu: "CPU",
graphics: "Graphics",
memory: "Memory",
storage: "Storage",
media: "Media",
connectivity: "Connectivity",
output: "Output",
resolutions: "Resolutions",
sound: "Sound",
os: "OS",
};
const CATEGORY_NAMES = {
1: "Console",
2: "Arcade",
3: "Platform",
4: "Operating System",
5: "Portable Console",
6: "Computer",
};
function getRegionFlag(regionName) {
const map = {
"europe": "🇪🇺",
"north_america": "🇺🇸",
"australia": "🇦🇺",
"new_zealand": "🇳🇿",
"japan": "🇯🇵",
"china": "🇨🇳",
"asia": "🌏",
"worldwide": "🌍",
"korea": "🇰🇷",
"brazil": "🇧🇷",
};
return map[regionName] || "🌐";
}
/**
* Render platform logo or placeholder
*/
function renderPlatformLogo(data) {
const logoEl = document.getElementById("platform-logo");
const logoPlaceholder = document.getElementById("platform-logo-placeholder");
const logoUrl = data.platform_logo?.url
? igdbImageUrl(data.platform_logo.url, "t_logo_med_2x")
: null;
if (logoUrl) {
logoEl.src = logoUrl;
logoEl.alt = data.name || "";
logoEl.style.display = "";
} else {
logoPlaceholder.style.display = null;
logoPlaceholder.style.removeProperty("display");
}
}
/**
* Render platform badges (category, generation)
*/
function renderPlatformBadges(data) {
const badgesEl = document.getElementById("platform-badges");
if (data.category !== undefined) {
badgesEl.appendChild(makeBadge(CATEGORY_NAMES[data.category] || `Category ${data.category}`, "bg-primary"));
}
if (data.generation !== undefined) {
badgesEl.appendChild(makeBadge(`Gen ${data.generation}`, "bg-secondary"));
}
}
/**
* Render platform metadata (games count, abbreviation, etc.)
*/
function renderPlatformMetadata(data) {
const metaDl = document.getElementById("platform-meta");
if (data.games && data.games.length > 0) {
addDlRow(metaDl, "Games", `${data.games.length} game${data.games.length === 1 ? '' : 's'}`);
}
if (data.abbreviation) {
addDlRow(metaDl, "Abbreviation", data.abbreviation);
}
if (data.alternative_name) {
addDlRow(metaDl, "Also Known As", data.alternative_name);
}
if (data.platform_type?.name) {
addDlRow(metaDl, "Type", data.platform_type.name);
}
}
/**
* Create accordion item for a platform version
*/
function createVersionAccordionItem(version, index) {
const itemId = `version-accordion-${index}`;
const headingId = `version-heading-${index}`;
const item = document.createElement("div");
item.className = "accordion-item rounded-0";
// Header
const header = document.createElement("h2");
header.className = "accordion-header";
header.id = headingId;
item.appendChild(header);
const button = document.createElement("button");
button.className = "accordion-button" + (index > 0 ? " collapsed" : "");
button.type = "button";
button.dataset.bsToggle = "collapse";
button.dataset.bsTarget = `#${itemId}`;
button.setAttribute("aria-expanded", index === 0 ? "true" : "false");
button.setAttribute("aria-controls", itemId);
button.textContent = version.name || `Version ${index + 1}`;
// Add logo next to version name if available
if (version.platform_logo?.url) {
const vLogo = document.createElement("img");
vLogo.src = igdbImageUrl(version.platform_logo.url, "t_thumb");
vLogo.alt = "";
vLogo.className = "me-2";
vLogo.style.height = "35px";
vLogo.style.objectFit = "contain";
button.prepend(vLogo);
}
header.appendChild(button);
// Collapse body
const collapseDiv = document.createElement("div");
collapseDiv.id = itemId;
collapseDiv.className = "accordion-collapse collapse" + (index === 0 ? " show" : "");
collapseDiv.setAttribute("aria-labelledby", headingId);
item.appendChild(collapseDiv);
const body = document.createElement("div");
body.className = "accordion-body";
collapseDiv.appendChild(body);
populateVersionBody(body, version);
return item;
}
/**
* Populate version accordion body with content
*/
function populateVersionBody(body, version) {
// Summary
if (version.summary) {
const p = document.createElement("p");
p.textContent = version.summary;
body.appendChild(p);
}
// Release dates
if (version.platform_version_release_dates && version.platform_version_release_dates.length > 0) {
const rdHeading = document.createElement("h6");
rdHeading.textContent = "Release Dates";
body.appendChild(rdHeading);
const rdList = document.createElement("ul");
rdList.className = "list-unstyled ms-2 mb-3";
version.platform_version_release_dates.forEach(rd => {
const li = document.createElement("li");
const regionName = rd.release_region?.region;
const flag = regionName ? getRegionFlag(regionName) : "🌐";
li.textContent = `${flag} ${rd.human || rd.y || ""}`;
rdList.appendChild(li);
});
body.appendChild(rdList);
}
// Specs
const specDl = document.createElement("dl");
specDl.className = "row mb-0";
let hasSpecs = false;
Object.entries(SPEC_LABELS).forEach(([key, label]) => {
if (version[key]) {
hasSpecs = true;
addDlRow(specDl, label, version[key]);
}
});
if (hasSpecs) {
const specHeading = document.createElement("h6");
specHeading.textContent = "Specifications";
body.appendChild(specHeading);
body.appendChild(specDl);
}
// IGDB link
if (version.url) {
const a = document.createElement("a");
a.href = version.url;
a.target = "_blank";
a.rel = "noopener";
a.className = "btn btn-outline-secondary btn-sm mt-2";
a.textContent = "View version on IGDB";
body.appendChild(a);
}
}
function renderPlatform(data) {
document.title = (data.name || "Platform") + " – GameDB";
document.getElementById("platform-name").textContent = data.name || "Unknown Platform";
renderPlatformLogo(data);
renderPlatformBadges(data);
renderPlatformMetadata(data);
// Summary
if (data.summary) {
const summarySection = document.getElementById("platform-summary-section");
summarySection.classList.remove("d-none");
document.getElementById("platform-summary").textContent = data.summary;
}
// Hardware Versions
if (data.versions && data.versions.length > 0) {
const section = document.getElementById("platform-versions-section");
section.classList.remove("d-none");
const accordion = document.getElementById("platform-versions");
data.versions.forEach((version, index) => {
accordion.appendChild(createVersionAccordionItem(version, index));
});
}
// Games on this platform
if (data.games && data.games.length > 0) {
const section = document.getElementById("platform-games-section");
section.classList.remove("d-none");
const container = document.getElementById("platform-games");
renderGameList(container, data.games);
}
// IGDB link
if (data.url) {
const igdbLink = document.getElementById("platform-igdb-link");
igdbLink.href = data.url;
igdbLink.classList.remove("d-none");
}
}
document.addEventListener("DOMContentLoaded", () => {
loadItemDetail("platforms", renderPlatform);
});
/* istanbul ignore next */
if (typeof module !== "undefined") {
module.exports = {
getRegionFlag,
renderPlatformLogo,
renderPlatformBadges,
renderPlatformMetadata,
createVersionAccordionItem,
populateVersionBody,
renderPlatform,
};
}