Update seed data to include new cards, and modify hex codes for existing decks to be more different. Also add functionality to set a dark font color for card_badges if the bg color is too light
This commit is contained in:
parent
2cb35e853d
commit
15f8eb7cf4
6 changed files with 12779 additions and 8112 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.1.2 on 2025-03-22 04:08
|
||||
# Generated by Django 5.1.2 on 2025-03-28 04:43
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
|
@ -16,11 +16,11 @@ class Migration(migrations.Migration):
|
|||
name='Card',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=128)),
|
||||
('cardset', models.CharField(max_length=8)),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('cardset', models.CharField(max_length=32)),
|
||||
('cardnum', models.IntegerField()),
|
||||
('style', models.CharField(max_length=255)),
|
||||
('rarity_icon', models.CharField(max_length=8)),
|
||||
('style', models.CharField(max_length=128)),
|
||||
('rarity_icon', models.CharField(max_length=12)),
|
||||
('rarity_level', models.IntegerField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
|
|
@ -64,4 +64,8 @@ class Migration(migrations.Migration):
|
|||
('deck', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='name_translations', to='cards.deck')),
|
||||
],
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='card',
|
||||
unique_together={('cardset', 'cardnum')},
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Card(models.Model):
|
|||
decks = models.ManyToManyField("Deck")
|
||||
cardset = models.CharField(max_length=32)
|
||||
cardnum = models.IntegerField()
|
||||
style = models.CharField(max_length=16)
|
||||
style = models.CharField(max_length=128)
|
||||
rarity_icon = models.CharField(max_length=12)
|
||||
rarity_level = models.IntegerField()
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,36 @@ from django.db.models.signals import m2m_changed
|
|||
from django.dispatch import receiver
|
||||
from .models import Card
|
||||
|
||||
def color_is_dark(bg_color):
|
||||
"""
|
||||
Determine if a given hexadecimal color is dark.
|
||||
|
||||
This function accepts a 6-digit hex color string (with or without a leading '#').
|
||||
It calculates the brightness using the formula:
|
||||
|
||||
brightness = (0.299 * red) + (0.587 * green) + (0.114 * blue)
|
||||
|
||||
A brightness value less than or equal to 186 indicates that the color is dark.
|
||||
|
||||
Args:
|
||||
bg_color (str): A 6-digit hex color string (e.g. "#FFFFFF" or "FFFFFF").
|
||||
|
||||
Returns:
|
||||
bool: True if the color is dark (brightness <= 186), False otherwise.
|
||||
"""
|
||||
# Remove the leading '#' if it exists.
|
||||
color = bg_color[1:7] if bg_color[0] == '#' else bg_color
|
||||
|
||||
# Convert the hex color components to integers.
|
||||
r = int(color[0:2], 16)
|
||||
g = int(color[2:4], 16)
|
||||
b = int(color[4:6], 16)
|
||||
|
||||
# Compute brightness based on weighted RGB values.
|
||||
brightness = (r * 0.299) + (g * 0.587) + (b * 0.114)
|
||||
|
||||
return brightness <= 200
|
||||
|
||||
@receiver(m2m_changed, sender=Card.decks.through)
|
||||
def update_card_style(sender, instance, action, **kwargs):
|
||||
if action == "post_add":
|
||||
|
|
@ -14,4 +44,6 @@ def update_card_style(sender, instance, action, **kwargs):
|
|||
instance.style = f"background: linear-gradient(to right, {', '.join(hex_colors)});"
|
||||
else:
|
||||
instance.style = "background: linear-gradient(to right, #AAAAAA, #AAAAAA, #AAAAAA);"
|
||||
if not color_is_dark(decks.first().hex_color):
|
||||
instance.style += "color: var(--color-gray-700);"
|
||||
instance.save(update_fields=["style"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue