Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ca12918
Initial set of changes
dormieriancitizen Jul 9, 2025
886ae2d
It works now
dormieriancitizen Jul 9, 2025
d542e65
removed data dump
dormieriancitizen Jul 9, 2025
dd4661a
Fix specials and per-instance attributes
dormieriancitizen Jul 9, 2025
681826e
WHY IS SPECIALCARD AND SPECIAL_CARD DIFFERENT
dormieriancitizen Jul 9, 2025
cb17b83
Customisable canvas size
dormieriancitizen Jul 9, 2025
b57fb2e
NamedTuple is perhaps the best thing to ever thing
dormieriancitizen Jul 9, 2025
2a92f2c
Realised it isn't always top left bc of text anchor, so that was
dormieriancitizen Jul 12, 2025
7d9df48
Beginning of template logic
dormieriancitizen Jul 18, 2025
a4636f0
Model changes for card templating
dormieriancitizen Jul 20, 2025
c11e1ec
create migration
dormieriancitizen Jul 20, 2025
99a6b3b
Add to admin panel, fix syntax so it works in JSON (ordering is
dormieriancitizen Jul 20, 2025
5cd66dc
Cache fonts, automatic text color (with caching), slight changes to
dormieriancitizen Jul 21, 2025
88ccc14
Refactor draw_layer because the nesting was a little unhinged. Also, add
dormieriancitizen Jul 21, 2025
2931ea9
Fix off-by-one
dormieriancitizen Jul 21, 2025
0d09446
Make default template a json, fix the schema, move things about
dormieriancitizen Jul 21, 2025
52601ef
Actually respect stroke fill
dormieriancitizen Jul 21, 2025
9d6651a
Fix bug involving different font sizes, and actually attain mostly full
dormieriancitizen Jul 21, 2025
6817307
Real actual parity now. Everything (should?) be the same.
dormieriancitizen Jul 21, 2025
6d67271
I lied because I spelled laggron's name wrong.
dormieriancitizen Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion admin_panel/bd_models/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ball import BallAdmin, EconomyAdmin, RegimeAdmin
from .ball import BallAdmin, CardTemplateAdmin, EconomyAdmin, RegimeAdmin
from .ball_instance import BallInstanceAdmin
from .guild import GuildAdmin
from .player import PlayerAdmin
Expand All @@ -13,5 +13,6 @@
"GuildAdmin",
"PlayerAdmin",
"SpecialAdmin",
"CardTemplateAdmin",
"TradeAdmin",
]
16 changes: 15 additions & 1 deletion admin_panel/bd_models/admin/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
from django.utils.safestring import mark_safe
from django.utils.text import capfirst

from ..models import Ball, BallInstance, Economy, Regime, TradeObject, transform_media
from ..models import (
Ball,
BallInstance,
CardTemplate,
Economy,
Regime,
TradeObject,
transform_media,
)

if TYPE_CHECKING:
from django.db.models import Field, Model, QuerySet
Expand Down Expand Up @@ -81,6 +89,12 @@ def icon_image(self, obj: Economy):
return mark_safe(f'<img src="/media/{transform_media(str(obj.icon))}" height=30px />')


@admin.register(CardTemplate)
class CardTemplateAdmin(admin.ModelAdmin):
list_display = ("name", "pk")
search_fields = ("name",)


