@@ -107,7 +107,7 @@ class HomebrewGamesApp {
107107 this . currentPage = 'home' ;
108108 document . getElementById ( 'home-page' ) . classList . add ( 'active' ) ;
109109 document . getElementById ( 'games-page' ) . classList . remove ( 'active' ) ;
110- document . title = 'Homebrew Games Archive ' ;
110+ document . title = 'Homebrew Games' ;
111111 }
112112
113113 showGamesPage ( system , status ) {
@@ -299,12 +299,116 @@ class HomebrewGamesApp {
299299 this . loadMoreGames ( ) ;
300300 }
301301 }
302- }
303302
304- // Initialize the app when DOM is loaded
305- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
306- new HomebrewGamesApp ( ) ;
307- } ) ;
303+ // Settings management
304+ loadSettings ( ) {
305+ this . currentLanguage = localStorage . getItem ( 'language' ) || 'en' ;
306+ this . currentTheme = localStorage . getItem ( 'theme' ) || 'dark' ;
307+ }
308+
309+ saveSettings ( ) {
310+ localStorage . setItem ( 'language' , this . currentLanguage ) ;
311+ localStorage . setItem ( 'theme' , this . currentTheme ) ;
312+ }
313+
314+ // Translation functionality
315+ async loadTranslations ( ) {
316+ try {
317+ const response = await fetch ( `translations/${ this . currentLanguage } .json` ) ;
318+ if ( ! response . ok ) throw new Error ( 'Failed to load translations' ) ;
319+ this . translations = await response . json ( ) ;
320+ } catch ( error ) {
321+ console . error ( 'Error loading translations:' , error ) ;
322+ // Fallback to English if current language fails
323+ if ( this . currentLanguage !== 'en' ) {
324+ try {
325+ const fallbackResponse = await fetch ( 'translations/en.json' ) ;
326+ this . translations = await fallbackResponse . json ( ) ;
327+ } catch ( fallbackError ) {
328+ console . error ( 'Error loading fallback translations:' , fallbackError ) ;
329+ this . translations = { } ;
330+ }
331+ }
332+ }
333+ }
334+
335+ async changeLanguage ( lang ) {
336+ if ( lang === this . currentLanguage ) return ;
337+
338+ this . currentLanguage = lang ;
339+ this . saveSettings ( ) ;
340+
341+ // Update language button states
342+ document . querySelectorAll ( '.lang-btn' ) . forEach ( btn => {
343+ btn . classList . toggle ( 'active' , btn . getAttribute ( 'data-lang' ) === lang ) ;
344+ } ) ;
345+
346+ // Load new translations
347+ await this . loadTranslations ( ) ;
348+ this . updateLanguage ( ) ;
349+ }
350+
351+ updateLanguage ( ) {
352+ // Update all elements with data-translate attribute
353+ document . querySelectorAll ( '[data-translate]' ) . forEach ( element => {
354+ const key = element . getAttribute ( 'data-translate' ) ;
355+ if ( this . translations [ key ] ) {
356+ element . textContent = this . translations [ key ] ;
357+ }
358+ } ) ;
359+
360+ // Update dynamic content
361+ this . updateDynamicTranslations ( ) ;
362+ }
363+
364+ updateDynamicTranslations ( ) {
365+ // Update loading text
366+ const loadingElement = document . querySelector ( '#loading p' ) ;
367+ if ( loadingElement && this . translations [ 'loading-text' ] ) {
368+ loadingElement . textContent = this . translations [ 'loading-text' ] ;
369+ }
370+
371+ // Update no more games text
372+ const noMoreGamesElement = document . querySelector ( '#no-more-games p' ) ;
373+ if ( noMoreGamesElement && this . translations [ 'no-more-games' ] ) {
374+ noMoreGamesElement . textContent = this . translations [ 'no-more-games' ] ;
375+ }
376+
377+ // Update all dropdown links
378+ document . querySelectorAll ( '.dropdown-link' ) . forEach ( link => {
379+ const href = link . getAttribute ( 'href' ) ;
380+ if ( href . includes ( '/new-games' ) ) {
381+ link . textContent = this . translations [ 'nav-new-games' ] || 'New Games' ;
382+ } else if ( href . includes ( '/ports' ) ) {
383+ link . textContent = this . translations [ 'nav-ports' ] || 'Ports' ;
384+ } else if ( href . includes ( '/re-releases' ) ) {
385+ link . textContent = this . translations [ 'nav-re-releases' ] || 'Re-Releases' ;
386+ } else if ( href . includes ( '/in-development' ) ) {
387+ link . textContent = this . translations [ 'nav-in-development' ] || 'In Development' ;
388+ }
389+ } ) ;
390+ }
391+
392+ // Theme functionality
393+ toggleTheme ( ) {
394+ this . currentTheme = this . currentTheme === 'dark' ? 'light' : 'dark' ;
395+ this . saveSettings ( ) ;
396+ this . updateTheme ( ) ;
397+ }
398+
399+ updateTheme ( ) {
400+ const body = document . body ;
401+ const themeIcon = document . querySelector ( '.theme-icon' ) ;
402+
403+ if ( this . currentTheme === 'light' ) {
404+ body . setAttribute ( 'data-theme' , 'light' ) ;
405+ if ( themeIcon ) themeIcon . textContent = '☀️' ;
406+ } else {
407+ body . removeAttribute ( 'data-theme' ) ;
408+ if ( themeIcon ) themeIcon . textContent = '🌙' ;
409+ }
410+ }
411+ }
308412
309413// GitHub API integration (for future use)
310414class GitHubDataManager {
@@ -353,114 +457,5 @@ document.addEventListener('DOMContentLoaded', () => {
353457 new HomebrewGamesApp ( ) ;
354458} ) ;
355459
356- // Homebrew Games App - Additional methods
357- HomebrewGamesApp . prototype . loadSettings = function ( ) {
358- this . currentLanguage = localStorage . getItem ( 'language' ) || 'en' ;
359- this . currentTheme = localStorage . getItem ( 'theme' ) || 'dark' ;
360- } ;
361-
362- HomebrewGamesApp . prototype . saveSettings = function ( ) {
363- localStorage . setItem ( 'language' , this . currentLanguage ) ;
364- localStorage . setItem ( 'theme' , this . currentTheme ) ;
365- } ;
366-
367- HomebrewGamesApp . prototype . loadTranslations = async function ( ) {
368- try {
369- const response = await fetch ( `translations/${ this . currentLanguage } .json` ) ;
370- if ( ! response . ok ) throw new Error ( 'Failed to load translations' ) ;
371- this . translations = await response . json ( ) ;
372- } catch ( error ) {
373- console . error ( 'Error loading translations:' , error ) ;
374- // Fallback to English if current language fails
375- if ( this . currentLanguage !== 'en' ) {
376- try {
377- const fallbackResponse = await fetch ( 'translations/en.json' ) ;
378- this . translations = await fallbackResponse . json ( ) ;
379- } catch ( fallbackError ) {
380- console . error ( 'Error loading fallback translations:' , fallbackError ) ;
381- this . translations = { } ;
382- }
383- }
384- }
385- } ;
386-
387- HomebrewGamesApp . prototype . changeLanguage = async function ( lang ) {
388- if ( lang === this . currentLanguage ) return ;
389-
390- this . currentLanguage = lang ;
391- this . saveSettings ( ) ;
392-
393- // Update language button states
394- document . querySelectorAll ( '.lang-btn' ) . forEach ( btn => {
395- btn . classList . toggle ( 'active' , btn . getAttribute ( 'data-lang' ) === lang ) ;
396- } ) ;
397-
398- // Load new translations
399- await this . loadTranslations ( ) ;
400- this . updateLanguage ( ) ;
401- } ;
402-
403- HomebrewGamesApp . prototype . updateLanguage = function ( ) {
404- // Update all elements with data-translate attribute
405- document . querySelectorAll ( '[data-translate]' ) . forEach ( element => {
406- const key = element . getAttribute ( 'data-translate' ) ;
407- if ( this . translations [ key ] ) {
408- element . textContent = this . translations [ key ] ;
409- }
410- } ) ;
411-
412- // Update dynamic content
413- this . updateDynamicTranslations ( ) ;
414- } ;
415-
416- HomebrewGamesApp . prototype . updateDynamicTranslations = function ( ) {
417- // Update loading text
418- const loadingElement = document . querySelector ( '#loading p' ) ;
419- if ( loadingElement && this . translations [ 'loading-text' ] ) {
420- loadingElement . textContent = this . translations [ 'loading-text' ] ;
421- }
422-
423- // Update no more games text
424- const noMoreGamesElement = document . querySelector ( '#no-more-games p' ) ;
425- if ( noMoreGamesElement && this . translations [ 'no-more-games' ] ) {
426- noMoreGamesElement . textContent = this . translations [ 'no-more-games' ] ;
427- }
428-
429- // Update all dropdown links
430- document . querySelectorAll ( '.dropdown-link' ) . forEach ( link => {
431- const href = link . getAttribute ( 'href' ) ;
432- if ( href . includes ( '/new-games' ) ) {
433- link . textContent = this . translations [ 'nav-new-games' ] || 'New Games' ;
434- } else if ( href . includes ( '/ports' ) ) {
435- link . textContent = this . translations [ 'nav-ports' ] || 'Ports' ;
436- } else if ( href . includes ( '/re-releases' ) ) {
437- link . textContent = this . translations [ 'nav-re-releases' ] || 'Re-Releases' ;
438- } else if ( href . includes ( '/in-development' ) ) {
439- link . textContent = this . translations [ 'nav-in-development' ] || 'In Development' ;
440- }
441- } ) ;
442- } ;
443-
444- HomebrewGamesApp . prototype . toggleTheme = function ( ) {
445- this . currentTheme = this . currentTheme === 'dark' ? 'light' : 'dark' ;
446- this . saveSettings ( ) ;
447- this . updateTheme ( ) ;
448- } ;
449-
450- HomebrewGamesApp . prototype . updateTheme = function ( ) {
451- const body = document . body ;
452- const themeIcon = document . querySelector ( '.theme-icon' ) ;
453-
454- if ( this . currentTheme === 'light' ) {
455- body . setAttribute ( 'data-theme' , 'light' ) ;
456- themeIcon . textContent = '☀️' ;
457- } else {
458- body . removeAttribute ( 'data-theme' ) ;
459- themeIcon . textContent = '🌙' ;
460- }
461- } ;
462-
463- }
464-
465460// Export for potential use in other modules
466- window . GitHubDataManager = GitHubDataManager ;
461+ window . GitHubDataManager = GitHubDataManager ;
0 commit comments