Difference between revisions of "Calamity track/Script"

From Wildermyth Wiki
(Created page with "This is a [https://www.python.org/downloads/ Python] script to generate the calamity track table. Copy the code in the box below into a text file named '''<nowiki>calamity...")
 
m
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is a [https://www.python.org/downloads/ Python] script to generate the [[calamity track]] table. Copy the code in the box below into a text file named '''<nowiki>calamityTable.py</nowiki>''' (or whatever you want) inside the '''<nowiki>Wildermyth</nowiki>''' directory. Then run it by calling '''<nowiki>python calamityTable.py</nowiki>''' from the command line. It will create a text file named '''<nowiki>calamityTable.txt</nowiki>''', which is wiki-formatted and can be pasted into the [[calamity track]] page.
This is a [https://www.python.org/downloads/ Python] script to generate the [[calamity track]] table. Copy the code in the box below into a text file named '''<nowiki>wikiCalamityTable.py</nowiki>''' (or whatever you want) inside the '''<nowiki>Wildermyth</nowiki>''' directory. Then run it by calling '''<nowiki>python wikiCalamityTable.py</nowiki>''' from the command line. It will create a text file named '''<nowiki>wikiCalamityTable.txt</nowiki>''', which is wiki-formatted and can be pasted into the [[calamity track]] page.


{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| '''<nowiki>calamityTable.py</nowiki>'''
| '''<nowiki>wikiCalamityTable.py</nowiki>'''
|-
|-
|
|
Line 64: Line 64:
         if k == 0:
         if k == 0:
           if 'onlyIfFlavorHasCards' in tracks[j]:
           if 'onlyIfFlavorHasCards' in tracks[j]:
             add_entry(card_list,flavor,tracks[j]['onlyIfFlavorHasCards'],{'name':cardName + ' %s'%cardNumbers[k],'cards':monsters,'count':k+1})
             add_entry(card_list,flavor,tracks[j]['onlyIfFlavorHasCards'],{'name':cardName,'numeral':cardNumbers[k],'cards':monsters,'count':k+1,'position':j})
             max_cards = max(tracks[j]['onlyIfFlavorHasCards'],max_cards)
             max_cards = max(tracks[j]['onlyIfFlavorHasCards'],max_cards)
           else:
           else:
             add_entry(card_list,flavor,0,{'name':cardName + ' %s'%cardNumbers[k],'cards':monsters,'count':k+1})
             add_entry(card_list,flavor,0,{'name':cardName,'numeral':cardNumbers[k],'cards':monsters,'count':k+1,'position':j})
         else:
         else:
           if 'trackAdvanceThresholds' in tracks[j]:
           if 'trackAdvanceThresholds' in tracks[j]:
             add_entry(card_list,flavor,tracks[j]['trackAdvanceThresholds'][k-1],{'name':cardName + ' %s'%cardNumbers[k],'cards':monsters,'count':k+1})
             add_entry(card_list,flavor,tracks[j]['trackAdvanceThresholds'][k-1],{'name':cardName,'numeral':cardNumbers[k],'cards':monsters,'count':k+1})
             max_cards = max(tracks[j]['trackAdvanceThresholds'][k-1],max_cards)
             max_cards = max(tracks[j]['trackAdvanceThresholds'][k-1],max_cards)
           else:
           else:
Line 79: Line 79:
string += 'In this way, each faction has a [[calamity track]] consisting of successively more dangerous cards.\n'
string += 'In this way, each faction has a [[calamity track]] consisting of successively more dangerous cards.\n'
string += '==Table==\n'
string += '==Table==\n'
string += 'If drawn within a [[mission]], each card typically generates a number of the specified monster equal to the card\'s roman numeral. There are some exceptions, which are noted in the table.\n'
string += 'If drawn within a [[mission]], each card typically generates a number of the specified monster equal to the card\'s roman numeral. '
string += 'There are some exceptions, which are noted in the table. '
string += 'Also, \'\'italicized\'\' cards are not drawn as [[calamity]] cards but are instead available from a campaign\'s outset.\n'
string += '{| class="wikitable" style="text-align: center"\n'
string += '{| class="wikitable" style="text-align: center"\n'
string += '! Threshold<br>cards !! [[%s]] !! [[%s]] !! [[%s]] !! [[%s]] !! [[%s]]\n'%tuple(card_list)
string += '! Threshold<br>cards !! [[%s]] !! [[%s]] !! [[%s]] !! [[%s]] !! [[%s]]\n'%tuple(card_list)
Line 92: Line 94:
         if j > 0:
         if j > 0:
           string += '<br>'
           string += '<br>'
         string += card['name']
        if 'position' in card and card['position'] < 2:
          string += "''"
         string += '[[%s|%s]] %s'%(card['cards'][0],card['name'],card['numeral'])
        if 'position' in card and card['position'] < 2:
          string += "''"
         if len(set(card['cards'])) > 1 or len(card['cards']) != card['count']:
         if len(set(card['cards'])) > 1 or len(card['cards']) != card['count']:
           string += '<ref>'
           string += '<ref>'
Line 104: Line 110:
string += '|}\n\n'
string += '|}\n\n'
string += '==Notes==\n'
string += '==Notes==\n'
string += '<small>Last updated [[%s]] using [[/Script|this script]].</small>\n'%version[:-1]
string += 'Last updated [[%s]] using [[/Script|this script]].\n'%version[:-1]
    
    
with open('calamityTable.txt', 'w') as f:
with open('wikiCalamityTable.txt', 'w') as f:
   f.write(string)</nowiki>
   f.write(string)</nowiki>
|}
|}

Latest revision as of 13:38, 5 March 2022

This is a Python script to generate the calamity track table. Copy the code in the box below into a text file named wikiCalamityTable.py (or whatever you want) inside the Wildermyth directory. Then run it by calling python wikiCalamityTable.py from the command line. It will create a text file named wikiCalamityTable.txt, which is wiki-formatted and can be pasted into the calamity track page.