Add map image support with coordinate mapping to pixels

This commit is contained in:
Reditus committed 2026-05-15 03:40:15 +01:00
1 parent 3d63950d01
commit d769c3ef86
5 files changed
+255 -11

No files matched your search

+25
View File
@@ -69,6 +69,31 @@ DEFAULTS = {
'check_interval_hours': 24,
'renewal_days_before_expiry': 30,
},
'maps': {
'default_map': 'DeepDesert',
'DeepDesert': {
'image': 'maps/Deep_Desert_Map1.jpg',
'bounds': {
'min_x': 466906,
'max_x': 466907,
'min_y': -620339,
'max_y': -620340
},
'flip_y': False,
'image_size': {'width': 1200, 'height': 800}
},
'HaggaBasin': {
'image': None,
'bounds': {
'min_x': 21352,
'max_x': 23166,
'min_y': 233981,
'max_y': 237943
},
'flip_y': False,
'image_size': {'width': 800, 'height': 600}
}
},
}
+41 -1
View File
@@ -557,11 +557,51 @@ def register_routes(app, services, settings):
all_maps.add(loc['map'])
maps = sorted(all_maps)
# Get map configuration from settings
map_config = settings.get('maps', {})
default_map = map_config.get('default_map', 'DeepDesert')
# Calculate pixel positions for markers
def to_pixel_coords(x, y, map_name):
cfg = map_config.get(map_name, {})
bounds = cfg.get('bounds', {})
img_size = cfg.get('image_size', {'width': 1000, 'height': 600})
min_x = bounds.get('min_x', 0)
max_x = bounds.get('max_x', 1)
min_y = bounds.get('min_y', 0)
max_y = bounds.get('max_y', 1)
if max_x == min_x or max_y == min_y:
return None, None
# Scale to image dimensions
px = ((x - min_x) / (max_x - min_x)) * img_size['width']
py = ((y - min_y) / (max_y - min_y)) * img_size['height']
# Flip Y if needed (some coordinate systems have inverted Y)
if cfg.get('flip_y', False):
py = img_size['height'] - py
return int(px), int(py)
# Add pixel positions
for p in player_locations:
p['px'], p['py'] = to_pixel_coords(p['x'], p['y'], p.get('map', ''))
for v in vehicle_locations:
v['px'], v['py'] = to_pixel_coords(v['x'], v['y'], v.get('map', ''))
for b in building_locations:
b['px'], b['py'] = to_pixel_coords(b['x'], b['y'], b.get('map', ''))
return render_template('map.html',
players=player_locations,
vehicles=vehicle_locations,
buildings=building_locations,
maps=maps)
maps=maps,
map_config=map_config,
default_map=default_map)
except Exception as e:
logger.exception("Error in map route")
return render_template('map.html', db_error=f"{type(e).__name__}: {e}")
+52
View File
@@ -0,0 +1,52 @@
import sys
sys.path.insert(0, '.')
from app.config import load_settings
from app.services.database import DatabaseService
import re
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)
# Get count by map
counts = db.query('''
SELECT map, COUNT(*) as cnt
FROM dune.actors
WHERE transform IS NOT NULL
GROUP BY map
ORDER BY cnt DESC
''')
print('Map coordinate counts:')
for c in counts:
print(f" {c['map']}: {c['cnt']} items")
# Get bounds for HaggaBasin (seems to have more)
print('\n=== HaggaBasin bounds ===')
coords = db.query('''
SELECT transform FROM dune.actors
WHERE map = 'HaggaBasin' AND transform IS NOT NULL
LIMIT 500
''')
points = []
for a in coords:
t = a.get('transform')
if t:
pos_match = re.search(r'\(([0-9.e+-]+),([0-9.e+-]+),([0-9.e+-]+)\)', str(t))
if pos_match:
points.append((float(pos_match.group(1)), float(pos_match.group(2))))
if points:
x_vals = [p[0] for p in points]
y_vals = [p[1] for p in points]
print(f'Min X: {min(x_vals):.1f}, Max X: {max(x_vals):.1f}')
print(f'Min Y: {min(y_vals):.1f}, Max Y: {max(y_vals):.1f}')
print(f'X range: {max(x_vals) - min(x_vals):.1f}')
print(f'Y range: {max(y_vals) - min(y_vals):.1f}')
Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

