mirror of
https://github.com/vegu-ai/talemate.git
synced 2025-12-16 03:37:51 +01:00
Add unique random color assignment for characters in load_scene_from_character_card function
This commit is contained in:
@@ -16,6 +16,7 @@ from talemate.exceptions import UnknownDataSpec
|
||||
from talemate.status import LoadingStatus
|
||||
from talemate.config import get_config
|
||||
from talemate.util import extract_metadata, select_best_texts_by_keyword, count_tokens
|
||||
from talemate.util.colors import unique_random_colors
|
||||
from talemate.agents.base import DynamicInstruction
|
||||
from talemate.game.engine.nodes.registry import import_scene_node_definitions
|
||||
from talemate.scene_assets import (
|
||||
@@ -1055,11 +1056,16 @@ async def load_scene_from_character_card(
|
||||
if not selected_names:
|
||||
raise ValueError("No character names provided in import options")
|
||||
|
||||
# Assign unique random colors to each character
|
||||
assigned_colors = unique_random_colors(len(selected_names))
|
||||
|
||||
# Create characters from selected names
|
||||
characters = []
|
||||
for char_name in selected_names:
|
||||
for idx, char_name in enumerate(selected_names):
|
||||
assigned_color = assigned_colors[idx]
|
||||
if char_name == original_character.name:
|
||||
# Use original character if name matches
|
||||
# Use original character if name matches, but assign it a unique color
|
||||
original_character.color = assigned_color
|
||||
characters.append(original_character)
|
||||
else:
|
||||
# Create a copy of the original character with the new name
|
||||
@@ -1068,7 +1074,7 @@ async def load_scene_from_character_card(
|
||||
name=char_name,
|
||||
description=original_character.description,
|
||||
greeting_text=original_character.greeting_text,
|
||||
color=original_character.color,
|
||||
color=assigned_color,
|
||||
is_player=original_character.is_player,
|
||||
dialogue_instructions=original_character.dialogue_instructions,
|
||||
example_dialogue=[], # Will be regenerated
|
||||
|
||||
@@ -5,6 +5,7 @@ __all__ = [
|
||||
"COLOR_NAMES",
|
||||
"COLOR_MAP",
|
||||
"random_color",
|
||||
"unique_random_colors",
|
||||
]
|
||||
|
||||
# Primary mapping of Vue color names to hex codes
|
||||
@@ -78,3 +79,24 @@ COLORS = sorted(list(COLOR_MAP.values()))
|
||||
|
||||
def random_color() -> str:
|
||||
return random.choice(COLORS)
|
||||
|
||||
|
||||
def unique_random_colors(count: int) -> list[str]:
|
||||
"""Return a list of unique random colors.
|
||||
|
||||
Args:
|
||||
count: Number of unique colors to return
|
||||
|
||||
Returns:
|
||||
List of color hex codes. If count exceeds available colors,
|
||||
duplicates may be included but colors are still randomized.
|
||||
"""
|
||||
if count <= 0:
|
||||
return []
|
||||
|
||||
if count > len(COLORS):
|
||||
# If we have more requested colors than available, allow duplicates but still randomize
|
||||
return [random.choice(COLORS) for _ in range(count)]
|
||||
else:
|
||||
# Sample unique colors for each requested color
|
||||
return random.sample(COLORS, count)
|
||||
|
||||
Reference in New Issue
Block a user