fork/replay-manager-for-slippi
git clone https://git.julia.blue/fork/replay-manager-for-slippi
e87008e
2.3.5
1import { MatchResult , SlotState } from '@parry-gg/client' ; 2import { Backup , Report , VideogameAssetOff } from '@mui/icons-material' ; 3import { 4Avatar , 5Box , 6Button , 7CircularProgress , 8Dialog , 9DialogActions , 10DialogContent , 11DialogContentText , 12DialogTitle , 13Divider , 14IconButton , 15Stack , 16Tooltip , 17Typography , 18} from '@mui/material' ; 19import { MouseEventHandler , useEffect , useState } from 'react' ; 20import styled from '@emotion/styled' ; 21import { 22ChallongeMatchItem , 23EnforcerSetting , 24EnforceState , 25EnforceStatus , 26Id , 27Mode , 28Player , 29Replay , 30ReportSettings , 31Set , 32StartggGame , 33StartggGameSelection , 34StartggSet , 35State , 36Stream , 37} from '../common/types' ; 38import { 39characterNames , 40characterStartggIds , 41isValidCharacter , 42stageNames , 43stageStartggIds , 44startggCharacterIds , 45startggStageIds , 46} from '../common/constants' ; 47import LabeledCheckbox from './LabeledCheckbox' ; 48import getCharacterIcon from './getCharacterIcon' ; 49import { assertInteger , assertString } from '../common/asserts' ; 50 51const bgColor = 'rgba(34, 178, 76, 0.2)' ; 52 53function getCharacterIconInner ( 54characterId :number | undefined , 55costumeIndex ?:number , 56) { 57if ( characterId === undefined ) { 58return getCharacterIcon ( 31 , 0 ); 59} 60if ( costumeIndex === undefined ) { 61return getCharacterIcon ( characterId , 0 ); 62} 63return getCharacterIcon ( characterId , costumeIndex ); 64} 65 66const EntrantSection = styled ( Stack ) ` 67align-items: center; 68width: 50%; 69` ; 70 71const EntrantText = styled ( Stack ) ` 72margin: 0 4px; 73min-width: 0; 74` ; 75 76const EntrantScore = styled ( EntrantText ) ` 77width: 16px; 78` ; 79 80const Name = styled . div ` 81overflow-x: hidden; 82text-overflow: ellipsis; 83white-space: nowrap; 84` ; 85 86function isValid ( player :Player ) { 87return player . playerType === 0 || player . playerType === 1 ; 88} 89 90function setAndReplaysValid ( selectedReplays :Replay [], set :Set , mode :Mode ) { 91if ( selectedReplays . length === 0 ) { 92return { valid :false , reason :'No replays selected' }; 93} 94if ( mode === Mode . CHALLONGE && set . state === State . COMPLETED ) { 95return { valid :false , reason :'Set already completed' }; 96} 97 98let reason = '' ; 99const valid = selectedReplays . every (( replay , i ) => { 100if ( set . id === 0 ) { 101if ( ! reason ) { 102reason = 'No set selected' ; 103} 104return false ; 105} 106if ( Number . isInteger ( set . id ) && ( set . id as number ) < 0 ) { 107if ( ! reason ) { 108reason = 'Tiebreaker sets cannot be reported' ; 109} 110return false ; 111} 112 113const validPlayers = replay . players . filter ( isValid ); 114if ( 115validPlayers . length !== 116set . entrant1Participants . length + set . entrant2Participants . length 117) { 118if ( ! reason ) { 119reason = `Game ${ i + 1 } has wrong number of players` ; 120} 121return false ; 122} 123if ( ! ( validPlayers . find (( player ) => player . isWinner ) || replay . timeout )) { 124if ( ! reason ) { 125reason = `Game ${ i + 1 } does not have a winner` ; 126} 127return false ; 128} 129if ( ! validPlayers . every (( player ) => player . playerOverrides . entrantId )) { 130if ( ! reason ) { 131reason = `Game ${ i + 1 } does not have all players assigned` ; 132} 133return false ; 134} 135return true ; 136}); 137 138return { valid, reason}; 139} 140 141function getScoresAndWinnerId ( selectedReplays :Replay []) { 142let gameCount = 0 ; 143const gameWins = new Map < Id , number >(); 144let leaderId :Id = 0 ; 145let leaderWins = 0 ; 146selectedReplays . forEach (( replay ) => { 147const gameWinnerId = replay . players 148. filter ( isValid ) 149. find (( player ) => player . isWinner )?. playerOverrides . entrantId ; 150if ( ! gameWinnerId ) { 151return ; 152} 153 154const n = ( gameWins . get ( gameWinnerId ) || 0 ) + 1 ; 155if ( n > leaderWins ) { 156leaderWins = n ; 157leaderId = gameWinnerId ; 158} 159gameCount += 1 ; 160gameWins . set ( gameWinnerId , n ); 161}); 162 163return { 164scores :gameWins , 165winnerId :leaderWins / gameCount > 0.5 ?leaderId :0 , 166}; 167} 168 169function getDisplayNameFromPlayer ( player ?:Player ) { 170return player ?. playerOverrides . displayName || player ?. displayName ; 171} 172 173function ReportButton ({ 174 disabled, 175 elevate, 176 onClick, 177} :{ 178disabled ?:boolean ; 179elevate :boolean ; 180onClick ?:MouseEventHandler < HTMLButtonElement >; 181}) { 182return ( 183< Button 184disabled = { disabled } 185endIcon = {< Backup />} 186onClick = { onClick } 187size = "small" 188variant = "contained" 189sx = {{ 190zIndex :( theme ) => ( elevate ?theme . zIndex . drawer + 2 :undefined ), 191}} 192> 193Report 194</ Button > 195); 196} 197ReportButton . defaultProps = { 198disabled :false , 199onClick :undefined , 200}; 201 202export default function SetControls ({ 203 copyReplays, 204 deleteReplays, 205 reportChallongeSet, 206 reportStartggSet, 207 reportParryggSet, 208 reportOfflineModeSet, 209 setReportSettings, 210 resetGuide, 211 mode, 212 isCopying, 213 copyDisabled, 214 isDeleting, 215 dqId, 216 hasRemainingReplays, 217 reportSettings, 218 selectedReplays, 219 set, 220 elevate, 221 enforcerVersion, 222 enforcerSetting, 223 smuggleCostumeIndex, 224 wouldDeleteCopyDir, 225 replayLoadCount, 226 undoSubdir, 227} :{ 228copyReplays :( 229updatedSetFields ?:{ 230id :Id ; 231sggId :number | null ; 232completedAtMs :number ; 233stream :Stream | null ; 234}, 235violators ?:{ 236checkNames :Map < string , boolean >; 237displayName :string ; 238entrantId :Id ; 239}[], 240) => Promise < void >; 241deleteReplays :() => Promise < void >; 242reportChallongeSet :( 243matchId :string , 244items :ChallongeMatchItem [], 245) => Promise < Set >; 246reportStartggSet :( 247set :StartggSet , 248originalSet :Set , 249) => Promise < Set | undefined >; 250reportParryggSet :( 251result :MatchResult . AsObject , 252originalSet :Set , 253) => Promise < Set | undefined >; 254reportOfflineModeSet :( set :StartggSet ) => Promise < Set >; 255setReportSettings :( newReportSettings :ReportSettings ) => Promise < void >; 256resetGuide :() => void ; 257mode :Mode ; 258isCopying :boolean ; 259copyDisabled :boolean ; 260isDeleting :boolean ; 261dqId :Id ; 262hasRemainingReplays :boolean ; 263reportSettings :ReportSettings ; 264selectedReplays :Replay []; 265set :Set ; 266elevate :boolean ; 267enforcerVersion :string ; 268enforcerSetting :EnforcerSetting ; 269smuggleCostumeIndex :boolean ; 270wouldDeleteCopyDir :boolean ; 271replayLoadCount :number ; 272undoSubdir :string ; 273}) { 274const [ open , setOpen ] = useState ( false ); 275const [ reporting , setReporting ] = useState ( false ); 276const [ reportError , setReportError ] = useState ( '' ); 277const [ reportErrorOpen , setReportErrorOpen ] = useState ( false ); 278const [ startggSet , setStartggSet ] = useState < StartggSet >({ 279setId :set . id , 280winnerId :0 , 281isDQ :false , 282gameData :[], 283}); 284const [ challongeMatchItems , setChallongeMatchItems ] = useState < 285ChallongeMatchItem [] 286>([ 287{ 288participant_id :'' , 289score_set :'' , 290rank :0 , 291advancing :false , 292}, 293{ 294participant_id :'' , 295score_set :'' , 296rank :0 , 297advancing :false , 298}, 299]); 300const [ parryggMatchResult , setParryggMatchResult ] = 301useState < MatchResult . AsObject >({ 302slotsList :[ 303{ 304slot :0 , 305score :0 , 306state :SlotState . SLOT_STATE_NUMERIC , 307}, 308{ 309slot :1 , 310score :0 , 311state :SlotState . SLOT_STATE_NUMERIC , 312}, 313], 314}); 315 316const [ enforcerResultOpen , setEnforcerResultOpen ] = useState ( false ); 317const [ enforceState , setEnforceState ] = useState < EnforceState >({ 318status :EnforceStatus . DONE , 319fileNameToPlayerFailures :new Map (), 320}); 321useEffect (() => { 322window . electron . onEnforceState ( 323( event , newEnforceState , newReplayLoadCount ) => { 324if ( newReplayLoadCount >= replayLoadCount ) { 325setEnforceState ( newEnforceState ); 326} 327}, 328); 329}, [ replayLoadCount ]); 330const selectedReplaysWithEnforceErrors = 331enforceState . status === EnforceStatus . DONE 332 ?selectedReplays . filter (( replay ) => 333enforceState . fileNameToPlayerFailures . has ( replay . fileName ), 334) 335 :[]; 336let showEnforcerPopup = false ; 337if ( enforcerSetting === EnforcerSetting . POP_UP_ALL ) { 338showEnforcerPopup = selectedReplaysWithEnforceErrors . length > 0 ; 339} else if ( enforcerSetting === EnforcerSetting . POP_UP_GOOMWAVE ) { 340showEnforcerPopup = selectedReplaysWithEnforceErrors . some (( replay ) => 341enforceState . fileNameToPlayerFailures 342. get ( replay . fileName ) ! 343. some (( enforcerPlayerError ) => 344enforcerPlayerError . checkNames . includes ( 'GoomWave Clamping' ), 345), 346); 347} 348 349const isDq = dqId === set . entrant1Id || dqId === set . entrant2Id ; 350const validSelections = setAndReplaysValid ( selectedReplays , set , mode ); 351let scores = new Map < Id , number >(); 352let winnerId :Id = 0 ; 353if ( validSelections . valid ) { 354({ scores, winnerId} = getScoresAndWinnerId ( selectedReplays )); 355} else if ( isDq ) { 356if ( dqId === set . entrant1Id ) { 357scores . set ( set . entrant1Id , - 1 ); 358scores . set ( set . entrant2Id , 0 ); 359winnerId = set . entrant2Id ; 360} else { 361scores . set ( set . entrant1Id , 0 ); 362scores . set ( set . entrant2Id , - 1 ); 363winnerId = set . entrant1Id ; 364} 365} 366 367const entrant1SetScore = scores . get ( set . entrant1Id ) || 0 ; 368const entrant2SetScore = scores . get ( set . entrant2Id ) || 0 ; 369 370const getStartggSet = () :StartggSet => { 371if ( isDq ) { 372return { setId :set . id , winnerId, isDQ :true , gameData :[] }; 373} 374 375const gameData :StartggGame [] = []; 376selectedReplays . forEach (( replay , i ) => { 377const gameWinnerId = replay . players . find (( player ) => player . isWinner ) 378?. playerOverrides . entrantId ; 379if ( ! gameWinnerId ) { 380return ; 381} 382 383const originalEntrant1Score = set . gameScores [ i ]?. entrant1Score ?? 0 ; 384const originalEntrant2Score = set . gameScores [ i ]?. entrant2Score ?? 0 ; 385let entrant1CostumeOffset = Math . floor ( originalEntrant1Score / 100 ) * 100 ; 386let entrant2CostumeOffset = Math . floor ( originalEntrant2Score / 100 ) * 100 ; 387let entrant1Stocks = originalEntrant1Score % 100 ; 388let entrant2Stocks = originalEntrant2Score % 100 ; 389const participantIdToSelection = new Map < Id , StartggGameSelection >(); 390const validPlayers = replay . players . filter ( 391( player ) => 392isValid ( player ) && isValidCharacter ( player . externalCharacterId ), 393); 394validPlayers . forEach (( player ) => { 395const { entrantId, participantId} = player . playerOverrides ; 396participantIdToSelection . set ( participantId , { 397characterId :characterStartggIds . get ( player . externalCharacterId ) ! , 398 entrantId, 399}); 400if ( validPlayers . length === 2 ) { 401if ( entrantId === set . entrant1Id ) { 402if ( smuggleCostumeIndex ) { 403entrant1CostumeOffset = ( player . costumeIndex + 1 ) * 100 ; 404} 405if ( player . stocksRemaining >= 0 ) { 406entrant1Stocks = player . stocksRemaining ; 407} 408} else { 409if ( smuggleCostumeIndex ) { 410entrant2CostumeOffset = ( player . costumeIndex + 1 ) * 100 ; 411} 412if ( player . stocksRemaining >= 0 ) { 413entrant2Stocks = player . stocksRemaining ; 414} 415} 416} 417}); 418const selections = [ 419 ...set . entrant1Participants . map ( 420( participant ) => participantIdToSelection . get ( participant . id ) ! , 421), 422 ...set . entrant2Participants . map ( 423( participant ) => participantIdToSelection . get ( participant . id ) ! , 424), 425]; 426gameData . push ({ 427entrant1Score :entrant1CostumeOffset + entrant1Stocks , 428entrant2Score :entrant2CostumeOffset + entrant2Stocks , 429gameNum :i + 1 , 430stageId :stageStartggIds . get ( replay . stageId ), 431 selections, 432winnerId :assertInteger ( gameWinnerId ), 433}); 434}); 435return { setId :set . id , winnerId, isDQ :false , gameData}; 436}; 437 438const getChallongeMatchItems = () :ChallongeMatchItem [] => [ 439{ 440participant_id :set . entrant1Id . toString ( 10 ), 441score_set :entrant1SetScore . toString ( 10 ), 442rank :winnerId === set . entrant1Id ?1 :2 , 443advancing :winnerId === set . entrant1Id , 444}, 445{ 446participant_id :set . entrant2Id . toString ( 10 ), 447score_set :entrant2SetScore . toString ( 10 ), 448rank :winnerId === set . entrant2Id ?1 :2 , 449advancing :winnerId === set . entrant2Id , 450}, 451]; 452 453const getMatchResult = () :MatchResult . AsObject => { 454const entrant1Dq = isDq && dqId === set . entrant1Id ; 455const entrant2Dq = isDq && dqId === set . entrant2Id ; 456 457return { 458slotsList :[ 459{ 460slot :0 , 461score :entrant1Dq ?0 :entrant1SetScore , 462state :entrant1Dq 463 ?SlotState . SLOT_STATE_DQ 464 :SlotState . SLOT_STATE_NUMERIC , 465}, 466{ 467slot :1 , 468score :entrant2Dq ?0 :entrant2SetScore , 469state :entrant2Dq 470 ?SlotState . SLOT_STATE_DQ 471 :SlotState . SLOT_STATE_NUMERIC , 472}, 473], 474}; 475}; 476 477let deleteOverrideReason = '' ; 478if ( set . fullRoundText === 'Grand Final' && hasRemainingReplays ) { 479deleteOverrideReason = 'possible Grand Finals Reset replays detected' ; 480} else if ( wouldDeleteCopyDir ) { 481deleteOverrideReason = 'would delete replays in copy folder' ; 482} 483 484let reportCopyDeleteIntent = 'Report' ; 485if ( reportSettings . alsoCopy || undoSubdir ) { 486reportCopyDeleteIntent += ', Copy' ; 487} 488if ( 489( reportSettings . alsoCopy && 490reportSettings . alsoDelete && 491deleteOverrideReason . length === 0 ) || 492undoSubdir 493) { 494reportCopyDeleteIntent += ', Delete' ; 495} 496 497let reportCopyDeleteButton = reportCopyDeleteIntent ; 498if ( enforceState . status === EnforceStatus . PENDING ) { 499reportCopyDeleteButton = 'Checking with SLP Enforcer' ; 500} else if (( reportSettings . alsoCopy || undoSubdir ) && copyDisabled ) { 501reportCopyDeleteButton = 'Copy destination not set' ; 502} else if (( reportSettings . alsoCopy || undoSubdir ) && isCopying ) { 503reportCopyDeleteButton = 'Copying' ; 504} else if (( reportSettings . alsoDelete || undoSubdir ) && isDeleting ) { 505reportCopyDeleteButton = 'Deleting' ; 506} else if ( reporting ) { 507reportCopyDeleteButton = 'Reporting' ; 508} 509 510return ( 511<> 512{ validSelections . valid && ( winnerId || isDq ) ?( 513< ReportButton 514elevate = { elevate } 515onClick = {() => { 516if ( mode === Mode . STARTGG || mode === Mode . OFFLINE_MODE ) { 517setStartggSet ( getStartggSet ()); 518} else if ( mode === Mode . CHALLONGE ) { 519setChallongeMatchItems ( getChallongeMatchItems ()); 520} else if ( mode === Mode . PARRYGG ) { 521setParryggMatchResult ( getMatchResult ()); 522} 523if ( 524( selectedReplaysWithEnforceErrors . length > 0 && 525showEnforcerPopup ) || 526enforceState . status === EnforceStatus . ERROR 527) { 528setEnforcerResultOpen ( true ); 529} 530setOpen ( true ); 531}} 532/> 533) :( 534< Tooltip 535arrow 536title = { ! validSelections . valid ?validSelections . reason :'No winner' } 537> 538< div > 539< ReportButton disabled elevate = { elevate } /> 540</ div > 541</ Tooltip > 542)} 543< Dialog 544open = { open } 545onClose = {() => { 546setOpen ( false ); 547setStartggSet ({ 548setId :set . id , 549winnerId :0 , 550isDQ :false , 551gameData :[], 552}); 553}} 554> 555< DialogTitle typography = "body1" > 556Report set on { mode === Mode . STARTGG && 'start.gg' } 557{ mode === Mode . CHALLONGE && 'Challonge' } 558{ mode === Mode . PARRYGG && 'parry.gg' } 559{ mode === Mode . OFFLINE_MODE && 'Offline Mode' } 560</ DialogTitle > 561< DialogContent sx = {{ width :'500px' }}> 562< Stack > 563< Box sx = {{ typography :'caption' }} textAlign = "center" > 564{ set . fullRoundText } 565</ Box > 566< Stack 567alignItems = "center" 568direction = "row" 569sx = {{ typography :'h5' }} 570> 571< EntrantSection 572borderRight = { 1 } 573direction = "row-reverse" 574style = {{ 575backgroundColor : 576set . entrant1Id === winnerId ?bgColor :undefined , 577}} 578> 579< Box marginRight = "8px" width = "24px" textAlign = "right" > 580{ entrant1SetScore } 581</ Box > 582< Stack textAlign = "right" > 583< Name >{ set . entrant1Participants [ 0 ]. displayName }</ Name > 584{ set . entrant1Participants . length > 1 && ( 585< Name >{ set . entrant1Participants [ 1 ]. displayName }</ Name > 586)} 587</ Stack > 588</ EntrantSection > 589< EntrantSection 590borderLeft = { 1 } 591direction = "row" 592style = {{ 593backgroundColor : 594set . entrant2Id === winnerId ?bgColor :undefined , 595}} 596> 597< Box marginLeft = "8px" width = "24px" > 598{ entrant2SetScore } 599</ Box > 600< Stack > 601< Name >{ set . entrant2Participants [ 0 ]. displayName }</ Name > 602{ set . entrant2Participants . length > 1 && ( 603< Name >{ set . entrant2Participants [ 1 ]. displayName }</ Name > 604)} 605</ Stack > 606</ EntrantSection > 607</ Stack > 608</ Stack > 609< Divider sx = {{ marginTop :'16px' }} /> 610< Stack flexGrow = { 1 }> 611{( mode === Mode . STARTGG || mode === Mode . OFFLINE_MODE ) && 612startggSet . gameData . map (( gameData ) => ( 613< Stack key = { gameData . gameNum } marginTop = "8px" > 614{ gameData . stageId && ( 615< Box sx = {{ typography :'caption' }} textAlign = "center" > 616{ stageNames . get ( startggStageIds . get ( gameData . stageId ) ! )} 617</ Box > 618)} 619< Stack direction = "row" sx = {{ typography :'body2' }}> 620< EntrantSection borderRight = { 1 } direction = "row-reverse" > 621< Stack 622alignItems = "center" 623direction = "row-reverse" 624paddingTop = "4px" 625paddingBottom = "4px" 626paddingLeft = { 627set . entrant1Participants . length === 1 628 ?'4px' 629 :undefined 630} 631style = {{ 632backgroundColor : 633set . entrant1Id === gameData . winnerId 634 ?bgColor 635 :undefined , 636}} 637> 638< EntrantScore textAlign = "right" > 639{ set . entrant1Id === gameData . winnerId && 'W' } 640</ EntrantScore > 641{ set . entrant1Participants . length === 1 && ( 642< Avatar 643alt = { characterNames . get ( 644startggCharacterIds . get ( 645gameData . selections [ 0 ]. characterId , 646) ! , 647)} 648src = { getCharacterIconInner ( 649startggCharacterIds . get ( 650gameData . selections [ 0 ]. characterId , 651), 652gameData . entrant1Score >= 100 653 ?Math . floor ( gameData . entrant1Score / 100 ) - 1 654 :undefined , 655)} 656sx = {{ height :24 , width :24 }} 657variant = "square" 658/> 659)} 660{ set . entrant1Participants . length === 2 && ( 661<> 662< Avatar 663alt = { characterNames . get ( 664startggCharacterIds . get ( 665gameData . selections [ 1 ]. characterId , 666) ! , 667)} 668src = { getCharacterIconInner ( 669startggCharacterIds . get ( 670gameData . selections [ 1 ]. characterId , 671), 672)} 673sx = {{ height :24 , width :24 }} 674variant = "square" 675/> 676< Avatar 677alt = { characterNames . get ( 678startggCharacterIds . get ( 679gameData . selections [ 0 ]. characterId , 680) ! , 681)} 682src = { getCharacterIconInner ( 683startggCharacterIds . get ( 684gameData . selections [ 0 ]. characterId , 685), 686)} 687sx = {{ height :24 , width :24 }} 688variant = "square" 689/> 690</> 691)} 692</ Stack > 693{ set . entrant1Participants . length === 1 && 694set . entrant1Id === gameData . winnerId && 695gameData . entrant1Score % 100 && ( 696< Tooltip 697arrow 698placement = "left" 699title = { ` ${ gameData . entrant1Score % 100 } stock` } 700> 701< Stack 702alignItems = "end" 703direction = "row" 704gap = "1px" 705marginRight = "8px" 706height = "100%" 707> 708{[ 709 ...Array ( gameData . entrant1Score % 100 ). keys (), 710]. map (() => ( 711< Avatar 712src = { getCharacterIconInner ( 713startggCharacterIds . get ( 714gameData . selections [ 0 ]. characterId , 715), 716gameData . entrant1Score >= 100 717 ?Math . floor ( 718gameData . entrant1Score / 100 , 719) - 1 720 :undefined , 721)} 722sx = {{ height :12 , width :12 }} 723variant = "square" 724/> 725))} 726</ Stack > 727</ Tooltip > 728)} 729</ EntrantSection > 730< EntrantSection borderLeft = { 1 } direction = "row" > 731< Stack 732alignItems = "center" 733direction = "row" 734paddingTop = "4px" 735paddingBottom = "4px" 736paddingRight = { 737set . entrant2Participants . length === 1 738 ?'4px' 739 :undefined 740} 741style = {{ 742backgroundColor : 743set . entrant2Id === gameData . winnerId 744 ?bgColor 745 :undefined , 746}} 747> 748< EntrantScore > 749{ set . entrant2Id === gameData . winnerId && 'W' } 750</ EntrantScore > 751{ set . entrant2Participants . length === 1 && ( 752< Avatar 753alt = { characterNames . get ( 754startggCharacterIds . get ( 755gameData . selections [ 1 ]. characterId , 756) ! , 757)} 758src = { getCharacterIconInner ( 759startggCharacterIds . get ( 760gameData . selections [ 1 ]. characterId , 761), 762gameData . entrant2Score >= 100 763 ?Math . floor ( gameData . entrant2Score / 100 ) - 1 764 :undefined , 765)} 766sx = {{ height :24 , width :24 }} 767variant = "square" 768/> 769)} 770{ set . entrant2Participants . length === 2 && ( 771<> 772< Avatar 773alt = { characterNames . get ( 774startggCharacterIds . get ( 775gameData . selections [ 776set . entrant1Participants . length 777]. characterId , 778) ! , 779)} 780src = { getCharacterIconInner ( 781startggCharacterIds . get ( 782gameData . selections [ 783set . entrant1Participants . length 784]. characterId , 785), 786)} 787sx = {{ height :24 , width :24 }} 788variant = "square" 789/> 790< Avatar 791alt = { characterNames . get ( 792startggCharacterIds . get ( 793gameData . selections [ 794set . entrant1Participants . length + 1 795]. characterId , 796) ! , 797)} 798src = { getCharacterIconInner ( 799startggCharacterIds . get ( 800gameData . selections [ 801set . entrant1Participants . length + 1 802]. characterId , 803), 804)} 805sx = {{ height :24 , width :24 }} 806variant = "square" 807/> 808</> 809)} 810</ Stack > 811{ set . entrant2Participants . length === 1 && 812set . entrant2Id === gameData . winnerId && 813gameData . entrant2Score % 100 && ( 814< Tooltip 815arrow 816placement = "right" 817title = { ` ${ gameData . entrant2Score % 100 } stock` } 818> 819< Stack 820alignItems = "end" 821direction = "row" 822gap = "1px" 823marginLeft = "8px" 824height = "100%" 825> 826{[ 827 ...Array ( gameData . entrant2Score % 100 ). keys (), 828]. map (() => ( 829< Avatar 830src = { getCharacterIconInner ( 831startggCharacterIds . get ( 832gameData . selections [ 1 ]. characterId , 833), 834gameData . entrant2Score >= 100 835 ?Math . floor ( 836gameData . entrant2Score / 100 , 837) - 1 838 :undefined , 839)} 840sx = {{ height :12 , width :12 }} 841variant = "square" 842/> 843))} 844</ Stack > 845</ Tooltip > 846)} 847</ EntrantSection > 848</ Stack > 849</ Stack > 850))} 851</ Stack > 852< Divider sx = {{ marginTop :'8px' }} /> 853< Stack justifyContent = "flex-end" > 854< LabeledCheckbox 855checked = { reportSettings . alsoCopy || undoSubdir . length > 0 } 856disabled = { undoSubdir . length > 0 } 857label = "Copy replays after reporting" 858labelPlacement = "start" 859set = {( checked :boolean ) => { 860const newReportSettings = { ...reportSettings }; 861newReportSettings . alsoCopy = checked ; 862setReportSettings ( newReportSettings ); 863}} 864/> 865< LabeledCheckbox 866checked = { reportSettings . alsoDelete || undoSubdir . length > 0 } 867disabled = { 868! reportSettings . alsoCopy || 869deleteOverrideReason . length > 0 || 870undoSubdir . length > 0 871} 872label = { 873deleteOverrideReason . length > 0 874 ?`Delete disabled, ${ deleteOverrideReason } ` 875 :'...then delete originals and eject' 876} 877labelPlacement = "start" 878set = {( checked :boolean ) => { 879const newReportSettings = { ...reportSettings }; 880newReportSettings . alsoDelete = checked ; 881setReportSettings ( newReportSettings ); 882}} 883/> 884</ Stack > 885</ DialogContent > 886< DialogActions > 887{ enforceState . status === EnforceStatus . ERROR && ( 888< Tooltip arrow placement = "top" title = "SLP Enforcer Failure" > 889< IconButton 890onClick = {() => { 891setEnforcerResultOpen ( true ); 892}} 893> 894< Report /> 895</ IconButton > 896</ Tooltip > 897)} 898{ selectedReplaysWithEnforceErrors . length > 0 && ( 899< Tooltip 900arrow 901placement = "top" 902title = "Controller Ruleset Violation Detected" 903> 904< IconButton 905onClick = {() => { 906setEnforcerResultOpen ( true ); 907}} 908> 909< VideogameAssetOff /> 910</ IconButton > 911</ Tooltip > 912)} 913< Button 914disabled = { 915reporting || 916( reportSettings . alsoCopy && isCopying ) || 917( reportSettings . alsoCopy && copyDisabled ) || 918enforceState . status === EnforceStatus . PENDING 919} 920endIcon = { 921reporting || enforceState . status === EnforceStatus . PENDING ?( 922< CircularProgress size = "24px" /> 923) :( 924< Backup /> 925) 926} 927onClick = { async () => { 928setReporting ( true ); 929try { 930let updatedSet :Set | undefined ; 931if ( mode === Mode . STARTGG ) { 932updatedSet = await reportStartggSet ( startggSet , set ); 933} else if ( mode === Mode . CHALLONGE ) { 934updatedSet = await reportChallongeSet ( 935assertString ( set . id ), 936challongeMatchItems , 937); 938} else if ( mode === Mode . PARRYGG ) { 939updatedSet = await reportParryggSet ( parryggMatchResult , set ); 940} else if ( mode === Mode . OFFLINE_MODE ) { 941updatedSet = await reportOfflineModeSet ( startggSet ); 942} 943if ( reportSettings . alsoCopy || undoSubdir ) { 944const entrantIdToDisplayNameAndCheckNames = new Map < 945Id , 946{ checkNames :Map < string , boolean >; displayName :string } 947>(); 948selectedReplaysWithEnforceErrors . forEach (( replay ) => { 949enforceState . fileNameToPlayerFailures 950. get ( replay . fileName ) ! 951. forEach (( playerFailure ) => { 952const failurePlayer = replay . players . find ( 953( player ) => player . port === playerFailure . port , 954) ! ; 955const displayName = 956failurePlayer . playerOverrides . displayName || 957failurePlayer . displayName ; 958const { entrantId} = failurePlayer . playerOverrides ; 959if ( entrantId ) { 960if ( 961entrantIdToDisplayNameAndCheckNames . has ( entrantId ) 962) { 963const { checkNames} = 964entrantIdToDisplayNameAndCheckNames . get ( 965entrantId , 966) ! ; 967playerFailure . checkNames . forEach (( checkName ) => { 968checkNames . set ( checkName , true ); 969}); 970} else { 971entrantIdToDisplayNameAndCheckNames . set ( entrantId , { 972checkNames :new Map ( 973playerFailure . checkNames . map (( checkName ) => [ 974checkName , 975true , 976]), 977), 978 displayName, 979}); 980} 981} 982}); 983}); 984await copyReplays ( 985updatedSet 986 ?{ 987id :updatedSet . id , 988sggId :updatedSet . sggId , 989completedAtMs :updatedSet . completedAtMs , 990stream :updatedSet . stream , 991} 992 :undefined , 993Array . from ( entrantIdToDisplayNameAndCheckNames ). map ( 994([ entrantId , { checkNames, displayName}]) => ({ 995 checkNames, 996 displayName, 997 entrantId, 998}), 999), 1000); 1001} 1002if ( 1003( reportSettings . alsoCopy && 1004reportSettings . alsoDelete && 1005deleteOverrideReason . length === 0 ) || 1006undoSubdir 1007) { 1008await deleteReplays (); 1009} 1010setOpen ( false ); 1011setStartggSet ({ 1012setId :set . id , 1013winnerId :0 , 1014isDQ :false , 1015gameData :[], 1016}); 1017resetGuide (); 1018} catch ( e :any ) { 1019const message = e instanceof Error ?e . message :e ; 1020setReportError ( message ); 1021setReportErrorOpen ( true ); 1022} finally { 1023setReporting ( false ); 1024} 1025}} 1026variant = "contained" 1027> 1028{ reportCopyDeleteButton } 1029</ Button > 1030</ DialogActions > 1031</ Dialog > 1032< Dialog 1033open = { reportErrorOpen } 1034onClose = {() => { 1035setReportErrorOpen ( false ); 1036setReportError ( '' ); 1037}} 1038> 1039< DialogTitle >{ reportCopyDeleteIntent } error! </ DialogTitle > 1040< DialogContent > 1041< DialogContentText >{ reportError }</ DialogContentText > 1042</ DialogContent > 1043< DialogActions > 1044< Button 1045onClick = {() => { 1046setReportErrorOpen ( false ); 1047setReportError ( '' ); 1048}} 1049> 1050Close 1051</ Button > 1052</ DialogActions > 1053</ Dialog > 1054< Dialog 1055open = { enforcerResultOpen } 1056onClose = {() => { 1057setEnforcerResultOpen ( false ); 1058}} 1059> 1060< Stack 1061alignItems = "center" 1062direction = "row" 1063justifyContent = "space-between" 1064marginRight = "24px" 1065> 1066< DialogTitle > 1067{ enforceState . status === EnforceStatus . DONE && 1068'Controller Ruleset Violation Detected' } 1069{ enforceState . status === EnforceStatus . ERROR && 1070'SLP Enforcer Failure' } 1071</ DialogTitle > 1072< Typography variant = "caption" > 1073SLP Enforcer version { enforcerVersion } 1074</ Typography > 1075</ Stack > 1076< DialogContent sx = {{ width :'500px' }}> 1077{ enforceState . status === EnforceStatus . DONE && ( 1078< Stack spacing = "8px" > 1079{ selectedReplaysWithEnforceErrors . map (( selectedReplay ) => ( 1080< Box key = { selectedReplay . fileName }> 1081< Box typography = "caption" > 1082{ stageNames . get ( selectedReplay . stageId )} 1083</ Box > 1084{ enforceState . fileNameToPlayerFailures 1085. get ( selectedReplay . fileName ) ! 1086. map (( enforcePlayerFailure ) => ( 1087< Box key = { enforcePlayerFailure . port } typography = "body2" > 1088{ getDisplayNameFromPlayer ( 1089selectedReplay . players . find ( 1090( player ) => 1091player . port === enforcePlayerFailure . port , 1092), 1093)} 1094: { enforcePlayerFailure . checkNames . join ( ', ' )} 1095</ Box > 1096))} 1097</ Box > 1098))} 1099</ Stack > 1100)} 1101{ enforceState . status === EnforceStatus . ERROR && ( 1102< DialogContentText > 1103{ enforceState . reason instanceof Error 1104 ?enforceState . reason . message 1105 :enforceState . reason . toString ()} 1106</ DialogContentText > 1107)} 1108</ DialogContent > 1109</ Dialog > 1110</> 1111); 1112}