Skip to content

Commit

Permalink
✨ Add OS detection system
Browse files Browse the repository at this point in the history
  • Loading branch information
NoaSecond committed Nov 20, 2024
1 parent be50a68 commit 3e2b693
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions components/gameCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<a class="title"><?php echo htmlspecialchars($title); ?></a>
<a class="description"><?php echo htmlspecialchars($description); ?></a>
<a class="tags"><?php echo htmlspecialchars(implode(',', $gameTags)); ?></a>
<a class="avaiblePlatforms"><?php echo htmlspecialchars(implode( ',', $platforms)); ?></a>
<a class="action"><?php echo htmlspecialchars($action); ?></a>
<a class="unavaible"><?php echo htmlspecialchars($unavailable); ?></a>
<a class="actionLink"><?php echo htmlspecialchars($actionLink); ?></a>
</div>
<div class="foreground">
Expand Down
1 change: 1 addition & 0 deletions components/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<!-- <script src="/js/lang.js" defer></script> -->
<script src="/js/dynamicTitle.js" defer></script>
<script src="/js/rightClick.js" defer></script>
<script src="/js/osDetection.js" defer></script>
<!-- Ajax -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> -->
<!-- Fonts -->
Expand Down
9 changes: 6 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@
<h1>LaCorbeille STUDIO</h1>
</div>
<div id="carousel">
<?php
// Correct platforms labels : Windows, Linux, MacOS, iOS, Android
$unavailable = "Indisponible pour votre plateforme";
?>
<?php
$title = "A Little Adventure";
$description = "A Little Adventure est platformer vibrant où chaque niveau regorge d'obstacles et de défis.";
$description = "A Little Adventure est un platformer vibrant où chaque niveau regorge d'obstacles et de défis.";
$gameTags = ["Platformer", "Adventure", "3D", "LowPoly"];
$action = "Télécharger le prototype";
$actionLink = "/assets/downloadable/A Little Adventure.exe";
Expand All @@ -64,8 +68,7 @@
?>
<?php
$title = "Rice Battle";
// $description = "Rice Battle est un jeu de combat en 2.5D dans l'univers de la cuisine asiatique.";
$description = "Ce jeu est en cours de développement.";
$description = "Rice Battle est un jeu de combat en 2.5D dans l'univers de la cuisine asiatique.<br>Ce jeu est en cours de développement.";
$gameTags = ["Combat", "2.5D", "Arcade"];
// $action = "Télécharger la beta";
$action = "";
Expand Down
19 changes: 17 additions & 2 deletions js/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ function updateContentWrapper(card) {
const cardButton = card.querySelector('.contentWrapperInfo .action').textContent;
const cardActionLink = card.querySelector('.contentWrapperInfo .actionLink').textContent;
const tagsArray = cardTags ? cardTags.split(',') : [];
const avaiblePlatforms = card.querySelector('.avaiblePlatforms').textContent;
const platformsArray = avaiblePlatforms ? avaiblePlatforms.split(',') : [];
const platformImages = Array.from(card.querySelectorAll('.platforms img'));

// Create new elements
Expand All @@ -82,7 +84,7 @@ function updateContentWrapper(card) {

const contentWrapperDescription = document.createElement('a');
contentWrapperDescription.id = 'gameDescription';
contentWrapperDescription.textContent = cardDescription;
contentWrapperDescription.innerHTML = cardDescription;

const contentWrapperTagsWrapper = document.createElement('div');
contentWrapperTagsWrapper.id = 'gameTags';
Expand All @@ -102,18 +104,31 @@ function updateContentWrapper(card) {
contentWrapperPlatformsWrapper.appendChild(platformImg);
});

// OS detection
const os = detectOS();
let isOSAvaible = false;
platformsArray.forEach(platform => {
if (platform === os) {
isOSAvaible = true;
}
});

// Add new elements to the contentWrapper
contentWrapper.appendChild(contentWrapperTitle);
contentWrapper.appendChild(contentWrapperDescription);
contentWrapper.appendChild(contentWrapperTagsWrapper);
contentWrapper.appendChild(contentWrapperPlatformsWrapper);
if (cardButton) {
if (cardButton && isOSAvaible) {
const contentWrapperButton = document.createElement('button');
contentWrapperButton.textContent = cardButton;
contentWrapperButton.addEventListener('click', () => {
window.location.href = cardActionLink;
});
contentWrapper.appendChild(contentWrapperButton);
} else if (!isOSAvaible) {
const contentWrapperButton = document.createElement('button');
contentWrapperButton.textContent = 'Indisponible sur votre OS';
contentWrapperButton.disabled = true;
contentWrapper.appendChild(contentWrapperButton);
}
}
18 changes: 18 additions & 0 deletions js/osDetection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function detectOS() {
const userAgent = navigator.userAgent.toLowerCase();
const platform = navigator.platform.toLowerCase();

if (platform.includes("mac") || userAgent.includes("macintosh")) {
return "MacOS";
} else if (platform.includes("win") || userAgent.includes("windows")) {
return "Windows";
} else if (platform.includes("linux") || userAgent.includes("linux")) {
return "Linux";
} else if (/iphone|ipad|ipod/.test(userAgent)) {
return "iOS";
} else if (/android/.test(userAgent)) {
return "Android";
} else {
return "Inconnu";
}
}

0 comments on commit 3e2b693

Please sign in to comment.