Files
DosVault/templates/game_detail.html
2025-09-06 22:28:11 -04:00

291 lines
13 KiB
HTML

{% extends "base.html" %}
{% block title %}{{ game.metadata_obj.title or game.title }} - DosVault{% endblock %}
{% block content %}
<div class="max-w-4xl mx-auto">
<div class="mb-6">
<nav class="text-sm text-gray-400 mb-4">
<a href="/" class="hover:text-white">Browse Games</a>
<span class="mx-2">/</span>
<span class="text-white">{{ game.metadata_obj.title or game.title }}</span>
</nav>
<div class="flex justify-between items-start">
<div>
<h1 class="text-3xl font-bold mb-2">{{ game.metadata_obj.title or game.title }}</h1>
<p class="text-gray-400">{{ game.path.name }}</p>
</div>
<div class="flex space-x-3">
{% if not is_demo %}
<button onclick="toggleFavorite({{ game.id }})"
class="text-red-400 hover:text-red-300 text-2xl"
id="favorite-{{ game.id }}">
{% if is_favorite %}♥{% else %}♡{% endif %}
</button>
{% endif %}
{% if current_user and current_user.role == "super" %}
<a href="/admin/games/{{ game.id }}/edit"
class="bg-yellow-600 hover:bg-yellow-700 px-4 py-2 rounded text-sm">
Edit Metadata
</a>
{% endif %}
{% if can_download %}
<button onclick="downloadGame({{ game.id }})"
class="bg-green-600 hover:bg-green-700 px-4 py-2 rounded">
Download Game
</button>
{% else %}
<span class="bg-gray-600 px-4 py-2 rounded cursor-not-allowed">
{% if current_user %}Demo Mode - No Downloads{% else %}Login to Download{% endif %}
</span>
{% endif %}
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<div class="lg:col-span-2">
{% if game.metadata_obj and game.metadata_obj.description %}
<div class="bg-gray-800 rounded-lg p-6 border border-gray-700 mb-6">
<h2 class="text-xl font-bold mb-3">Description</h2>
<p class="text-gray-300 leading-relaxed">{{ game.metadata_obj.description }}</p>
</div>
{% endif %}
<div class="bg-gray-800 rounded-lg p-6 border border-gray-700">
<h2 class="text-xl font-bold mb-4">Game Information</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
{% if game.metadata_obj %}
{% if game.metadata_obj.year %}
<div>
<p class="text-gray-400 text-sm">Release Year</p>
<p class="font-medium">{{ game.metadata_obj.year }}</p>
</div>
{% endif %}
{% if game.metadata_obj.developer %}
<div>
<p class="text-gray-400 text-sm">Developer</p>
<p class="font-medium">{{ game.metadata_obj.developer }}</p>
</div>
{% endif %}
{% if game.metadata_obj.publisher %}
<div>
<p class="text-gray-400 text-sm">Publisher</p>
<p class="font-medium">{{ game.metadata_obj.publisher }}</p>
</div>
{% endif %}
{% if game.metadata_obj.players %}
<div>
<p class="text-gray-400 text-sm">Players</p>
<p class="font-medium">{{ game.metadata_obj.players }}</p>
</div>
{% endif %}
{% if game.metadata_obj.genre %}
<div class="md:col-span-2">
<p class="text-gray-400 text-sm mb-2">Genres</p>
<div class="flex flex-wrap gap-2">
{% for genre in game.metadata_obj.genre %}
<a href="/browse/genres/{{ genre.name | urlencode }}" class="bg-blue-600 hover:bg-blue-700 px-2 py-1 rounded text-sm transition-colors">{{ genre.name }}</a>
{% endfor %}
</div>
</div>
{% endif %}
{% if game.metadata_obj.tags %}
<div class="md:col-span-2">
<p class="text-gray-400 text-sm mb-2">Tags</p>
<div class="flex flex-wrap gap-2">
{% for tag in game.metadata_obj.tags %}
<span class="bg-gray-600 px-2 py-1 rounded text-sm">{{ tag.name }}</span>
{% endfor %}
</div>
</div>
{% endif %}
{% endif %}
<div class="md:col-span-2">
<p class="text-gray-400 text-sm">File Path</p>
<p class="font-mono text-sm bg-gray-700 p-2 rounded">{{ game.path }}</p>
</div>
</div>
</div>
</div>
<div class="space-y-6">
{% if game.metadata_obj and (game.metadata_obj.cover_image_path or game.metadata_obj.cover_image) %}
<div class="bg-gray-800 rounded-lg p-4 border border-gray-700">
<h3 class="text-lg font-bold mb-3">Cover Art</h3>
<img {% if game.metadata_obj.cover_image_path %}src="/images/{{ game.metadata_obj.cover_image_path.name }}"{% else %}src="{{ game.metadata_obj.cover_image }}"{% endif %}
alt="{{ game.metadata_obj.title or game.title }} cover"
class="w-full rounded">
</div>
{% endif %}
{% if game.metadata_obj and (game.metadata_obj.screenshot_path or game.metadata_obj.screenshot) %}
<div class="bg-gray-800 rounded-lg p-4 border border-gray-700">
<h3 class="text-lg font-bold mb-3">Screenshot</h3>
<div class="relative group cursor-pointer" onclick="openScreenshotModal('{% if game.metadata_obj.screenshot_path %}/images/{{ game.metadata_obj.screenshot_path.name }}{% else %}{{ game.metadata_obj.screenshot }}{% endif %}', '{{ game.metadata_obj.title or game.title }}')">
<img {% if game.metadata_obj.screenshot_path %}src="/images/{{ game.metadata_obj.screenshot_path.name }}"{% else %}src="{{ game.metadata_obj.screenshot }}"{% endif %}
alt="{{ game.metadata_obj.title or game.title }} screenshot"
class="w-full rounded transition-transform duration-200 group-hover:scale-105">
<div class="absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-20 rounded transition-all duration-200 flex items-center justify-center">
<svg class="w-12 h-12 text-white opacity-0 group-hover:opacity-80 transition-opacity duration-200" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7"></path>
</svg>
</div>
</div>
<p class="text-xs text-gray-500 mt-2 text-center">Click to enlarge</p>
</div>
{% endif %}
{% if not game.metadata_obj or not game.metadata_obj.description %}
<div class="bg-gray-800 rounded-lg p-4 border border-gray-700 text-center">
<div class="text-4xl mb-2">📦</div>
<p class="text-gray-400 text-sm">No detailed metadata available for this game</p>
{% if current_user and current_user.role == "super" %}
<a href="/admin/games/{{ game.id }}/edit"
class="inline-block mt-2 text-blue-400 hover:text-blue-300 text-sm underline">
Add Metadata
</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
</div>
<!-- Screenshot Modal -->
<div id="screenshotModal" class="hidden fixed inset-0 bg-black bg-opacity-75 z-50 flex items-center justify-center p-4">
<div class="relative max-w-4xl max-h-full">
<button onclick="closeScreenshotModal()" class="absolute top-4 right-4 text-white hover:text-gray-300 text-3xl z-10 bg-black bg-opacity-50 rounded-full w-12 h-12 flex items-center justify-center">
&times;
</button>
<img id="screenshotModalImage" src="" alt="" class="max-w-full max-h-full rounded-lg">
<div class="absolute bottom-4 left-4 right-4 text-center">
<p id="screenshotModalTitle" class="text-white bg-black bg-opacity-50 px-4 py-2 rounded-lg"></p>
</div>
</div>
</div>
<script>
function openScreenshotModal(imageSrc, title) {
const modal = document.getElementById('screenshotModal');
const image = document.getElementById('screenshotModalImage');
const titleElement = document.getElementById('screenshotModalTitle');
image.src = imageSrc;
image.alt = title + ' screenshot';
titleElement.textContent = title + ' - Screenshot';
modal.classList.remove('hidden');
document.body.style.overflow = 'hidden'; // Prevent background scrolling
}
function closeScreenshotModal() {
const modal = document.getElementById('screenshotModal');
modal.classList.add('hidden');
document.body.style.overflow = 'auto'; // Restore scrolling
}
// Close modal when clicking outside the image
document.getElementById('screenshotModal').addEventListener('click', function(e) {
if (e.target === this) {
closeScreenshotModal();
}
});
// Close modal with Escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeScreenshotModal();
}
});
async function toggleFavorite(gameId) {
const token = localStorage.getItem('authToken');
if (!token) {
showLogin();
return;
}
try {
const response = await fetch(`/games/${gameId}/favorite`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
}
});
if (response.ok) {
const favoriteBtn = document.getElementById(`favorite-${gameId}`);
const isFavorited = favoriteBtn.textContent.trim() === '♥';
if (isFavorited) {
// Remove from favorites
favoriteBtn.textContent = '♡';
favoriteBtn.classList.remove('text-red-600');
favoriteBtn.classList.add('text-red-400');
} else {
// Add to favorites
favoriteBtn.textContent = '♥';
favoriteBtn.classList.remove('text-red-400');
favoriteBtn.classList.add('text-red-600');
}
} else if (response.status === 401) {
localStorage.removeItem('authToken');
showLogin();
}
} catch (error) {
console.error('Error toggling favorite:', error);
}
}
async function downloadGame(gameId) {
const token = localStorage.getItem('authToken');
if (!token) {
showLogin();
return;
}
try {
const response = await fetch(`/download/${gameId}`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
if (response.ok) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// Get filename from Content-Disposition header, removing quotes and underscores
let filename = response.headers.get('Content-Disposition')?.split('filename=')[1] || 'game.zip';
filename = filename.replace(/^["_]+|["_]+$/g, ''); // Remove quotes and underscores from start and end
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
} else if (response.status === 401) {
localStorage.removeItem('authToken');
showLogin();
} else {
alert('Download failed. Please try again.');
}
} catch (error) {
console.error('Download error:', error);
alert('Download failed. Please try again.');
}
}
</script>
{% endblock %}