+137 -10
View File
@@ -148,6 +148,88 @@
font-size: 13px;
color: var(--text-muted);
}
.map-display {
position: relative;
width: 100%;
height: 100%;
overflow: auto;
background: #1a1a1a;
}
.map-image-container {
position: relative;
display: inline-block;
min-width: 1200px;
min-height: 800px;
}
.map-image {
width: 100%;
max-width: 100%;
height: auto;
display: block;
}
.map-marker {
position: absolute;
width: 12px;
height: 12px;
border-radius: 50%;
cursor: pointer;
transform: translate(-50%, -50%);
border: 2px solid #fff;
box-shadow: 0 2px 4px rgba(0,0,0,0.5);
transition: transform 0.15s;
z-index: 10;
}
.map-marker:hover {
transform: translate(-50%, -50%) scale(1.5);
z-index: 100;
}
.map-marker.player {
background: var(--primary);
}
.map-marker.vehicle {
background: #3498db;
}
.map-marker.building {
background: var(--success);
}
.map-marker-tooltip {
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
background: rgba(0,0,0,0.85);
color: #fff;
padding: 4px 8px;
border-radius: 4px;
font-size: 11px;
white-space: nowrap;
display: none;
margin-bottom: 4px;
}
.map-marker:hover .map-marker-tooltip {
display: block;
}
.map-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
color: var(--text-muted);
padding: 40px;
text-align: center;
}
</style>
<h2>World Map</h2>
@@ -240,22 +322,67 @@
</div>
<div class="map-view">
{% set current_map = map_config.get(default_map, {}) %}
{% set map_image = current_map.get('image') %}
{% if map_image %}
<div class="map-display">
<div class="map-image-container">
<img src="{{ url_for('static', filename=map_image) }}" class="map-image" alt="Map">
{# Players #}
{% if show_players is not defined %}{% set show_players = true %}{% endif %}
{% if show_players %}
{% for p in players %}
{% if p.px is not none and p.py is not none %}
<div class="map-marker player" style="left:{{ p.px }}px;top:{{ p.py }}px;" title="{{ p.name }}">
<span class="map-marker-tooltip">{{ p.name }} (Player)</span>
</div>
{% endif %}
{% endfor %}
{% endif %}
{# Vehicles #}
{% if show_vehicles is not defined %}{% set show_vehicles = true %}{% endif %}
{% if show_vehicles %}
{% for v in vehicles %}
{% if v.px is not none and v.py is not none %}
<div class="map-marker vehicle" style="left:{{ v.px }}px;top:{{ v.py }}px;" title="{{ v.class }}">
<span class="map-marker-tooltip">{{ v.class.split('/')[-1].split('.')[0] }} (Vehicle)</span>
</div>
{% endif %}
{% endfor %}
{% endif %}
{# Buildings #}
{% if show_buildings is not defined %}{% set show_buildings = true %}{% endif %}
{% if show_buildings %}
{% for b in buildings[:30] %}
{% if b.px is not none and b.py is not none %}
<div class="map-marker building" style="left:{{ b.px }}px;top:{{ b.py }}px;" title="{{ b.class }}">
<span class="map-marker-tooltip">{{ b.class.split('/')[-1].split('.')[0] }} (Building)</span>
</div>
{% endif %}
{% endfor %}
{% endif %}
</div>
</div>
{% else %}
<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>
<h3>No Map Configured</h3>
<p>Configure a map in settings to display coordinates.</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>
Players: {{ players|length }}<br>
Vehicles: {{ vehicles|length }}<br>
Buildings: {{ buildings|length }}
</div>
</div>
{% endif %}
<div id="selected-coords" style="display:none;margin-top:16px;">
<strong>Selected:</strong>
<div class="coord-display" id="coord-display"></div>
</div>
</div>
</div>