Skip to content

Commit

Permalink
Add: --list-unused-strings to list the unused strings
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Dec 15, 2024
1 parent eca3580 commit 9828e59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nml/grfstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ class Language:
@type strings: C{dict} of
"""

used_strings = []

def __init__(self, default):
self.default = default
self.langid = None
Expand Down Expand Up @@ -985,6 +987,9 @@ def get_string(self, string, lang_id):
assert string_id in self.strings
assert lang_id == self.langid or self.langid == DEFAULT_LANGUAGE

if string_id not in Language.used_strings:
Language.used_strings.append(string_id)

str_type = self.strings[string_id].get_type()
parsed_string = ""
if self.strings[string_id].gender is not None:
Expand Down Expand Up @@ -1291,3 +1296,10 @@ def read_lang_files(lang_dir, default_lang_file):
continue
parse_file(filename, False)
langs.sort()


def list_unused_strings():
for string in default_lang.strings:
if string in Language.used_strings:
continue
generic.print_warning(generic.Warning.GENERIC, 'String "{}" is unused'.format(string))
7 changes: 7 additions & 0 deletions nml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def parse_cli(argv):
allow_extra_zoom=True,
allow_32bpp=True,
disable_palette_validation=False,
list_unused_strings=False,
)
opt_parser.add_option("-d", "--debug", action="store_true", dest="debug", help="write the AST to stdout")
opt_parser.add_option("-s", "--stack", action="store_true", dest="stack", help="Dump stack when an error occurs")
Expand Down Expand Up @@ -231,6 +232,9 @@ def parse_cli(argv):
dest="disable_palette_validation",
help="Disable palette validation for sprites",
)
opt_parser.add_option(
"--list-unused-strings", action="store_true", dest="list_unused_strings", help="List unused strings"
)

opts, args = opt_parser.parse_args(argv)

Expand Down Expand Up @@ -359,6 +363,9 @@ def main(argv):
)

input.close()

if opts.list_unused_strings:
grfstrings.list_unused_strings()
sys.exit(ret)


Expand Down

0 comments on commit 9828e59

Please sign in to comment.