Advertisement
Pantalaimon

Parse MTGO .dek file into TappedOut.net format

Aug 21st, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;This script will prompt the user for a MTGO .dek file, parse it into the format used by TappedOut.net, and copy it to the clipboard.
  2. ;If the dek has a sideboard, that will also be parsed.
  3.  
  4. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  5. #Warn  ; Recommended for catching common errors.
  6. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  7. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  8.  
  9. ;PLEASE ENTER YOUR DEFAULT STARTING DIRECTORY BELOW
  10. CONST_STARTING_DIR = C:\
  11.  
  12. arrayDeckParsed =
  13. arraySideboardParsed =
  14.  
  15. boolSideboardExists = 0
  16.  
  17. stringRegExMain = Quantity="(?P<Count>[0-9]+)" Sideboard="false" Name="(?P<Name>[^"]+)
  18. stringRegExSideboard = Quantity="(?P<Count>[0-9]+)" Sideboard="true" Name="(?P<Name>[^"]+)
  19.  
  20. ;-----END INIT-----
  21.  
  22. ;user can't proceed without choosing a file
  23. Loop
  24. {
  25.     FileSelectFile, stringFileChosen,,%CONST_STARTING_DIR%,Choose a .dek file to convert to Tapped-Out format:,MTGO Deck Files (*.dek)
  26.         if (ErrorLevel <> 1)
  27.             break
  28.         else
  29.             MsgBox,Please choose a file to continue!
  30. }
  31.  
  32. ;read the .dek the user just chose
  33. FileRead,arrayDeck,%stringFileChosen%
  34.  
  35. ;loop through the .dek line by line
  36. Loop,parse,arrayDeck,`n,`r
  37. {
  38.     ;if the first regex matches, it's a main card, if not (check that) it's a sideboard card (the sideboard exists)
  39.    
  40.     stringTempRegEx =
  41.     RegExMatch(A_LoopField,stringRegExMain,stringTempRegEx)
  42.     if (stringTempRegEx <> "")
  43.         arrayDeckParsed = %arrayDeckParsed%%stringTempRegExCount%x %stringTempRegExName%`n
  44.     else
  45.     {
  46.         RegExMatch(A_LoopField,stringRegExSideboard,stringTempRegEx)
  47.         if (stringTempRegEx <> "")
  48.         {
  49.             arraySideboardParsed = %arraySideboardParsed%%stringTempRegExCount%x %stringTempRegExName%`n
  50.             if (boolSideboardExists = 0)
  51.                 boolSideboardExists = 1
  52.         }
  53.     }
  54. }
  55.  
  56. Clipboard = %arrayDeckParsed%
  57.  
  58. ;if there was a sideboard, display different prompt and copy that too.
  59. if (boolSideBoardExists = 1)
  60. {
  61.     MsgBox,Main parsed and copied to clipboard!`n`nPress OK to copy sideboard to clipboard.
  62.     Clipboard = %arraySideboardParsed%
  63.     MsgBox,Sideboard copied to clipboard!`n`nPress OK to quit.
  64. }
  65. else
  66.     MsgBox,Main parsed and copied to clipboard!`n`nPress OK to quit.
  67.    
  68. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement