Difference between revisions of "Monster stats/Script"

From Wildermyth Wiki
(Created page with "This is a [https://www.python.org/downloads/ Python] script to generate the monster stat tables. Copy the code in the box below into a text file named '''<nowiki>tables.py...")
 
m
 
(3 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 [[monster stat]] tables. Copy the code in the box below into a text file named '''<nowiki>tables.py</nowiki>''' (or whatever you want) inside the '''<nowiki>Wildermyth</nowiki>''' directory. Then run it by calling '''<nowiki>python tables.py</nowiki>''' from the command line. It will create a text file for each difficulty named '''<nowiki>tables_<difficulty>.txt</nowiki>''', full of wiki-formatted tables that can be pasted into the appropriate wiki pages.
This is a [https://www.python.org/downloads/ Python] script to generate the [[monster stat]] tables. Copy the code in the box below into a text file named '''<nowiki>wikiMonsterStats.py</nowiki>''' (or whatever you want) inside the '''<nowiki>Wildermyth</nowiki>''' directory. Then run it by calling '''<nowiki>python wikiMonsterStats.py</nowiki>''' from the command line. It will create a text file for each difficulty named '''<nowiki>wikiMonsterStats_<difficulty>.txt</nowiki>''', full of wiki-formatted tables that can be pasted into the appropriate wiki pages.


{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| '''<nowiki>tables.py</nowiki>'''
| '''<nowiki>wikiMonsterStats.py</nowiki>'''
|-
|-
|
|
  <nowiki>import json
  <nowiki>import json
from glob import glob
from glob import glob
with open('version.txt','r',encoding='utf8') as f:
  lines = f.readlines()
  version = lines[0]


name_path_base = ''
name_path_base = ''
Line 69: Line 73:
   for faction in list(type_paths):
   for faction in list(type_paths):
     string += '{| role="presentation" class="wikitable sortable mw-collapsible mw-collapsed" style="text-align: center"\n'
     string += '{| role="presentation" class="wikitable sortable mw-collapsible mw-collapsed" style="text-align: center"\n'
     string += '| style="width:880px" | ' + "'''%s'''\n"%faction
     string += '| style="width:880px" | ' + ("'''%s'''\n"%faction if faction=='Miscellaneous' else "'''[[%s]]'''\n"%faction)
     string += '|-\n'
     string += '|-\n'
     string += '|\n\n'
     string += '|\n\n'
     string += '{| class="wikitable sortable" style="text-align: center"\n'
     string += '{| class="wikitable sortable" style="text-align: center"\n'
     string += '! ID !! Name !! Health !! Armor !! Warding !! Block + Dodge !! Speed !! Melee Accuracy !! Ranged Accuracy\n'
     string += '! ID !! Name !! [[Health]] !! [[Armor]] !! [[Warding]] !! [[Block]] + [[Dodge]] !! [[Speed]] !! [[Melee Accuracy]] !! [[Ranged Accuracy]]\n'
     for l in type_paths[faction]:
     for l in type_paths[faction]:
       for m in glob(l + '/*.json'):
       for m in glob(l + '/*.json'):
Line 91: Line 95:
           avoid = str(int(block)+int(dodge))
           avoid = str(int(block)+int(dodge))
           string += '|-\n'
           string += '|-\n'
           string += '| <small>' + id + '</small> || ' + name + ' || ' + health + ' || ' + armor + ' || ' + warding + ' || ' + avoid + ' || ' + speed + ' || ' + macc + ' || ' + racc + '\n'
           string += '| <small>' + id + '</small> || [[' + name + ']] || ' + health + ' || ' + armor + ' || ' + warding + ' || ' + avoid + ' || ' + speed + ' || ' + macc + ' || ' + racc + '\n'
        
        
     string += '|}\n\n'
     string += '|}\n\n'
     string += '|}\n\n'
     string += '|}\n\n'
   
  string += '==Notes==\nLast updated [[%s]] using [[Monster stats/Script|this script]].\n'%version[:-1]
    
    
   with open('tables_%s.txt'%diff, 'w') as f:
   with open('wikiMonsterStats_%s.txt'%diff, '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 monster stat tables. Copy the code in the box below into a text file named wikiMonsterStats.py (or whatever you want) inside the Wildermyth directory. Then run it by calling python wikiMonsterStats.py from the command line. It will create a text file for each difficulty named wikiMonsterStats_<difficulty>.txt, full of wiki-formatted tables that can be pasted into the appropriate wiki pages.