Skip to content

Commit

Permalink
random color things fix
Browse files Browse the repository at this point in the history
  • Loading branch information
catgirlinspace committed Nov 21, 2023
1 parent 9edff8a commit f0730c9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/splashcat.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion splatnet_assets/templates/splatnet_assets/mask_image.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load mask_id %}
{% get_color uploader %}
{% get_color uploader use_random_color %}
{% with object|mask_id as mask_id %}
<svg
class="{{ class }}" viewBox="0 0 {{ object.mask_image.width }} {{ object.mask_image.height }}"
Expand Down
13 changes: 11 additions & 2 deletions splatnet_assets/templatetags/mask_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import random

from django import template
from django.utils.crypto import get_random_string

from splatnet_assets.fields import Color
from splatnet_assets.models import SubWeapon, SpecialWeapon
from users.models import User, SponsorshipTiers

Expand All @@ -13,13 +16,19 @@ def mask_id(weapon_object: SubWeapon | SpecialWeapon):
return f"mask_id_{weapon_object.id}_{random_string}"


random_color_options = [
Color.from_hex("cd43a6"),
]


@register.simple_tag(takes_context=True)
def get_color(context, uploader: User):
def get_color(context, uploader: User, use_random_color: bool):
user = context.get('user')
if uploader.sponsor_tiers[SponsorshipTiers.SPONSOR]:
context['color'] = uploader.favorite_color
elif user and user.is_authenticated:
context['color'] = context['user'].favorite_color
if not context.get('color'):
context['color'] = uploader.battles.latest("played_time").teams.first().color
context['color'] = random.choice(random_color_options) if use_random_color else uploader.battles.latest(
"played_time").teams.first().color
return ''
2 changes: 1 addition & 1 deletion templates/splashcat/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h2 class="text-2xl font-splatoon1">Recent Battles</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
{% cache 60 home_global_recent_battles %}
{% for battle in recent_battles %}
{% include "users/includes/battle-card.html" with battle=battle display_uploader=True %}
{% include "users/includes/battle-card.html" with battle=battle display_uploader=True use_random_color=True %}
{% endfor %}
{% endcache %}
</div>
Expand Down

0 comments on commit f0730c9

Please sign in to comment.