Fix results template fighter names and prevent duplicate match_video initialization

- Added guard in loadTemplate() to skip if template already loaded
- Fixed executePhaseTransition() to properly pass match data to results template
- Removed duplicate match_video loading logic in fetchOverlayData()
- Template names are now normalized to prevent case-sensitivity issues
parent 80e69d88
......@@ -355,7 +355,16 @@ class WebOverlayController {
* @param {string} templateName - Name of the template (e.g., 'fixtures', 'results', 'match')
*/
async loadTemplate(templateName) {
this.log(`Loading template: ${templateName}`);
// Normalize template name
const normalizedName = templateName.replace('.html', '').toLowerCase();
// Guard: Skip if already loading or already showing this template
if (this.currentTemplate === normalizedName) {
this.log(`Template "${normalizedName}" already loaded, skipping`);
return true;
}
this.log(`Loading template: ${templateName} (current: ${this.currentTemplate})`);
try {
// Map template names to template paths
......@@ -411,7 +420,7 @@ class WebOverlayController {
// Load the template
this.overlayIframe.src = templatePath;
this.currentTemplate = templateName;
this.currentTemplate = normalizedName; // Store normalized name
this.log(`Template loaded: ${templatePath}`);
// Emit template loaded event
......@@ -638,17 +647,8 @@ class WebOverlayController {
}
// Legacy support: Also check is_playing_match_video flag
const wasPlayingMatchVideo = this.overlayData.is_playing_match_video;
const isNowPlayingMatchVideo = response.is_playing_match_video;
// Handle match video state changes (fallback for older API)
// Only do this if we haven't already handled the phase transition
if (isNowPlayingMatchVideo && !wasPlayingMatchVideo && newPhase === 'match' && this.currentTemplate !== 'match_video') {
// Match video just started - stop rotation and load match_video template
this.log('Match video started - stopping template rotation');
this.stopTemplateRotation();
this.loadTemplate('match_video');
}
// This is now handled by the phase transition logic above
// No need for duplicate handling here
this.overlayData = response;
......@@ -727,15 +727,18 @@ class WebOverlayController {
// Match phase - stop rotation and show match template
this.log('Match phase - stopping rotation, loading match_video template');
this.stopTemplateRotation();
// Only load if not already showing match_video
if (this.currentTemplate !== 'match_video') {
this.loadTemplate('match_video');
}
break;
case 'result':
// Result phase - stop rotation and show results template
this.log('Result phase - stopping rotation, loading results template');
this.stopTemplateRotation();
// Send result data to template before loading
// Use 'resultUpdate' message type which the web adapter handles
// Build result data with proper match information
const resultData = {
outcome: data.outcome || data.result,
result: data.result,
......@@ -743,13 +746,23 @@ class WebOverlayController {
match_id: data.match_id,
fixture_id: data.fixture_id,
winningOutcomes: data.winningOutcomes || [],
match: data.match || null
// Ensure match data is properly included with fighter names
match: data.match || (this.overlayData ? this.overlayData.match : null) || null
};
// Log the match data for debugging
this.log('Result data match info:', resultData.match);
this.log('Sending resultUpdate to overlay:', resultData);
// Send result data to template before loading
this.sendMessageToOverlay('resultUpdate', resultData);
// Also send as dataUpdated for compatibility
this.sendMessageToOverlay('dataUpdated', resultData);
// Only load if not already showing results
if (this.currentTemplate !== 'results') {
this.loadTemplate('results');
}
break;
case 'idle':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment