Änderung: Hinzufügung des Taxi-Minispiels und zugehöriger Funktionen
Änderungen: - Integration des Taxi-Minispiels mit neuen Routen und Komponenten im Backend und Frontend. - Erstellung von Modellen und Datenbank-Schemas für das Taxi-Spiel, einschließlich TaxiGameState, TaxiLevelStats und TaxiMap. - Erweiterung der Navigationsstruktur und der Benutzeroberfläche, um das Taxi-Spiel und die zugehörigen Tools zu unterstützen. - Aktualisierung der Übersetzungen für das Taxi-Minispiel in Deutsch und Englisch. Diese Anpassungen erweitern die Funktionalität der Anwendung um ein neues Minispiel und verbessern die Benutzererfahrung durch neue Features und Inhalte.
This commit is contained in:
@@ -174,6 +174,10 @@ const menuStructure = {
|
||||
match3: {
|
||||
visible: ["all"],
|
||||
path: "/minigames/match3"
|
||||
},
|
||||
taxi: {
|
||||
visible: ["all"],
|
||||
path: "/minigames/taxi"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -274,6 +278,10 @@ const menuStructure = {
|
||||
match3: {
|
||||
visible: ["mainadmin", "match3"],
|
||||
path: "/admin/minigames/match3"
|
||||
},
|
||||
taxiTools: {
|
||||
visible: ["mainadmin", "taxi"],
|
||||
path: "/admin/minigames/taxi-tools"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
144
backend/controllers/taxiController.js
Normal file
144
backend/controllers/taxiController.js
Normal file
@@ -0,0 +1,144 @@
|
||||
import TaxiService from '../services/taxiService.js';
|
||||
|
||||
function extractHashedUserId(req) {
|
||||
return req.headers?.userid;
|
||||
}
|
||||
|
||||
class TaxiController {
|
||||
constructor() {
|
||||
this.taxiService = new TaxiService();
|
||||
}
|
||||
|
||||
// Spielstand laden
|
||||
async getGameState(req, res) {
|
||||
try {
|
||||
const hashedUserId = extractHashedUserId(req);
|
||||
const gameState = await this.taxiService.getGameState(hashedUserId);
|
||||
res.json({ success: true, data: gameState });
|
||||
} catch (error) {
|
||||
console.error('Error getting taxi game state:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden des Spielstands' });
|
||||
}
|
||||
}
|
||||
|
||||
// Spielstand speichern
|
||||
async saveGameState(req, res) {
|
||||
try {
|
||||
const userId = extractHashedUserId(req);
|
||||
const { level, score, money, passengersDelivered, fuel } = req.body;
|
||||
|
||||
const gameState = await this.taxiService.saveGameState(userId, {
|
||||
level,
|
||||
score,
|
||||
money,
|
||||
passengersDelivered,
|
||||
fuel
|
||||
});
|
||||
|
||||
res.json({ success: true, data: gameState });
|
||||
} catch (error) {
|
||||
console.error('Error saving taxi game state:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Speichern des Spielstands' });
|
||||
}
|
||||
}
|
||||
|
||||
// Level-Statistiken abrufen
|
||||
async getLevelStats(req, res) {
|
||||
try {
|
||||
const userId = extractHashedUserId(req);
|
||||
const { level } = req.params;
|
||||
|
||||
const stats = await this.taxiService.getLevelStats(userId, parseInt(level));
|
||||
res.json({ success: true, data: stats });
|
||||
} catch (error) {
|
||||
console.error('Error getting level stats:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Level-Statistiken' });
|
||||
}
|
||||
}
|
||||
|
||||
// Bestenliste abrufen
|
||||
async getLeaderboard(req, res) {
|
||||
try {
|
||||
const { type = 'score', limit = 10 } = req.query;
|
||||
const leaderboard = await this.taxiService.getLeaderboard(type, parseInt(limit));
|
||||
res.json({ success: true, data: leaderboard });
|
||||
} catch (error) {
|
||||
console.error('Error getting leaderboard:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Bestenliste' });
|
||||
}
|
||||
}
|
||||
|
||||
// Spiel beenden und Punkte verarbeiten
|
||||
async finishGame(req, res) {
|
||||
try {
|
||||
const userId = extractHashedUserId(req);
|
||||
const { finalScore, finalMoney, passengersDelivered, level } = req.body;
|
||||
|
||||
const result = await this.taxiService.finishGame(userId, {
|
||||
finalScore,
|
||||
finalMoney,
|
||||
passengersDelivered,
|
||||
level
|
||||
});
|
||||
|
||||
res.json({ success: true, data: result });
|
||||
} catch (error) {
|
||||
console.error('Error finishing game:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Beenden des Spiels' });
|
||||
}
|
||||
}
|
||||
|
||||
// Level freischalten
|
||||
async unlockLevel(req, res) {
|
||||
try {
|
||||
const userId = extractHashedUserId(req);
|
||||
const { level } = req.body;
|
||||
|
||||
const result = await this.taxiService.unlockLevel(userId, level);
|
||||
res.json({ success: true, data: result });
|
||||
} catch (error) {
|
||||
console.error('Error unlocking level:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Freischalten des Levels' });
|
||||
}
|
||||
}
|
||||
|
||||
// Spieler-Statistiken abrufen
|
||||
async getPlayerStats(req, res) {
|
||||
try {
|
||||
const userId = extractHashedUserId(req);
|
||||
const stats = await this.taxiService.getPlayerStats(userId);
|
||||
res.json({ success: true, data: stats });
|
||||
} catch (error) {
|
||||
console.error('Error getting player stats:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Spieler-Statistiken' });
|
||||
}
|
||||
}
|
||||
|
||||
// Level zurücksetzen
|
||||
async resetLevel(req, res) {
|
||||
try {
|
||||
const userId = extractHashedUserId(req);
|
||||
const { level } = req.body;
|
||||
|
||||
const result = await this.taxiService.resetLevel(userId, level);
|
||||
res.json({ success: true, data: result });
|
||||
} catch (error) {
|
||||
console.error('Error resetting level:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Zurücksetzen des Levels' });
|
||||
}
|
||||
}
|
||||
|
||||
// Alle Spielstände zurücksetzen
|
||||
async resetAllProgress(req, res) {
|
||||
try {
|
||||
const userId = extractHashedUserId(req);
|
||||
const result = await this.taxiService.resetAllProgress(userId);
|
||||
res.json({ success: true, data: result });
|
||||
} catch (error) {
|
||||
console.error('Error resetting all progress:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Zurücksetzen aller Fortschritte' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default TaxiController;
|
||||
144
backend/controllers/taxiMapController.js
Normal file
144
backend/controllers/taxiMapController.js
Normal file
@@ -0,0 +1,144 @@
|
||||
import TaxiMapService from '../services/taxiMapService.js';
|
||||
|
||||
class TaxiMapController {
|
||||
constructor() {
|
||||
this.taxiMapService = new TaxiMapService();
|
||||
|
||||
// Bind all methods to the class instance
|
||||
this.getMapTypes = this.getMapTypes.bind(this);
|
||||
this.getMaps = this.getMaps.bind(this);
|
||||
this.getMapById = this.getMapById.bind(this);
|
||||
this.getMapByPosition = this.getMapByPosition.bind(this);
|
||||
this.getDefaultMap = this.getDefaultMap.bind(this);
|
||||
this.createMap = this.createMap.bind(this);
|
||||
this.updateMap = this.updateMap.bind(this);
|
||||
this.deleteMap = this.deleteMap.bind(this);
|
||||
this.setDefaultMap = this.setDefaultMap.bind(this);
|
||||
}
|
||||
|
||||
async getMapTypes(req, res) {
|
||||
try {
|
||||
const mapTypes = await this.taxiMapService.getMapTypes();
|
||||
res.json({ success: true, data: mapTypes });
|
||||
} catch (error) {
|
||||
console.error('Error getting map types:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Map-Typen' });
|
||||
}
|
||||
}
|
||||
|
||||
async getMaps(req, res) {
|
||||
try {
|
||||
const maps = await this.taxiMapService.getMaps();
|
||||
res.json({ success: true, data: maps });
|
||||
} catch (error) {
|
||||
console.error('Error getting maps:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Maps' });
|
||||
}
|
||||
}
|
||||
|
||||
async getMapById(req, res) {
|
||||
try {
|
||||
const { mapId } = req.params;
|
||||
const map = await this.taxiMapService.getMapById(mapId);
|
||||
|
||||
if (!map) {
|
||||
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
|
||||
}
|
||||
|
||||
res.json({ success: true, data: map });
|
||||
} catch (error) {
|
||||
console.error('Error getting map by ID:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Map' });
|
||||
}
|
||||
}
|
||||
|
||||
async getMapByPosition(req, res) {
|
||||
try {
|
||||
const { positionX, positionY } = req.params;
|
||||
const map = await this.taxiMapService.getMapByPosition(
|
||||
parseInt(positionX),
|
||||
parseInt(positionY)
|
||||
);
|
||||
|
||||
if (!map) {
|
||||
return res.status(404).json({ success: false, message: 'Map an Position nicht gefunden' });
|
||||
}
|
||||
|
||||
res.json({ success: true, data: map });
|
||||
} catch (error) {
|
||||
console.error('Error getting map by position:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Map' });
|
||||
}
|
||||
}
|
||||
|
||||
async getDefaultMap(req, res) {
|
||||
try {
|
||||
const map = await this.taxiMapService.getDefaultMap();
|
||||
|
||||
if (!map) {
|
||||
return res.status(404).json({ success: false, message: 'Keine Standard-Map gefunden' });
|
||||
}
|
||||
|
||||
res.json({ success: true, data: map });
|
||||
} catch (error) {
|
||||
console.error('Error getting default map:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Laden der Standard-Map' });
|
||||
}
|
||||
}
|
||||
|
||||
async createMap(req, res) {
|
||||
try {
|
||||
const mapData = req.body;
|
||||
const map = await this.taxiMapService.createMap(mapData);
|
||||
res.status(201).json({ success: true, data: map });
|
||||
} catch (error) {
|
||||
console.error('Error creating map:', error);
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Erstellen der Map' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateMap(req, res) {
|
||||
try {
|
||||
const { mapId } = req.params;
|
||||
const updateData = req.body;
|
||||
const map = await this.taxiMapService.updateMap(mapId, updateData);
|
||||
res.json({ success: true, data: map });
|
||||
} catch (error) {
|
||||
console.error('Error updating map:', error);
|
||||
if (error.message === 'Map not found') {
|
||||
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
|
||||
}
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Aktualisieren der Map' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteMap(req, res) {
|
||||
try {
|
||||
const { mapId } = req.params;
|
||||
await this.taxiMapService.deleteMap(mapId);
|
||||
res.json({ success: true, message: 'Map erfolgreich gelöscht' });
|
||||
} catch (error) {
|
||||
console.error('Error deleting map:', error);
|
||||
if (error.message === 'Map not found') {
|
||||
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
|
||||
}
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Löschen der Map' });
|
||||
}
|
||||
}
|
||||
|
||||
async setDefaultMap(req, res) {
|
||||
try {
|
||||
const { mapId } = req.params;
|
||||
await this.taxiMapService.setDefaultMap(mapId);
|
||||
res.json({ success: true, message: 'Standard-Map erfolgreich gesetzt' });
|
||||
} catch (error) {
|
||||
console.error('Error setting default map:', error);
|
||||
if (error.message === 'Map not found') {
|
||||
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
|
||||
}
|
||||
res.status(500).json({ success: false, message: 'Fehler beim Setzen der Standard-Map' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default TaxiMapController;
|
||||
Reference in New Issue
Block a user