Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed get_numbered_name decoloration. #3414

Closed
wants to merge 0 commits into from
Closed

Conversation

jaborsh
Copy link
Contributor

@jaborsh jaborsh commented Jan 19, 2024

Brief overview of PR changes/additions

The logic for get_numbered_name has been rewritten so that _INFLECT does not remove colors from singular & pluralized names.

Other info (issues closed, discussion etc)

Closes #3413

@jaborsh
Copy link
Contributor Author

jaborsh commented Jan 19, 2024

Note: In my fix, I've included regular expressions for @InspectorCaracal's Hex implementation which follows the syntax |#RRGGBB, but its addition here does not diminish the overall integrity of the function.

@Griatch
Copy link
Member

Griatch commented Feb 4, 2024

Thanks for working on this! I have looked over this, and I need to ponder if this is the way to go about it though ... this re-implements |-style parsing in a second place, which breaks DRY principles and feels a little hackish to me ... not sure I have a better alternative atm, but will wait to merge this a bit, nevertheless.

@InspectorCaracal
Copy link
Contributor

Not as a solution, but as an alternative that might help spark a better idea: for my games, I've written the following function that I use pretty much everywhere. It's not a fantastic solution, due to its dependence on adding a temporary "marker" character that you don't really have a guarantee won't be included in someone's just normal string, which is why I only use it personally and so haven't bothered making it "nice".

re_colorful = re.compile(r'\|.+?\|n')
re_articles = re.compile(r'^(a|an|and|the)(\s+)', re.IGNORECASE)

def numbered_name(name, count, pair=False, pluralize=True, cap=False, prefix=True):
	name = re_articles.sub('', name)
	colorlist = re_colorful.findall(name)
	colorkeys = {}
	for colorword in colorlist:
		index = strip_ansi(colorword)+'@'
		colorkeys[index] = colorword
		name = name.replace(colorword, index)
	if count == 1 and prefix:
		name = INFLECT.an(name)
	else:
		if not count:
			num = "no"
		elif pair and count == 2 and not name.startswith("pair of"):
			num = "a pair of"
		else:
			num = INFLECT.number_to_words(count)
		if pluralize:
			name = INFLECT.plural_noun(name) or name
		if prefix:
			name = f"{num} {name}"

	if cap:
		name = name[0].upper() + name[1:]

	for index, colorword in colorkeys.items():
		name = name.replace(index, colorword)

	return name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Color is lost with get_numbered_name
3 participants