Skip to content

Commit

Permalink
Merge pull request #11 from JakeLegendXIII/feature/showcase-filters
Browse files Browse the repository at this point in the history
Add filter by tags to showcase
  • Loading branch information
tomspilman authored Nov 14, 2023
2 parents c507816 + a6f3b21 commit 892d665
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 208 deletions.
3 changes: 2 additions & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ _title: MonoGame
</div>
</section>

<script src="/scripts/game-banners.js"/>
<script src="/scripts/game-data.js"></script>
<script src="/scripts/game-banners.js"></script>

38 changes: 8 additions & 30 deletions scripts/game-banners.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
var banners = [

{"name":"sor4","logo":"sor4-logo.png","screenshot":"sor4-screenshot.jpg","url":"https:\/\/www.streets4rage.com\/","pixelart":false,"tags":["2D","Console","PlayStation4","XboxOne","NintendoSwitch","Featured"]},
{"name":"paladin","logo":"paladin-logo.png","screenshot":"paladin-screenshot.jpg","url":"http:\/\/pumpkin-games.net\/paladin.php","pixelart":false,"tags":["2D","Console","Mac","Linux","Desktop","XboxOne","NintendoSwitch","Featured"]},
{"name":"fhook","logo":"fhook-logo.png","screenshot":"fhook-screenshot.png","url":"http:\/\/flinthook.com\/","pixelart":true,"tags":["2D","Console","PlayStation4","XboxOne","NintendoSwitch","Featured"]},
{"name":"daryl","logo":"daryl-logo.png","screenshot":"daryl-screenshot.jpg","url":"https:\/\/danandgarygames.com\/superdaryldeluxe","pixelart":false,"tags":["2D","Console","PlayStation4","NintendoSwitch","Featured"]},
{"name":"chasm","logo":"chasm-logo.png","screenshot":"chasm-screenshot.png","url":"http:\/\/www.chasmgame.com\/","pixelart":true,"tags":["2D","Console","PlayStation4","PSVita","NintendoSwitch","Featured"]},
{"name":"celeste","logo":"celeste-logo.png","screenshot":"celeste-screenshot.png","url":"http:\/\/www.celestegame.com\/","pixelart":true,"tags":["2D","Console","XboxOne","NintendoSwitch","PlayStation4","Featured"]},
{"name":"redungeon","logo":"redungeon-logo.png","screenshot":"redungeon-screenshot.png","url":"http:\/\/www.eneminds.com\/redungeon\/","pixelart":true,"tags":["Mobile","iOS","Android","Featured"]},
{"name":"squareheroes","logo":"squareheroes-logo.png","screenshot":"squareheroes-screenshot.png","url":"http:\/\/www.squareheroes.com\/","pixelart":false,"tags":["Console","PlayStation4","Featured"]},
{"name":"wayward","logo":"wayward-logo.png","screenshot":"wayward-screenshot.jpg","url":"http:\/\/www.wtfrontier.com\/","pixelart":false,"tags":["Windows","Desktop","Featured"]},
{"name":"skulls","logo":"skulls-logo.png","screenshot":"skulls-screenshot.jpg","url":"http:\/\/skullsoftheshogun.com\/","pixelart":false,"tags":["Console","PlayStation4","Mobile","Android","Featured"]},
{"name":"ty","logo":"ty-logo.png","screenshot":"ty-screenshot.jpg","url":"http:\/\/www.kromestudios.com\/TY\/","pixelart":false,"tags":["Desktop","Windows","2D","Featured"]},
{"name":"hockey","logo":"oth-logo.png","screenshot":"oldtimehockey-screenshot.jpg","url":"http:\/\/www.bushhockeyleague.com\/","pixelart":false,"tags":["Console","PlayStation4","XboxOne","3D","Featured"]},
{"name":"flight","logo":"flight-logo.png","screenshot":"flight-screenshot.jpg","url":"http:\/\/www.infinite-flight.com\/","pixelart":false,"tags":["iOS","Android","Mobile","3D","Featured"]},
{"name":"neurovoider","logo":"neurovoider-logo.png","screenshot":"neurovoider-screenshot.jpg","url":"http:\/\/www.neurovoider.com\/","pixelart":true,"tags":["Windows","Mac","Linux","XboxOne","PlayStation4","PSVita","NintendoSwitch","2D","Desktop","Console","Featured"]},
{"name":"apotheon","logo":"apotheon-logo.png","screenshot":"apotheon-screenshot.jpg","url":"http:\/\/www.apotheongame.com\/","pixelart":false,"tags":["PlayStation4","2D","Console","Featured"]},
{"name":"axiom","logo":"axiom-logo.png","screenshot":"axiom-screenshot.png","url":"http:\/\/www.axiomverge.com\/","pixelart":true,"tags":["PlayStation4","XboxOne","NintendoSwitch","PSVita","2D","Console","Featured"]},
{"name":"towerfall","logo":"towerfall-logo.png","screenshot":"towerfall-screenshot.jpg","url":"http:\/\/www.towerfall-game.com\/","pixelart":true,"tags":["PlayStation4","XboxOne","NintendoSwitch","PSVita","2D","Console","Featured"]},
{"name":"stardew","logo":"stardew-logo4.png","screenshot":"stardew-screenshot.png","url":"http:\/\/www.stardewvalley.net\/","pixelart":true,"tags":["PlayStation4","XboxOne","NintendoSwitch","PSVita","2D","Console","Mac","Linux","Desktop","Featured"]},
{"name":"toothandtail","logo":"toothandtail-logo.png","screenshot":"toothandtail-screenshot.png","url":"http:\/\/www.toothandtailgame.com\/","pixelart":false,"tags":["PlayStation4","Windows","2D","Console","Desktop","Featured"]}

];

