Add map prototype with coordinate tracking for players, vehicles, buildings
This commit is contained in:
1 parent
70f573eed5
commit
f15e8783e2
4 files changed
+455
No files matched your search
@@ -451,3 +451,117 @@ def register_routes(app, services, settings):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Error in server_status route")
|
logger.exception("Error in server_status route")
|
||||||
return render_template('server.html', db_error=f"{type(e).__name__}: {e}")
|
return render_template('server.html', db_error=f"{type(e).__name__}: {e}")
|
||||||
|
|
||||||
|
# Map - shows locations of players, vehicles, buildings
|
||||||
|
@app.route('/map')
|
||||||
|
@login_required
|
||||||
|
def map_page():
|
||||||
|
try:
|
||||||
|
# Get players with coordinates
|
||||||
|
players = db.query("""
|
||||||
|
SELECT
|
||||||
|
a.id,
|
||||||
|
COALESCE(NULLIF(ps.character_name, ''), 'Unknown') as name,
|
||||||
|
a.map,
|
||||||
|
a.transform
|
||||||
|
FROM dune.actors a
|
||||||
|
JOIN dune.player_state ps ON a.id = ps.player_pawn_id
|
||||||
|
WHERE a.transform IS NOT NULL
|
||||||
|
ORDER BY a.map, ps.character_name
|
||||||
|
""") or []
|
||||||
|
|
||||||
|
# Get vehicles with coordinates
|
||||||
|
vehicles = db.query("""
|
||||||
|
SELECT v.id, v.name, a.map, a.transform, a.class
|
||||||
|
FROM dune.vehicles v
|
||||||
|
JOIN dune.actors a ON v.id = a.id
|
||||||
|
WHERE a.transform IS NOT NULL
|
||||||
|
ORDER BY a.map, v.name
|
||||||
|
""") or []
|
||||||
|
|
||||||
|
# Get buildings with coordinates
|
||||||
|
buildings = db.query("""
|
||||||
|
SELECT b.id, a.map, a.transform, a.class
|
||||||
|
FROM dune.buildings b
|
||||||
|
JOIN dune.actors a ON b.id = a.id
|
||||||
|
WHERE a.transform IS NOT NULL
|
||||||
|
ORDER BY a.map
|
||||||
|
LIMIT 200
|
||||||
|
""") or []
|
||||||
|
|
||||||
|
# Parse coordinates from transform field
|
||||||
|
def parse_transform(t):
|
||||||
|
if not t:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
# Format: ("(x,y,z)","(x,y,z,w)")
|
||||||
|
import re
|
||||||
|
pos_match = re.search(r'\(([0-9.e+-]+),([0-9.e+-]+),([0-9.e+-]+)\)', str(t))
|
||||||
|
if pos_match:
|
||||||
|
return {
|
||||||
|
'x': float(pos_match.group(1)),
|
||||||
|
'y': float(pos_match.group(2)),
|
||||||
|
'z': float(pos_match.group(3))
|
||||||
|
}
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Process players
|
||||||
|
player_locations = []
|
||||||
|
for p in players:
|
||||||
|
coords = parse_transform(p.get('transform'))
|
||||||
|
if coords:
|
||||||
|
player_locations.append({
|
||||||
|
'id': p['id'],
|
||||||
|
'name': p['name'],
|
||||||
|
'map': p['map'],
|
||||||
|
'x': coords['x'],
|
||||||
|
'y': coords['y'],
|
||||||
|
'z': coords['z']
|
||||||
|
})
|
||||||
|
|
||||||
|
# Process vehicles
|
||||||
|
vehicle_locations = []
|
||||||
|
for v in vehicles:
|
||||||
|
coords = parse_transform(v.get('transform'))
|
||||||
|
if coords:
|
||||||
|
vehicle_locations.append({
|
||||||
|
'id': v['id'],
|
||||||
|
'name': v.get('name', 'Unknown'),
|
||||||
|
'map': v['map'],
|
||||||
|
'class': v.get('class', '').split('/')[-1] if v.get('class') else '',
|
||||||
|
'x': coords['x'],
|
||||||
|
'y': coords['y'],
|
||||||
|
'z': coords['z']
|
||||||
|
})
|
||||||
|
|
||||||
|
# Process buildings
|
||||||
|
building_locations = []
|
||||||
|
for b in buildings:
|
||||||
|
coords = parse_transform(b.get('transform'))
|
||||||
|
if coords:
|
||||||
|
building_locations.append({
|
||||||
|
'id': b['id'],
|
||||||
|
'map': b['map'],
|
||||||
|
'class': b.get('class', '').split('/')[-1] if b.get('class') else '',
|
||||||
|
'x': coords['x'],
|
||||||
|
'y': coords['y'],
|
||||||
|
'z': coords['z']
|
||||||
|
})
|
||||||
|
|
||||||
|
# Get unique maps
|
||||||
|
all_maps = set()
|
||||||
|
for loc in player_locations + vehicle_locations + building_locations:
|
||||||
|
if loc.get('map'):
|
||||||
|
all_maps.add(loc['map'])
|
||||||
|
maps = sorted(all_maps)
|
||||||
|
|
||||||
|
return render_template('map.html',
|
||||||
|
players=player_locations,
|
||||||
|
vehicles=vehicle_locations,
|
||||||
|
buildings=building_locations,
|
||||||
|
maps=maps)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception("Error in map route")
|
||||||
|
return render_template('map.html', db_error=f"{type(e).__name__}: {e}")
|
||||||
@@ -37,4 +37,5 @@ NAV_PAGES = [
|
|||||||
('/vehicles', 'Vehicles'),
|
('/vehicles', 'Vehicles'),
|
||||||
('/guilds', 'Guilds'),
|
('/guilds', 'Guilds'),
|
||||||
('/buildings', 'Buildings'),
|
('/buildings', 'Buildings'),
|
||||||
|
('/map', 'Map'),
|
||||||
]
|
]
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import sys
|
||||||
|
sys.path.insert(0, '.')
|
||||||
|
from app.config import load_settings
|
||||||
|
from app.services.database import DatabaseService
|
||||||
|
|
||||||
|
settings = load_settings()
|
||||||
|
db_config = {
|
||||||
|
'host': settings['database']['host'],
|
||||||
|
'port': settings['database']['port'],
|
||||||
|
'user': settings['database']['user'],
|
||||||
|
'password': settings['database']['password'],
|
||||||
|
'database': settings['database']['name'],
|
||||||
|
}
|
||||||
|
db = DatabaseService(db_config, 2, 10)
|
||||||
|
|
||||||
|
# Check sample transform data for players
|
||||||
|
sample = db.query('''
|
||||||
|
SELECT id, class, map, transform FROM dune.actors
|
||||||
|
WHERE class LIKE '%DunePlayerCharacter_%'
|
||||||
|
LIMIT 3
|
||||||
|
''')
|
||||||
|
for s in sample:
|
||||||
|
print('Class:', s['class'])
|
||||||
|
print('Map:', s['map'])
|
||||||
|
print('Transform:', s['transform'][:500] if s['transform'] else 'None')
|
||||||
|
print('---')
|
||||||
|
|
||||||
|
# Also check vehicles
|
||||||
|
print('\n=== Vehicles ===')
|
||||||
|
veh = db.query('''
|
||||||
|
SELECT id, class, map, transform FROM dune.actors
|
||||||
|
WHERE class LIKE '%Vehicle%'
|
||||||
|
LIMIT 2
|
||||||
|
''')
|
||||||
|
for v in veh:
|
||||||
|
print('Class:', v['class'])
|
||||||
|
print('Map:', v['map'])
|
||||||
|
print('Transform:', v['transform'][:500] if v['transform'] else 'None')
|
||||||
|
print('---')
|
||||||
@@ -0,0 +1,301 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Map - Dune Dashboard{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<style>
|
||||||
|
.map-container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 300px 1fr;
|
||||||
|
gap: 20px;
|
||||||
|
height: calc(100vh - 120px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-sidebar {
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
overflow-y: auto;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-sidebar h3 {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--text-light);
|
||||||
|
margin: 16px 0 8px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-sidebar h3:first-child {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-checkbox {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 6px 0;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-checkbox input {
|
||||||
|
accent-color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.location-list {
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.location-item {
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin: 2px 0;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.location-item:hover {
|
||||||
|
background: var(--hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.location-item.player { border-left: 3px solid var(--primary); }
|
||||||
|
.location-item.vehicle { border-left: 3px solid #3498db; }
|
||||||
|
.location-item.building { border-left: 3px solid var(--success); }
|
||||||
|
|
||||||
|
.map-view {
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 8px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-placeholder {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100%;
|
||||||
|
color: var(--text-muted);
|
||||||
|
padding: 40px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-placeholder-icon {
|
||||||
|
font-size: 48px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-stats {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-card {
|
||||||
|
background: var(--bg);
|
||||||
|
padding: 12px 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-card .count {
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-card .label {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-select {
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--card-bg);
|
||||||
|
color: var(--text);
|
||||||
|
font-size: 13px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coord-display {
|
||||||
|
background: var(--code-bg);
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-light);
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-map-note {
|
||||||
|
background: var(--hover);
|
||||||
|
border: 1px dashed var(--border);
|
||||||
|
padding: 16px;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-top: 16px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<h2>World Map</h2>
|
||||||
|
|
||||||
|
{% if db_error %}
|
||||||
|
<div class="error-banner danger">{{ db_error }}</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="map-stats">
|
||||||
|
<div class="stat-card">
|
||||||
|
<div class="count">{{ players|length }}</div>
|
||||||
|
<div class="label">Players</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat-card">
|
||||||
|
<div class="count">{{ vehicles|length }}</div>
|
||||||
|
<div class="label">Vehicles</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat-card">
|
||||||
|
<div class="count">{{ buildings|length }}</div>
|
||||||
|
<div class="label">Buildings</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="map-container">
|
||||||
|
<div class="map-sidebar">
|
||||||
|
<h3>Filter by Type</h3>
|
||||||
|
<label class="map-checkbox">
|
||||||
|
<input type="checkbox" id="show-players" checked onchange="updateMap()">
|
||||||
|
Players ({{ players|length }})
|
||||||
|
</label>
|
||||||
|
<label class="map-checkbox">
|
||||||
|
<input type="checkbox" id="show-vehicles" checked onchange="updateMap()">
|
||||||
|
Vehicles ({{ vehicles|length }})
|
||||||
|
</label>
|
||||||
|
<label class="map-checkbox">
|
||||||
|
<input type="checkbox" id="show-buildings" checked onchange="updateMap()">
|
||||||
|
Buildings ({{ buildings|length }})
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<h3>Filter by Map</h3>
|
||||||
|
<select class="map-select" id="map-filter" onchange="filterMap()">
|
||||||
|
<option value="">All Maps</option>
|
||||||
|
{% for map in maps %}
|
||||||
|
<option value="{{ map }}">{{ map }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<h3>Players</h3>
|
||||||
|
<div class="location-list" id="player-list">
|
||||||
|
{% for p in players %}
|
||||||
|
<div class="location-item player" data-type="player" data-map="{{ p.map }}" data-x="{{ p.x }}" data-y="{{ p.y }}" data-z="{{ p.z }}" data-name="{{ p.name }}" onclick="showCoords(this)">
|
||||||
|
<span>{{ p.name }}</span>
|
||||||
|
<span style="color:var(--text-muted)">{{ p.map }}</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% if not players %}
|
||||||
|
<div style="color:var(--text-muted);font-size:12px;padding:8px;">No player locations</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Vehicles</h3>
|
||||||
|
<div class="location-list" id="vehicle-list">
|
||||||
|
{% for v in vehicles %}
|
||||||
|
<div class="location-item vehicle" data-type="vehicle" data-map="{{ v.map }}" data-x="{{ v.x }}" data-y="{{ v.y }}" data-z="{{ v.z }}" data-name="{{ v.name }} ({{ v.class }})" onclick="showCoords(this)">
|
||||||
|
<span>{{ v.name|truncate(15) }}</span>
|
||||||
|
<span style="color:var(--text-muted)">{{ v.map }}</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% if not vehicles %}
|
||||||
|
<div style="color:var(--text-muted);font-size:12px;padding:8px;">No vehicle locations</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Buildings</h3>
|
||||||
|
<div class="location-list" id="building-list">
|
||||||
|
{% for b in buildings[:50] %}
|
||||||
|
<div class="location-item building" data-type="building" data-map="{{ b.map }}" data-x="{{ b.x }}" data-y="{{ b.y }}" data-z="{{ b.z }}" data-name="{{ b.class }}" onclick="showCoords(this)">
|
||||||
|
<span>{{ b.class|truncate(20) }}</span>
|
||||||
|
<span style="color:var(--text-muted)">{{ b.map }}</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% if not buildings %}
|
||||||
|
<div style="color:var(--text-muted);font-size:12px;padding:8px;">No building locations</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if buildings|length > 50 %}
|
||||||
|
<div style="color:var(--text-muted);font-size:11px;padding:8px;">+{{ buildings|length - 50 }} more</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="map-view">
|
||||||
|
<div class="map-placeholder">
|
||||||
|
<div class="map-placeholder-icon">🗺️</div>
|
||||||
|
<h3>Map Image Coming Soon</h3>
|
||||||
|
<p>This is a prototype showing coordinate data.<br>Once you source a map image, markers will be overlaid here.</p>
|
||||||
|
<div class="no-map-note">
|
||||||
|
<strong>Data available:</strong><br>
|
||||||
|
Players: {{ players|length }} locations<br>
|
||||||
|
Vehicles: {{ vehicles|length }} locations<br>
|
||||||
|
Buildings: {{ buildings|length }} locations<br><br>
|
||||||
|
<em>Coordinates are extracted from the game world. Once a map image is added, these will appear as clickable markers.</em>
|
||||||
|
</div>
|
||||||
|
<div id="selected-coords" style="display:none;margin-top:16px;">
|
||||||
|
<strong>Selected:</strong>
|
||||||
|
<div class="coord-display" id="coord-display"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let currentFilter = '';
|
||||||
|
|
||||||
|
function showCoords(el) {
|
||||||
|
const type = el.dataset.type;
|
||||||
|
const name = el.dataset.name;
|
||||||
|
const map = el.dataset.map;
|
||||||
|
const x = parseFloat(el.dataset.x);
|
||||||
|
const y = parseFloat(el.dataset.y);
|
||||||
|
const z = parseFloat(el.dataset.z);
|
||||||
|
|
||||||
|
document.getElementById('selected-coords').style.display = 'block';
|
||||||
|
document.getElementById('coord-display').innerHTML =
|
||||||
|
`<strong>${name}</strong><br>` +
|
||||||
|
`Map: ${map}<br>` +
|
||||||
|
`X: ${x.toFixed(2)} | Y: ${y.toFixed(2)} | Z: ${z.toFixed(2)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterMap() {
|
||||||
|
currentFilter = document.getElementById('map-filter').value;
|
||||||
|
updateMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMap() {
|
||||||
|
const showPlayers = document.getElementById('show-players').checked;
|
||||||
|
const showVehicles = document.getElementById('show-vehicles').checked;
|
||||||
|
const showBuildings = document.getElementById('show-buildings').checked;
|
||||||
|
|
||||||
|
// Filter lists
|
||||||
|
document.querySelectorAll('#player-list .location-item').forEach(el => {
|
||||||
|
el.style.display = (showPlayers && (!currentFilter || el.dataset.map === currentFilter)) ? 'flex' : 'none';
|
||||||
|
});
|
||||||
|
document.querySelectorAll('#vehicle-list .location-item').forEach(el => {
|
||||||
|
el.style.display = (showVehicles && (!currentFilter || el.dataset.map === currentFilter)) ? 'flex' : 'none';
|
||||||
|
});
|
||||||
|
document.querySelectorAll('#building-list .location-item').forEach(el => {
|
||||||
|
el.style.display = (showBuildings && (!currentFilter || el.dataset.map === currentFilter)) ? 'flex' : 'none';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
Reference in new issue
Block a user