Ä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.
270 lines
7.2 KiB
JavaScript
270 lines
7.2 KiB
JavaScript
import BaseService from './BaseService.js';
|
|
import TaxiMap from '../models/taxi/taxiMap.js';
|
|
import TaxiMapType from '../models/taxi/taxiMapType.js';
|
|
|
|
class TaxiMapService extends BaseService {
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* Holt alle verfügbaren Map-Typen
|
|
*/
|
|
async getMapTypes() {
|
|
try {
|
|
const mapTypes = await TaxiMapType.findAll({
|
|
where: { isActive: true },
|
|
order: [['name', 'ASC']]
|
|
});
|
|
return mapTypes;
|
|
} catch (error) {
|
|
console.error('Error getting map types:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Holt alle verfügbaren Maps
|
|
*/
|
|
async getMaps() {
|
|
try {
|
|
const maps = await TaxiMap.findAll({
|
|
where: { isActive: true },
|
|
include: [{
|
|
model: TaxiMapType,
|
|
as: 'mapType'
|
|
}],
|
|
order: [['positionY', 'ASC'], ['positionX', 'ASC']]
|
|
});
|
|
return maps;
|
|
} catch (error) {
|
|
console.error('Error getting maps:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Holt eine spezifische Map
|
|
*/
|
|
async getMapById(mapId) {
|
|
try {
|
|
const map = await TaxiMap.findOne({
|
|
where: {
|
|
id: mapId,
|
|
isActive: true
|
|
},
|
|
include: [{
|
|
model: TaxiMapType,
|
|
as: 'mapType'
|
|
}]
|
|
});
|
|
return map;
|
|
} catch (error) {
|
|
console.error('Error getting map by ID:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Holt eine Map nach Position
|
|
*/
|
|
async getMapByPosition(positionX, positionY) {
|
|
try {
|
|
const map = await TaxiMap.findOne({
|
|
where: {
|
|
positionX: positionX,
|
|
positionY: positionY,
|
|
isActive: true
|
|
},
|
|
include: [{
|
|
model: TaxiMapType,
|
|
as: 'mapType'
|
|
}]
|
|
});
|
|
return map;
|
|
} catch (error) {
|
|
console.error('Error getting map by position:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Holt die Standard-Map
|
|
*/
|
|
async getDefaultMap() {
|
|
try {
|
|
const map = await TaxiMap.findOne({
|
|
where: {
|
|
isDefault: true,
|
|
isActive: true
|
|
},
|
|
include: [{
|
|
model: TaxiMapType,
|
|
as: 'mapType'
|
|
}]
|
|
});
|
|
return map;
|
|
} catch (error) {
|
|
console.error('Error getting default map:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Erstellt eine neue Map
|
|
*/
|
|
async createMap(mapData) {
|
|
try {
|
|
const map = await TaxiMap.create(mapData);
|
|
return map;
|
|
} catch (error) {
|
|
console.error('Error creating map:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Aktualisiert eine Map
|
|
*/
|
|
async updateMap(mapId, updateData) {
|
|
try {
|
|
const [updatedRowsCount] = await TaxiMap.update(updateData, {
|
|
where: { id: mapId }
|
|
});
|
|
|
|
if (updatedRowsCount === 0) {
|
|
throw new Error('Map not found');
|
|
}
|
|
|
|
return await this.getMapById(mapId);
|
|
} catch (error) {
|
|
console.error('Error updating map:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Löscht eine Map (soft delete)
|
|
*/
|
|
async deleteMap(mapId) {
|
|
try {
|
|
const [updatedRowsCount] = await TaxiMap.update(
|
|
{ isActive: false },
|
|
{ where: { id: mapId } }
|
|
);
|
|
|
|
if (updatedRowsCount === 0) {
|
|
throw new Error('Map not found');
|
|
}
|
|
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error('Error deleting map:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Setzt eine Map als Standard
|
|
*/
|
|
async setDefaultMap(mapId) {
|
|
try {
|
|
// Entferne Standard-Status von allen anderen Maps
|
|
await TaxiMap.update(
|
|
{ isDefault: false },
|
|
{ where: { isDefault: true } }
|
|
);
|
|
|
|
// Setze neue Standard-Map
|
|
const [updatedRowsCount] = await TaxiMap.update(
|
|
{ isDefault: true },
|
|
{ where: { id: mapId } }
|
|
);
|
|
|
|
if (updatedRowsCount === 0) {
|
|
throw new Error('Map not found');
|
|
}
|
|
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error('Error setting default map:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialisiert Standard-Map-Typen
|
|
*/
|
|
async initializeMapTypes() {
|
|
try {
|
|
const mapTypes = [
|
|
{ name: 'Corner Bottom Left', tileType: 'cornerBottomLeft', description: 'Bottom left corner tile' },
|
|
{ name: 'Corner Bottom Right', tileType: 'cornerBottomRight', description: 'Bottom right corner tile' },
|
|
{ name: 'Corner Top Left', tileType: 'cornerTopLeft', description: 'Top left corner tile' },
|
|
{ name: 'Corner Top Right', tileType: 'cornerTopRight', description: 'Top right corner tile' },
|
|
{ name: 'Horizontal', tileType: 'horizontal', description: 'Horizontal road tile' },
|
|
{ name: 'Vertical', tileType: 'vertical', description: 'Vertical road tile' },
|
|
{ name: 'Cross', tileType: 'cross', description: 'Cross intersection tile' },
|
|
{ name: 'Fuel Horizontal', tileType: 'fuelHorizontal', description: 'Horizontal road with fuel station' },
|
|
{ name: 'Fuel Vertical', tileType: 'fuelVertical', description: 'Vertical road with fuel station' },
|
|
{ name: 'T-Left', tileType: 'tLeft', description: 'T-junction facing left' },
|
|
{ name: 'T-Right', tileType: 'tRight', description: 'T-junction facing right' },
|
|
{ name: 'T-Up', tileType: 'tUp', description: 'T-junction facing up' },
|
|
{ name: 'T-Down', tileType: 'tDown', description: 'T-junction facing down' }
|
|
];
|
|
|
|
for (const mapType of mapTypes) {
|
|
await TaxiMapType.findOrCreate({
|
|
where: { name: mapType.name },
|
|
defaults: mapType
|
|
});
|
|
}
|
|
|
|
console.log('Taxi map types initialized');
|
|
} catch (error) {
|
|
console.error('Error initializing map types:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Erstellt eine Standard-Map
|
|
*/
|
|
async createDefaultMap() {
|
|
try {
|
|
// 8x8 Standard-Map mit verschiedenen Tile-Typen
|
|
const mapData = [
|
|
['cornerTopLeft', 'horizontal', 'horizontal', 'horizontal', 'horizontal', 'horizontal', 'horizontal', 'cornerTopRight'],
|
|
['vertical', 'cross', 'cross', 'cross', 'cross', 'cross', 'cross', 'vertical'],
|
|
['vertical', 'cross', 'cross', 'cross', 'cross', 'cross', 'cross', 'vertical'],
|
|
['vertical', 'cross', 'cross', 'cross', 'cross', 'cross', 'cross', 'vertical'],
|
|
['vertical', 'cross', 'cross', 'cross', 'cross', 'cross', 'cross', 'vertical'],
|
|
['vertical', 'cross', 'cross', 'cross', 'cross', 'cross', 'cross', 'vertical'],
|
|
['vertical', 'cross', 'cross', 'cross', 'cross', 'cross', 'cross', 'vertical'],
|
|
['cornerBottomLeft', 'horizontal', 'horizontal', 'horizontal', 'horizontal', 'horizontal', 'horizontal', 'cornerBottomRight']
|
|
];
|
|
|
|
const map = await TaxiMap.create({
|
|
name: 'Standard City Map',
|
|
description: 'A standard 8x8 city map with roads and intersections',
|
|
width: 8,
|
|
height: 8,
|
|
tileSize: 50,
|
|
mapTypeId: 1, // Assuming first map type
|
|
mapData: mapData,
|
|
positionX: 1,
|
|
positionY: 1,
|
|
isDefault: true,
|
|
isActive: true
|
|
});
|
|
|
|
return map;
|
|
} catch (error) {
|
|
console.error('Error creating default map:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default TaxiMapService;
|