Skip to content

Commit

Permalink
match2 output (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Shashank Atreya <Liquipedia>
  • Loading branch information
godarkrai authored Mar 16, 2022
1 parent 914c57f commit efaaeae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
],
"messages": [
"dota2webapi-detected-matchid-number",
"dota2db-dialog-match2-output",
"dota2webapi-heroes.json",
"dota2webapi-items.json"
],
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dota2webapi-api-description": "Get data of a match from the Dota 2 Web API.",
"dota2webapi-api-matchid-description": "The ID of the match of which you want to pull data from the Dota 2 Web API",
"dota2webapi-api-data-description": "Which data to get.",
"dota2db-dialog-match2-output": "Match2 Output (Only works with bracket details)",
"dota2webapi-error-non-strictly-positive-match-id": "You must select a numeric match ID > 0",
"dota2webapi-error-retrieving-local-data": "Error while retrieving local data",
"dota2webapi-error-missing-api-key": "Dota 2 Web API key is missing",
Expand Down
42 changes: 33 additions & 9 deletions resources/scripts/ext.dota2WebApi.toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ $( function() {
)
);
}
output += '</table>';
output += '</table><br>';
output += '<input type="checkbox" id="dota2db-dialog-match2-output" name="dota2db-dialog-match2-output">';
output += '<label for="dota2db-dialog-match2-output">' + mw.message( 'dota2db-dialog-match2-output' ).text() + '</label><br>';

return output;
}
Expand Down Expand Up @@ -80,7 +82,7 @@ $( function() {
$( '#' + configuration.id + ' .dota2webapi-result tr:odd' ).addClass( 'odd' );
}

function processGameForBracketDetails( params ) {
function processGameForBracketDetails( params, match2 ) {
var winningFaction = $( '#insert-bracket-match-details-dialog .dota2webapi-result .match-' + params.row + ' .match-data' ).data( 'winningFaction' ),
matchID = $( '#insert-bracket-match-details-dialog .dota2webapi-result .match-' + params.row + ' .match-data' ).data( 'matchid' ),
winningTeamName = $( '#insert-bracket-match-details-dialog .dota2webapi-result .match-' + params.row + ' .' + winningFaction + '-side' ).text(),
Expand Down Expand Up @@ -112,14 +114,25 @@ $( function() {
team2Bans = radiantBans.replace( /\{r\}/g, 2 );
}

text += '|match' + params.matchIndex + '={{Match\n';
if ( match2 ) {
text += '|map' + params.matchIndex + '={{Map\n';
} else {
text += '|match' + params.matchIndex + '={{Match\n';
}

text += '|team1side=' + team1Side + '\n';
text += team1Picks;
text += team1Bans;
text += '|team2side=' + team2Side + '\n';
text += team2Picks;
text += team2Bans;
text += $( '#insert-bracket-match-details-dialog .dota2webapi-result .match-' + params.row + ' .match-data' ).data( 'wikitextEnd' ).replace( '{w}', winningTeam );
if ( match2 ) {
text += $( '#insert-bracket-match-details-dialog .dota2webapi-result .match-' + params.row + ' .match-data' )
.data( 'wikitextEnd' ).replace( 'win', 'winner' ).replace( '{w}', winningTeam );
} else {
text += $( '#insert-bracket-match-details-dialog .dota2webapi-result .match-' + params.row + ' .match-data' )
.data( 'wikitextEnd' ).replace( '{w}', winningTeam );
}

return { winningTeam: winningTeam, matchID: matchID, text: text };
}
Expand Down Expand Up @@ -322,7 +335,7 @@ $( function() {
var selection,
matchIDs,
matchIDsPars = [ ],
vars, i = 0;
vars, i = 0, match2 = false;
selection = context.$textarea.textSelection( 'getSelection' ).replace( /\s+$/, '' ).replace( /^\s+/, '' );

if ( selection === '' ) {
Expand All @@ -345,6 +358,9 @@ $( function() {
title: 'Insert bracket match details',
id: 'insert-bracket-match-details-dialog',
insertCallback: function() {
if ( $( '#dota2db-dialog-match2-output' ).is( ':checked' ) ) {
match2 = true;
}
var wikitext, team1, team2,
s, sStart = '', sMatchID = '', sEnd = ''; // , replaceText = '';
var $checked = $( '#insert-bracket-match-details-dialog input[name="insert-selection"]:checked' );
Expand All @@ -358,7 +374,11 @@ $( function() {
team1 = $checked.parent().siblings( '.series-title' ).find( '.team1' ).text();
team2 = $checked.parent().siblings( '.series-title' ).find( '.team2' ).text();

sStart = '{{BracketMatchSummary\n';
if ( !match2 ) {
sStart = '{{BracketMatchSummary\n';
} else {
sStart = '';
}
sStart += '|date=';
sStart += date;
sStart += '\n';
Expand All @@ -371,7 +391,7 @@ $( function() {
team2: team2,
matchIndex: i + 1,
row: matches[ i ]
} );
}, match2 );

// replaceText += processedGame.matchID + '\n';

Expand All @@ -380,7 +400,11 @@ $( function() {
sEnd += processedGame.text;
}

sEnd += '}}';
if ( !match2 ) {
sEnd += '}}';
} else {
sEnd = String( sEnd );
}

s = sStart + sMatchID + sEnd;
} else if ( $checked.attr( 'class' ) === 'match-radio' ) {
Expand All @@ -391,7 +415,7 @@ $( function() {
team2: team2,
matchIndex: 1,
row: $checked.attr( 'rel' )
} );
}, match2 );
s = processedGame.text;
// replaceText += processedGame.matchID + '\n';
}
Expand Down

0 comments on commit efaaeae

Please sign in to comment.