2019-01-08 19:45:57 +01:00
// Download latest version
2023-04-10 01:31:45 +02:00
fetch ( "https://api.github.com/repos/cemu-project/cemu_graphic_packs/releases/latest" ) . then ( fetchRes => fetchRes . json ( ) ) . then ( fetchJson => {
2019-01-08 19:45:57 +01:00
console . debug ( "Fetched releases from github..." ) ;
document . getElementById ( "primary_download" ) . href = fetchJson . assets [ 0 ] . browser _download _url ;
return ;
} ) . catch ( fetchErr => {
console . error ( "Seems like something isn't working..." , fetchErr ) ;
} ) ;
// Search Supported Games
var supportedGames = undefined ;
var supportedGamesSearchSet = undefined ;
var supportedGamesSearchSetHalfTitles = { } ;
const altNames = {
"botw" : "The Legend of Zelda: Breath of the Wild" ,
"hw" : "Hyrule Warriors" ,
2020-01-10 01:39:20 +01:00
"mc" : "Minecraft" ,
"slw" : "Sonic Lost World" ,
2021-04-02 03:12:00 +02:00
"smm" : "Super Mario Maker" ,
"mk8" : "Mario Kart 8" ,
2019-01-08 19:45:57 +01:00
"tphd" : "The Legend of Zelda: Twilight Princess HD" ,
"wwhd" : "The Legend of Zelda: The Wind Waker HD" ,
2020-01-10 01:39:20 +01:00
// easter eggs
2021-04-25 07:15:23 +02:00
"zemu" : "The Legend of Zelda: Breath of the Wild" ,
2020-01-10 01:39:20 +01:00
"breath of the dicknut" : "The Legend of Zelda: Breath of the Wild" ,
"f-zero" : "FAST Racing NEO" ,
"m&m" : "Sonic" ,
2021-04-02 03:10:28 +02:00
"michael" : "Sonic" ,
2020-01-10 01:39:20 +01:00
"best game" : "Meme Run"
2019-01-08 19:45:57 +01:00
} ;
async function searchSupportedGames ( searchString ) {
document . getElementById ( "supported-games-search" ) . classList . add ( "loading" ) ;
document . getElementById ( "supported-games-search-results" ) . innerHTML = "" ;
if ( ! supportedGames ) {
supportedGames = true ;
2019-01-08 21:13:49 +01:00
await fetch ( ( window . location . origin + window . location . pathname ) + "/supported_titles.json" , { cache : "no-store" } ) . then ( fetchRes => fetchRes . json ( ) ) . then ( fetchJson => {
2019-01-08 19:45:57 +01:00
console . debug ( "Fetched supported titles from '/supported_titles.json'." ) ;
supportedGames = fetchJson ;
supportedGamesSearchSet = FuzzySet ( [ ] , false , 2 , 3 ) ;
for ( supportedGame in supportedGames ) {
supportedGamesSearchSet . add ( supportedGame ) ;
}
return ;
} ) . catch ( fetchErr => {
console . error ( "Seems like something bad happened!" , fetchErr ) ;
} ) ;
}
if ( supportedGames === true ) return ; // Fix race errors with input
2019-05-04 17:36:19 +02:00
let resultsHintSearch = [ ] ;
2019-01-08 19:45:57 +01:00
if ( Object . keys ( altNames ) . includes ( searchString . toLowerCase ( ) ) ) searchString = altNames [ searchString . toLowerCase ( ) ] ;
2021-04-25 07:15:23 +02:00
switch ( searchString . toLowerCase ( ) ) {
2021-04-25 08:30:14 +02:00
case "digital foundry" : {
2021-04-25 07:15:23 +02:00
document . title = "Home - CEMU Hacks" ;
document . getElementsByClassName ( "navbar-brand" ) [ 0 ] . innerText = "CEMU Hacks" ;
document . getElementsByClassName ( "display-4" ) [ 0 ] . innerText = "CEMU Hacks" ;
document . getElementsByClassName ( "lead" ) [ 0 ] . innerText = "Get your online CEMU hax here!!" ;
2021-04-30 14:50:28 +02:00
break ;
2021-04-25 08:30:14 +02:00
}
case "ign" : {
2021-04-25 07:15:23 +02:00
// IGN based for calling it community built presets & plugins instead of hacks
document . title = "Home - Cemu Plugins" ;
document . getElementsByClassName ( "navbar-brand" ) [ 0 ] . innerText = "Cemu Plugins" ;
document . getElementsByClassName ( "display-4" ) [ 0 ] . innerText = "Cemu Plugins" ;
2021-04-30 14:50:28 +02:00
break ;
2021-04-25 08:30:14 +02:00
}
2020-01-10 01:39:20 +01:00
}
2019-05-04 17:36:19 +02:00
if ( searchString != "*" ) resultsHintSearch = supportedGamesSearchSet . get ( searchString ) ;
else {
for ( supportedGame in supportedGames ) {
resultsHintSearch . push ( [ 0 , supportedGame ] ) ;
}
}
2019-01-08 19:45:57 +01:00
if ( resultsHintSearch != undefined && resultsHintSearch != null ) {
for ( let i = 0 ; i < resultsHintSearch . length ; i ++ ) {
let currResult = resultsHintSearch [ i ] [ 1 ] ;
let searchResultEntry = document . createElement ( "li" ) ;
let gameTitleText = document . createTextNode ( currResult ) ;
let versionBadge = document . createElement ( "span" ) ;
2019-05-04 17:36:19 +02:00
let versionBadgeText ;
2020-01-10 04:33:10 +01:00
if ( supportedGames [ currResult ] . version == 4 ) versionBadgeText = document . createTextNode ( "Fully supports OpenGL and Vulkan" ) ;
else if ( supportedGames [ currResult ] . version == 3 ) versionBadgeText = document . createTextNode ( "Fully supports OpenGL" ) ;
2020-01-10 01:39:20 +01:00
else if ( supportedGames [ currResult ] . version == 2 ) versionBadgeText = document . createTextNode ( "Only supported on 1.8.0 through 1.13.2" ) ;
2019-05-04 17:36:19 +02:00
else versionBadgeText = document . createTextNode ( "No resolution pack yet :(" ) ;
2019-01-08 19:45:57 +01:00
let resolutionBadge = document . createElement ( "span" ) ;
let resolutionBadgeText = document . createTextNode ( supportedGames [ currResult ] . nativeRes + "p" ) ;
searchResultEntry . className = "list-group-item list-group-item-action" ;
versionBadge . className = "badge badge-light ml-2" ;
resolutionBadge . className = "badge badge-pill badge-primary float-right" ;
searchResultEntry . onclick = searchInfoModalTrigger
2020-01-10 01:39:20 +01:00
if ( supportedGames [ currResult ] . version === 4 ) {
searchResultEntry . classList . add ( "list-group-item-danger" ) ;
}
else if ( supportedGames [ currResult ] . version === 3 ) {
searchResultEntry . classList . add ( "list-group-item-primary" ) ;
}
else {
searchResultEntry . classList . add ( "list-group-item-secondary" ) ;
}
2019-01-08 19:45:57 +01:00
searchResultEntry . appendChild ( gameTitleText ) ;
versionBadge . appendChild ( versionBadgeText ) ;
searchResultEntry . appendChild ( versionBadge ) ;
resolutionBadge . appendChild ( resolutionBadgeText ) ;
searchResultEntry . appendChild ( resolutionBadge ) ;
document . getElementById ( "supported-games-search-results" ) . appendChild ( searchResultEntry ) ;
}
}
document . getElementById ( "supported-games-search" ) . classList . remove ( "loading" ) ;
}
async function searchInfoModalTrigger ( clickedElem ) {
$ ( "#searchInfoModal" ) . modal ( ) ; // Initiate animation
let clickedGame = clickedElem . target . firstChild . textContent ;
// Reset Compat Information
2020-01-10 01:39:20 +01:00
document . getElementById ( "modal-preview-image" ) . src = "assets/images/no-cover-available.png" ;
2019-01-08 19:45:57 +01:00
document . getElementById ( "information-box" ) . className = "compat-status-loading" ;
document . getElementById ( "gameTitle" ) . innerText = clickedGame ;
document . getElementById ( "compatWikiButton" ) . href = supportedGames [ clickedGame ] . compatLink ;
document . getElementById ( "nativeResolution" ) . textContent = supportedGames [ clickedGame ] . nativeRes ;
2020-01-10 01:39:20 +01:00
if ( supportedGames [ clickedGame ] . version == 4 ) document . getElementById ( "information-box" ) . classList . add ( "version-4-supported" ) ;
else if ( supportedGames [ clickedGame ] . version == 3 ) document . getElementById ( "information-box" ) . classList . add ( "version-3-supported" ) ;
else if ( supportedGames [ clickedGame ] . version == 2 ) document . getElementById ( "information-box" ) . classList . add ( "version-2-supported" ) ;
2019-01-08 19:45:57 +01:00
document . getElementById ( "information-box" ) . classList . add ( supportedGames [ clickedGame ] . hasUltrawide ? "ultrawide-supported" : "ultrawide-unsupported" ) ;
if ( supportedGames [ clickedGame ] . hasOwnProperty ( "compatLink" ) ) {
2020-01-10 01:39:20 +01:00
await fetch ( ` https://cors-anywhere.herokuapp.com/http://wiki.cemu.info/api.php?action=parse&page= ${ supportedGames [ clickedGame ] . compatLink . split ( "http://compat.cemu.info/wiki/" ) [ 1 ] } &redirects=true&prop=parsetree&format=json ` ) . then ( fetchRes => fetchRes . json ( ) ) . then ( fetchJson => {
2019-01-08 19:45:57 +01:00
console . debug ( ` Fetched ${ clickedGame } 's(= ${ supportedGames [ clickedGame ] . compatLink . split ( "http://compat.cemu.info/wiki/" ) [ 1 ] } ) compat wiki ` , fetchJson ) ;
let compatTemplates = new DOMParser ( ) . parseFromString ( fetchJson . parse . parsetree [ "*" ] , "application/xml" ) . documentElement . getElementsByTagName ( "template" ) ;
let compatJson = [ ] ;
for ( let i = 0 ; i < compatTemplates . length ; i ++ ) {
if ( compatTemplates [ i ] . firstChild . textContent . includes ( "Infobox VG" ) ) {
let infoboxParts = compatTemplates [ i ] . getElementsByTagName ( "name" ) ;
for ( let j = 0 ; j < infoboxParts . length ; j ++ ) {
compatJson [ infoboxParts [ j ] . textContent . trim ( ) ] = infoboxParts [ j ] . nextElementSibling . textContent . trim ( ) ;
}
break ;
}
}
console . debug ( "Parsed compat info..." , compatJson )
if ( ! compatJson . image . includes ( "*.jpg" ) ) {
2019-01-08 22:43:06 +01:00
document . getElementById ( "modal-preview-image" ) . src = "https://images.weserv.nl/?url=compat.cemu.info/wiki/Special:Redirect/file/" + compatJson . image . split ( "File:" ) [ 1 ] . split ( "|" ) [ 0 ] ;
2019-01-08 19:45:57 +01:00
}
document . getElementById ( "information-box" ) . classList . remove ( "compat-status-loading" ) ;
document . getElementById ( "information-box" ) . classList . add ( "compat-status-" + compatJson . rating . toLowerCase ( ) ) ;
} ) ;
}
$ ( "#searchInfoModal" ) . modal ( ) ;
}
2019-05-04 17:36:19 +02:00
function viewAllGames ( ) {
searchSupportedGames ( "*" ) ;
document . getElementById ( "viewAllGames" ) . onclick = hideAllGames ;
document . getElementById ( "viewAllGames" ) . innerText = "Hide the game list..." ;
}
function hideAllGames ( ) {
searchSupportedGames ( "" ) ;
document . getElementById ( "viewAllGames" ) . onclick = viewAllGames ;
document . getElementById ( "viewAllGames" ) . innerText = "Or view a list with all supported games..." ;
}
2019-01-08 19:45:57 +01:00
// searchSupportedGames(document.querySelector("#supported-games-search input.form-control").value); // If a user loads the page, execute the search inmediately. Initially meant so that if you'd return to the page and still had a search term, it would look correct.
document . querySelector ( "#supported-games-search input.form-control" ) . value = "" ; // Don't fetch stuff automatically when the user doesn't want to search. Considered better since it's an optional feature.
2019-05-04 17:36:19 +02:00
timeago ( ) . render ( document . querySelectorAll ( '.commit-time' ) ) ;
2021-04-30 14:50:28 +02:00
document . getElementById ( "viewAllGames" ) . onclick = viewAllGames ;