this post was submitted on 28 Oct 2023
6 points (100.0% liked)

Digital

260 readers
3 users here now

MTG Arena and Magic Online discussion

Discussion related to Magic's digital games, including MTG Arena and Magic Online (or MODO).

Learn more about MTG Arena and Magic Online!


founded 1 year ago
MODERATORS
 

I've been wanting to get started using XMage and thought it would be fun to play a few matches against the AI with the GRN Guild Kit decks (GK1) using the original printings. I found decklists on sites like mtg.wtf that list the card names and quantities, but they don't specify the original set name and card number for each card.

For example, this GitHub repo has decklists for various preconstructed decks, but also lacks the specific set information and card numbers.

What I'm really looking for are decklists that include the card name, quantity, set name, and card number in the set for each card, ideally formatted like this:

quantity [SETCODE:collector number] cardname

This .dck file format used by XMage would allow me to easily import the exact preconstructed deck I want to play with the original printings, without having to rebuild it.

It made me think how nice it would be to have all the preconstructed decks available as .dck files with the original printings specified, nicely organized into folders by product. That way I could easily grab the exact deck I want to play with in XMage without having to build it manually.

Does anyone know if prebuilt decklists with detailed set data like this already exist somewhere for preconstructed products like the Guild Kits? Or if not, I may try writing a script to generate them before manually creating the files myself.

Please let me know if you know of any resources where I could find complete decklists for preconstructed decks specifying the card names, quantities, set names, and card numbers! This would save me a lot of time in recreating the decks accurately in XMage.

you are viewing a single comment's thread
view the rest of the comments
[–] counterspell@mtgzone.com 2 points 1 year ago* (last edited 1 year ago)

Here are step-by-step instructions to migrate decks_v2.json to .dck files with the desired structure, assuming no prior knowledge of the command line:

  1. Open a web browser and go to the following link: https://github.com/taw/magic-preconstructed-decks
  2. Click the green "Code" button and select "Download ZIP" to download the repository as a ZIP file.
  3. Extract the ZIP file to a folder on your computer.
  4. Open the folder and create a new file migrate_decks.py.
  5. Right-click on the file and select "Open With" and then choose a text editor such as Notepad or Sublime Text.
  6. Copy the following Python script and paste it into the text editor:
import json
import os
import re

from typing import List, Dict

DECKS_FOLDER = 'Preconstructed Decks'

def load_decks(file_path: str) -> List[Dict]:
    with open(file_path, 'r') as f:
        return json.load(f)

def format_deck_name(name: str) -> str:
    name = name.lower().replace(' ', '_').replace('-', '_')
    return re.sub(r'[^a-z0-9_]', '', name)

def get_deck_info(deck: Dict) -> Dict:
    return {
        'name': format_deck_name(deck['name']),
        'type': deck['type'],
        'set_code': deck['set_code'].upper(),
        'set_name': deck['set_name'],
        'release_date': deck['release_date'],
        'deck_folder': DECKS_FOLDER,
        'cards': deck['cards'],
        'sideboard': deck['sideboard']
    }

def build_deck_text(deck_info: Dict) -> str:
    lines = [
        f'// {deck_info["name"]}',
        f'// Set: {deck_info["set_name"]} ({deck_info["set_code"]})',
        f'// Release Date: {deck_info["release_date"]}',
        '',
    ]

    for card in deck_info['cards']:
        lines.append(f'{card["count"]} [{card["set_code"]}:{card["number"]}] {card["name"]}')

    lines.append('')
    lines.append('SB:')

    for card in deck_info['sideboard']:
        lines.append(f'{card["count"]} [{card["set_code"]}:{card["number"]}] {card["name"]}')

    return '\n'.join(lines)

def build_deck_path(deck_info: Dict) -> str:
    return os.path.join(deck_info['deck_folder'],
                        deck_info['type'],
                        deck_info['set_code'])

def write_deck_file(deck_info: Dict, deck_text: str) -> None:
    deck_path = build_deck_path(deck_info)
    os.makedirs(deck_path, exist_ok=True)

    filename = f"{deck_info['name']}.dck"
    file_path = os.path.join(deck_path, filename)

    with open(file_path, 'w') as f:
        f.write(deck_text)

def migrate_decks(input_file: str, error_file: str) -> None:
    decks = load_decks(input_file)

    error_decks: List[Dict] = []
    for deck in decks:
        try:
            deck_info = get_deck_info(deck)
            deck_text = build_deck_text(deck_info)
            write_deck_file(deck_info, deck_text)
        except KeyError:
            error_decks.append(deck)

    if error_decks:
        with open(error_file, 'w') as f:
            json.dump(error_decks, f)

if __name__ == '__main__':
    migrate_decks('decks_v2.json', 'error_decks.json')
  1. Open a terminal or command prompt on your computer. On Windows, you can do this by pressing the Windows key and typing "cmd" and then pressing Enter.
  2. Navigate to the folder where the decks_v2.json file and the migrate_decks.py file are located. You can do this by typing cd followed by the path to the folder, such as cd C:\Users\YourName\Downloads\magic-preconstructed-decks-master.
  3. Type python migrate_decks.py and press Enter to run the Python script.
  4. Wait for the script to finish running. It will create a .dck file for each deck in the decks_v2.json file, with the desired structure.

Note: If you don't have Python installed on your computer, you can download it from the official website: https://www.python.org/downloads/. Choose the latest version for your operating system and follow the installation instructions.