fixed bug where duplicate box art icons would appear. This closes #78

This commit is contained in:
R. Aidan Campbell 2016-08-27 09:04:56 -04:00
parent 7f1caff2e8
commit 4df695bdc9

View File

@ -312,30 +312,34 @@ function showApps() {
console.log('Moved into showApps, but `api` did not initialize properly! Failing.'); console.log('Moved into showApps, but `api` did not initialize properly! Failing.');
return; return;
} }
// if game grid is populated, empty it
$("#game-grid").empty(); $("#game-grid").empty();
api.getAppList().then(function (appList) { api.getAppList().then(function (appList) {
// if game grid is populated, empty it
appList.forEach(function (app) { appList.forEach(function (app) {
api.getBoxArt(app.id).then(function (resolvedPromise) { api.getBoxArt(app.id).then(function (resolvedPromise) {
// put the box art into the image holder // put the box art into the image holder
var imageBlob = new Blob([resolvedPromise], {type: "image/png"}); if ($('#game-' + app.id).length === 0) {
$("#game-grid").append($("<div>", {html:$("<img \>", {src: URL.createObjectURL(imageBlob), id: 'game-'+app.id, name: app.title }), class: 'box-art mdl-cell mdl-cell--3-col'}).append($("<span>", {html: app.title, class:"game-title"}))); // double clicking the button will cause multiple box arts to appear.
$('#game-'+app.id).on('click', startGame); // to mitigate this we ensure we don't add a duplicate.
// This isn't perfect: there's lots of RTTs before the logic prevents anything
var imageBlob = new Blob([resolvedPromise], {type: "image/png"});
$("#game-grid").append($("<div>", {html:$("<img \>", {src: URL.createObjectURL(imageBlob), id: 'game-'+app.id, name: app.title }), class: 'box-art mdl-cell mdl-cell--3-col'}).append($("<span>", {html: app.title, class:"game-title"})));
$('#game-'+app.id).on('click', startGame);
// apply CSS stylization to indicate whether the app is active // apply CSS stylization to indicate whether the app is active
stylizeBoxArt(api, app.id); stylizeBoxArt(api, app.id);
}
}, function (failedPromise) { }, function (failedPromise) {
console.log('Error! Failed to retrieve box art for app ID: ' + app.id + '. Returned value was: ' + failedPromise) console.log('Error! Failed to retrieve box art for app ID: ' + app.id + '. Returned value was: ' + failedPromise)
console.log('failed API object: '); console.log('failed API object: ');
console.log(api.toString()); console.log(api.toString());
}); });
}); });
if ($('quitCurrentApp').length === 0) { // also prevent duplicate quit buttons from showing up
$("#game-grid").append($("<div>", {html:$("<img src=static\\res\\ic_remove_circle_white_24px.svg id=quitCurrentApp\>"), class: 'cancel-cell mdl-cell mdl-cell--3-col'}).append($("<span>", {html: 'Quit Current App', class:"game-title"}))); $("#game-grid").append($("<div>", {html:$("<img src=static\\res\\ic_remove_circle_white_24px.svg id=quitCurrentApp\>"), class: 'cancel-cell mdl-cell mdl-cell--3-col'}).append($("<span>", {html: 'Quit Current App', class:"game-title"})));
$('#quitCurrentApp').on('click', function() {api.quitApp(); api.refreshServerInfo(); }); $('#quitCurrentApp').on('click', function() {api.quitApp(); api.refreshServerInfo(); });
}
}, function (failedAppList) { }, function (failedAppList) {
console.log('Failed to get applist from host: ' + api.address); console.log('Failed to get applist from host: ' + api.address);