var preload = new Array();
var shuffled = [];
function shuffle(a,b,c,d){c=a.length;while(c)b=Math.random()*(--c+1)|0,d=a[c],a[c]=a[b],a[b]=d}
Expand Down Expand Up @@ -51,11 +27,11 @@ function init_banner()
if(result != null)
{
var name = result[1];
for (var i=0; i < banners.length; i++)
for (var i=0; i < games.length; i++)
{
if (banners[i].name == name)
if (games[i].name == name)
{
show_banner(banners[i]);
show_banner(games[i]);
return;
}
}
Expand All @@ -67,9 +43,13 @@ function init_banner()

function random_banner()
{
var featuredBanners = games.filter(function(banner) {
return banner.tags.includes('Featured');
});

if (shuffled.length <= 1)
{
shuffled = shuffled.concat(banners);
shuffled = shuffled.concat(featuredBanners);
shuffled = unique(shuffled);
shuffle(shuffled);
}
Expand Down Expand Up @@ -102,6 +82,4 @@ function show_banner(title)
logoImage.parentElement.href = title.url;
}

var BannerPath = "/images/showcase-header/";

init_banner();
35 changes: 35 additions & 0 deletions scripts/game-data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions scripts/showcase-filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function init_filter() {
var data = window.top.location.search;
var container = document.getElementById('gamesList');
var filterTag = data ? remove_questionmark(data) : null;

for (var i = 0; i < games.length; i++) {
if (!filterTag || games[i].tags.includes(filterTag)) {
add_to_screen(games[i], container);
}
}
}

function add_to_screen(game, container) {
var gameDiv = document.createElement('div');
gameDiv.id = game.name;
gameDiv.className = 'showcase-link-image';
gameDiv.style.backgroundImage = "url('" + BannerPath + game.screenshot + "')";

if (game.pixelart == true)
{
gameDiv.style["image-rendering"] = "pixelated";
gameDiv.style["-ms-interpolation-mode"] = "nearest-neighbor";
}
else
{
gameDiv.style["image-rendering"] = "auto";
gameDiv.style["-ms-interpolation-mode"] = "bicubic";
}

var link = document.createElement('a');
link.href = game.url;

var logoDiv = document.createElement('div');
logoDiv.style = "width:100%;height:100%;background:url('" + BannerPath + game.logo + "') center center no-repeat";
logoDiv.title = game.title;

link.appendChild(logoDiv);
gameDiv.appendChild(link);
container.appendChild(gameDiv);
}

function remove_questionmark(str) {
var pattern = /\?/;
var result = pattern.exec(str);
if (result != null) {
return str.replace('?', '');
} else {
return str;
}
}

init_filter();
Loading

0 comments on commit 892d665

Please sign in to comment.