@admin.register(Ball)
class BallAdmin(admin.ModelAdmin):
autocomplete_fields = ("regime", "economy")
Expand Down
2 changes: 1 addition & 1 deletion admin_panel/bd_models/admin/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SpecialAdmin(admin.ModelAdmin):
(
"Advanced",
{
"fields": ["tradeable", "hidden"],
"fields": ["tradeable", "hidden", "card_template"],
"classes": ["collapse"],
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Generated by Django 5.1.4 on 2025-07-20 21:12

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bd_models", "0007_player_trade_cooldown_policy"),
]

operations = [
migrations.CreateModel(
name="CardTemplate",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("name", models.CharField(max_length=64)),
("template", models.JSONField(help_text="Card template JSON")),
],
options={
"verbose_name_plural": "card templates",
"db_table": "cardtemplate",
"managed": True,
},
),
migrations.AlterModelOptions(
name="ball",
options={
"managed": True,
"verbose_name": "countryball",
"verbose_name_plural": "countryballs",
},
),
migrations.AlterModelOptions(
name="ballinstance",
options={"managed": True, "verbose_name": "countryball instance"},
),
migrations.AlterField(
model_name="ball",
name="country",
field=models.CharField(max_length=48, unique=True, verbose_name="Name"),
),
migrations.AddField(
model_name="regime",
name="card_template",
field=models.ForeignKey(
blank=True,
help_text="Card template to use",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="bd_models.cardtemplate",
),
),
migrations.AddField(
model_name="special",
name="card_template",
field=models.ForeignKey(
blank=True,
help_text="Card template to use",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="bd_models.cardtemplate",
),
),
]
32 changes: 31 additions & 1 deletion admin_panel/bd_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,32 @@ class Meta:
verbose_name_plural = "economies"


class CardTemplate(models.Model):
name = models.CharField(max_length=64)
template = models.JSONField(help_text="Card template JSON")

def __str__(self) -> str:
return self.name

class Meta:
managed = True
db_table = "cardtemplate"
verbose_name_plural = "card templates"


class Regime(models.Model):
name = models.CharField(max_length=64)
background = models.ImageField(max_length=200, help_text="1428x2000 PNG image")

card_template = models.ForeignKey(
CardTemplate,
on_delete=models.SET_NULL,
blank=True,
null=True,
help_text="Card template to use",
)
card_template_id: int | None

def __str__(self) -> str:
return self.name

Expand Down Expand Up @@ -169,6 +191,15 @@ class Special(models.Model):
max_length=64, help_text="Author of the special event artwork", null=True
)

card_template = models.ForeignKey(
CardTemplate,
on_delete=models.SET_NULL,
blank=True,
null=True,
help_text="Card template to use",
)
card_template_id: int | None

def __str__(self) -> str:
return self.name

Expand Down Expand Up @@ -249,7 +280,6 @@ def save(
using: str | None = None,
update_fields: Iterable[str] | None = None,
) -> None:

def lower_catch_names(names: str | None) -> str | None:
if names:
return ";".join([x.strip() for x in names.split(";")]).lower()
Expand Down
6 changes: 6 additions & 0 deletions admin_panel/preview/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from ballsdex.__main__ import init_tortoise
from ballsdex.core.models import (
Ball,
CardTemplate,
Economy,
Regime,
Special,
balls,
card_templates,
economies,
regimes,
specials,
Expand Down Expand Up @@ -40,3 +42,7 @@ async def refresh_cache():
specials.clear()
for special in await Special.all():
specials[special.pk] = special

card_templates.clear()
for card_template in await CardTemplate.all():
card_templates[card_template.pk] = card_template
11 changes: 9 additions & 2 deletions ballsdex/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
Ball,
BlacklistedGuild,
BlacklistedID,
CardTemplate,
Economy,
Regime,
Special,
balls,
card_templates,
economies,
regimes,
specials,
Expand Down Expand Up @@ -153,8 +155,8 @@ def __init__(

if settings.prometheus_enabled:
trace = aiohttp.TraceConfig()
trace.on_request_start.append(on_request_start)
trace.on_request_end.append(on_request_end)
trace.on_request_start.append(on_request_start) # pyright: ignore[reportArgumentType]
trace.on_request_end.append(on_request_end) # pyright: ignore[reportArgumentType]
options["http_trace"] = trace

super().__init__(command_prefix, intents=intents, tree_cls=CommandTree, **options)
Expand Down Expand Up @@ -240,6 +242,11 @@ async def load_cache(self):
specials[special.pk] = special
table.add_row("Special events", str(len(specials)))

card_templates.clear()
for card_template in await CardTemplate.all():
card_templates[card_template.pk] = card_template
table.add_row("Card Templates", str(len(card_templates)))

self.blacklist = set()
for blacklisted_id in await BlacklistedID.all().only("discord_id"):
self.blacklist.add(blacklisted_id.discord_id)
Expand Down
Loading