pokerogue/scripts/update_source_comments.py
Sirz Benjie 6766940fa1
[Misc] Make the repo REUSE compliant (#6474)
* Add license information

* Add reuse lint workflow

* Add snippets for spdx

* fix: minor wording adjustments and typo fixes

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* chore: add FileContributor attributions for Bertie

Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>

* begin licensing some audio assets

* Add pokemon reborn sound affect attribution

* Annotate Leavannite's section

* Add more licensing info

* Add license info to license files ._.

* Move ps1 files out of public

* Add license for animation jsons

* Add license for bat scripts in public

* Update licensing in scripts

* Fix typo in license ref

* Fix AGPL-3.0-or-later

* Add license info to typedoc.config.js

* Add MIT license for snippets

* chore: update license info for files in scripts

* chore: update license info

* chore: update license info

* chore: update license info

* Remove licenses used only by public before linting with reuse

* Add license info to new files added by docker PR

* chore: apply biome

* fix: add back linting workflow lost during merge

* Add attribution based on Hanniel's information

* Add attribution based on Officer Porkchop and Green Ninja's information

* add attribution to unicorn_power for reshiram/zekrom/kyurem epic variant

* Fixup minor typo

* Adjust sprite test to not think REUSE.toml is a sprite json

* Add missing continue-on-error to workflow

* fix: address kev's comments from code review

* docs: minor touchups

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
2025-09-23 08:49:03 -05:00

60 lines
2.3 KiB
Python

# SPDX-FileCopyrightText: 2024-2025 Pagefault Games
# SPDX-FileContributor: Benjamin Odom
#
# SPDX-License-Identifier: AGPL-3.0-only
import re
filenames = [['src/enums/moves.ts', 'move'], ['src/enums/abilities.ts', 'ability'], ['src/enums/species.ts', 'Pokémon']]
commentBlockStart = re.compile(r'\/\*[^\*].*') # Regex for the start of a comment block
commentBlockEnd = re.compile(r'.*,\*\/') # Regex for the end of a comment block
commentExp = re.compile(r'(?:\/\*\*.*\*\/)') # Regex for a url comment that already existed in the file
enumExp = re.compile('.*,') # Regex for a regular enum line
numberExp = re.compile(r' +\= +\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