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
|
import django.db.models.deletion
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
@ -16,11 +16,11 @@ class Migration(migrations.Migration):
|
||||||
name='Card',
|
name='Card',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
('name', models.CharField(max_length=128)),
|
('name', models.CharField(max_length=64)),
|
||||||
('cardset', models.CharField(max_length=8)),
|
('cardset', models.CharField(max_length=32)),
|
||||||
('cardnum', models.IntegerField()),
|
('cardnum', models.IntegerField()),
|
||||||
('style', models.CharField(max_length=255)),
|
('style', models.CharField(max_length=128)),
|
||||||
('rarity_icon', models.CharField(max_length=8)),
|
('rarity_icon', models.CharField(max_length=12)),
|
||||||
('rarity_level', models.IntegerField()),
|
('rarity_level', models.IntegerField()),
|
||||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
('updated_at', models.DateTimeField(auto_now=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')),
|
('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")
|
decks = models.ManyToManyField("Deck")
|
||||||
cardset = models.CharField(max_length=32)
|
cardset = models.CharField(max_length=32)
|
||||||
cardnum = models.IntegerField()
|
cardnum = models.IntegerField()
|
||||||
style = models.CharField(max_length=16)
|
style = models.CharField(max_length=128)
|
||||||
rarity_icon = models.CharField(max_length=12)
|
rarity_icon = models.CharField(max_length=12)
|
||||||
rarity_level = models.IntegerField()
|
rarity_level = models.IntegerField()
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
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 django.dispatch import receiver
|
||||||
from .models import Card
|
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)
|
@receiver(m2m_changed, sender=Card.decks.through)
|
||||||
def update_card_style(sender, instance, action, **kwargs):
|
def update_card_style(sender, instance, action, **kwargs):
|
||||||
if action == "post_add":
|
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)});"
|
instance.style = f"background: linear-gradient(to right, {', '.join(hex_colors)});"
|
||||||
else:
|
else:
|
||||||
instance.style = "background: linear-gradient(to right, #AAAAAA, #AAAAAA, #AAAAAA);"
|
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"])
|
instance.save(update_fields=["style"])
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
"fields": {
|
"fields": {
|
||||||
"name": "Genetic Apex: Pikachu",
|
"name": "Genetic Apex: Pikachu",
|
||||||
"cardset": "A1",
|
"cardset": "A1",
|
||||||
"hex_color": "#EB8600",
|
"hex_color": "#FCF326",
|
||||||
"created_at": "2025-02-16T07:55:05.097Z",
|
"created_at": "2025-02-16T07:55:05.097Z",
|
||||||
"updated_at": "2025-02-16T07:55:05.097Z"
|
"updated_at": "2025-02-16T07:55:05.097Z"
|
||||||
}
|
}
|
||||||
|
|
@ -75,5 +75,27 @@
|
||||||
"created_at": "2025-02-16T07:55:27.503Z",
|
"created_at": "2025-02-16T07:55:27.503Z",
|
||||||
"updated_at": "2025-02-16T07:55:27.503Z"
|
"updated_at": "2025-02-16T07:55:27.503Z"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "cards.deck",
|
||||||
|
"pk": 8,
|
||||||
|
"fields": {
|
||||||
|
"name": "Triumphant Light",
|
||||||
|
"cardset": "A2a",
|
||||||
|
"hex_color": "#DF8D2C",
|
||||||
|
"created_at": "2025-03-26T12:25:17.706Z",
|
||||||
|
"updated_at": "2025-03-26T12:25:17.706Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "cards.deck",
|
||||||
|
"pk": 9,
|
||||||
|
"fields": {
|
||||||
|
"name": "Shining Revelry",
|
||||||
|
"cardset": "A2b",
|
||||||
|
"hex_color": "#D7FDFC",
|
||||||
|
"created_at": "2025-03-26T12:25:17.706Z",
|
||||||
|
"updated_at": "2025-03-26T12:25:17.706Z"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
5767
seed/0003_Cards.json
5767
seed/0003_Cards.json
File diff suppressed because it is too large
Load diff
|
|
@ -81,7 +81,7 @@
|
||||||
@plugin "daisyui/theme" {
|
@plugin "daisyui/theme" {
|
||||||
name: "dark";
|
name: "dark";
|
||||||
default: false;
|
default: false;
|
||||||
prefersdark: false;
|
prefersdark: true;
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
--color-base-100: oklch(25.33% 0.016 252.42);
|
--color-base-100: oklch(25.33% 0.016 252.42);
|
||||||
--color-base-200: oklch(23.26% 0.014 253.1);
|
--color-base-200: oklch(23.26% 0.014 253.1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue