Added hyperlinks to Moves, Abilities, and Species enums (#586)
* Added hyperlinks to Moves enum Yes, I'm aware of what this looks like in the file itself, but it enables a nice neat little hyperlink shown below to the bulbapedia page when you hover over a move. I feel like the added convenience is worth making the file harder to read considering nobody is ever going to touch that file anyway. I plan on adding a python script to finish the rest of them, but didn't want to actually sink time into this if we absolutely despise it. * Added Python Script Created a python script to add comments with a url to abilities.ts, moves.ts, and species.ts using regex
This commit is contained in:
1 parent
1c9b65125d
commit
ce3d12d58e
4 files changed
+2369
-1
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import re
|
||||
|
||||
filenames = [['src/data/enums/moves.ts', 'move'], ['src/data/enums/abilities.ts', 'ability'], ['src/data/enums/species.ts', 'Pokémon']]
|
||||
|
||||
commentBlockStart = re.compile('\/\*[^\*].*') # Regex for the start of a comment block
|
||||
commentBlockEnd = re.compile('.*,\*\/') # Regex for the end of a comment block
|
||||
|
||||
commentExp = re.compile('(?:\/\*\*.*\*\/)') # Regex for a url comment that already existed in the file
|
||||
enumExp = re.compile('.*,') # Regex for a regular enum line
|
||||
|
||||
numberExp = re.compile(' +\= +\d+,')
|
||||
|
||||
replaceList = ['ALOLA', 'ETERNAL', 'GALAR', 'HISUI', 'PALDEA', 'BLOODMOON']
|
||||
|
||||
for args in filenames:
|
||||
|
||||
output = ''
|
||||
|
||||
skip = False # True when we should completely stop adding url comments for any reason
|
||||
blockComment = False # True when currently reading a comment block
|
||||
|
||||
file = open(args[0], 'r')
|
||||
line = file.readline()
|
||||
|
||||
while line:
|
||||
if(skip): # Appends the next line in the file and moves on if we already hit the end of the enum
|
||||
output += line
|
||||
line = file.readline()
|
||||
continue
|
||||
|
||||
skip = line.find('};') != -1 # True if we reached the end of an enum definition
|
||||
|
||||
# Determines when a comment block has started and we should stop adding url comments
|
||||
if (commentBlockStart.findall(line)):
|
||||
blockComment = True
|
||||
|
||||
if(not commentExp.findall(line)):
|
||||
urlInsert = numberExp.sub('', line).strip().rstrip('\n').rstrip(',').title() # Clean up the enum line to only the enum
|
||||
for replace in replaceList:
|
||||
urlInsert = urlInsert.replace(replace.title() + '_', '')
|
||||
if (not blockComment and enumExp.findall(line)):
|
||||
output += ' /**{@link https://bulbapedia.bulbagarden.net/wiki/' + urlInsert + '_(' + args[1] + ') | Source} */\n'
|
||||
output += line # Add the line to output since it isn't an existing url comment
|
||||
|
||||
# Determines if we're at the end of a comment block and can resume adding url comments
|
||||
if (blockComment):
|
||||
blockComment = not commentBlockEnd.findall(line)
|
||||
|
||||
line = file.readline()
|
||||
|
||||
file.close()
|
||||
|
||||
file = open(args[0], 'w', encoding='utf-8')
|
||||
file.write(output,)
|
||||
file.close
|
||||
Reference in new issue
Block a user