Skip to content

Commit

Permalink
I hope I didn't break anything (rollback ig )
Browse files Browse the repository at this point in the history
fix a few issues + QOL stuff.

honestly just read the code.
  • Loading branch information
JasonLovesDoggo committed Dec 20, 2023
1 parent f46041e commit c389472
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 50 deletions.
13 changes: 13 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ def update_current_qr_i(self, i: int):
def is_full(self):
return self.members.count() >= self.hunt.max_team_size

@property
def completed_hunt(self):
return self.current_qr_i >= self.hunt.total_locations

@property
def is_empty(self):
return self.members.count() == 0
Expand Down Expand Up @@ -303,6 +307,15 @@ class Hunt(models.Model):
def __str__(self):
return self.name

@property
def total_locations(self) -> int:
mid = min(
self.path_length, self.middle_locations.count()
) # if mid-locations are less than path length, use mid-locations as it will have been cut
mid += 1 if self.ending_location else 0
mid += 1 if self.starting_location else 0
return mid

@classmethod
def closest_hunt(cls) -> Hunt | None:
now = timezone.now()
Expand Down
103 changes: 59 additions & 44 deletions core/templates/core/index.html
Original file line number Diff line number Diff line change
@@ -1,65 +1,80 @@
{% extends "core/base.html" %}
{% load i18n %}
{% load static %}
{% load qr %}

{% block title %}
{% translate "Scavenger Hunt" %}
{% translate "Scavenger Hunt" %}
{% endblock %}

{% block header %}
{% blocktranslate with username=request.user.username %}
welcome, {{ username }}!
{% endblocktranslate %}
{% blocktranslate with username=request.user.username %}
welcome, {{ username }}!
{% endblocktranslate %}
{% endblock %}

{% block head_end %}
<link rel="stylesheet" href="{% static 'core/index.css' %}"/>
<link rel="stylesheet" href="{% static 'core/index.css' %}"/>
{% endblock %}


{% block body %}
{% if IN_HUNT or FUTURE_HUNT_EXISTS %}
{% if request.user.in_team and IN_HUNT %}
{% url 'qr_first' as first_url %} {% comment %}todo: add logic to swich text to /current{% endcomment %}
{% url 'qr_current' as current_url %}
{% blocktranslate %}
{{ hunt_name }} has started! go decrypt your <a href="{{ first_url }}">first hint</a>!
{% endblocktranslate %}
<br />
{% url 'team_invite' as invite_url %}
{% blocktranslate %}
or, would you like to <a href="{{ invite_url }}">invite more team members</a>?
{% endblocktranslate %}
{% else %}
<h3>
{% if request.user.in_team %}
{% blocktranslate with team=request.user.current_team.name %}
your team: {{ team }}
{% endblocktranslate %}
{% if not IN_HUNT or request.user.team.hunt.allow_creation_post_start %}
{% if IN_HUNT or FUTURE_HUNT_EXISTS %}
{% if request.user.in_team %}
{% if IN_HUNT %}
{% if request.user.current_team.current_qr_i == 0 %}
{{ hunt_name }} has started! go decrypt your
<a href={% url 'qr_first' %}>first hint</a>!
{% elif request.user.current_team.completed_hunt %} {# The team is done the hunt #}

{% hunt_ending_text request.user.current_team.hunt %}
<br>
{% blocktranslate %} Oh ho ho?
What lieth there? Tis the light at the end of the tunnel!! Congratulations valiant scavenger and thank you for playing!
<br>
<br>
You can view all of the logic hints {% endblocktranslate %}<a href={% url 'logic_clues' %}>{% translate 'here' %}</a>. | {% translate 'You found:' %} {{ request.user.current_team.hunt.total_locations }}{% translate ' Qr Codes' %}

<a class="button" href="{% url 'team_invite' %}">{% translate "invite more team members" %}</a>

<a class="button" href="{% url 'team_leave' %}">{% translate "leave team" %}</a>
{% endif %}
{% endif %}
</h3>
<ul class="nodot">
{% if not request.user.in_team %}
<li>
<a class="button" href="{% url 'join' %}">{% translate "join a team" %}</a>
</li>
<li>
<a class="button" href="{% url 'team_create' %}">{% translate "create a team" %}</a>
</li>
{% endif %}
</ul>
{% endif %}
{% else %}
<h2>
{% else %}
{{ hunt_name }} is in progress! go decrypt your
<a href={% url 'qr_current' %}>current hint</a>!
{% endif %}
<br/>
{% endif %}

<h3>
{% if not IN_HUNT or request.user.current_team.hunt.allow_creation_post_start %}
<ul class="nodot">
<li>
<a class="button"
href="{% url 'team_invite' %}">{% translate "invite more team members" %}</a>
</li>

<li><a class="button" href="{% url 'team_leave' %}">{% translate "leave team" %}</a></li>
</ul>
{% endif %}
</h3>

{% else %}
{% if not request.user.in_team %}
<ul class="nodot"> {# If The user is not in a team #}

<li>
<a class="button" href="{% url 'join' %}">{% translate "join a team" %}</a>
</li>
<li>
<a class="button" href="{% url 'team_create' %}">{% translate "create a team" %}</a>
</li>
</ul>
{% endif %}

{% endif %}
{% else %} {# Not in a hunt and no future hunt is scheduled #}
<h2>
{% blocktranslate %}
no future scavenger hunt is scheduled, please check back later
no future scavenger hunt is scheduled, please check back later
{% endblocktranslate %}
{% endif %}
</h2>
</h2>
{% endblock %}
5 changes: 3 additions & 2 deletions core/templates/core/qr.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
src.onmessage = (e) => {
console.log('msg', e)
}
// src.onmessage = (e) => location.reload()
// src.onmessage = (e) => location.reload() this a cool idea but we need to add more to it.
setInterval(() => console.log(src.readyState), 1000)
</script>
{% endif %}
{% endblock %}


{% block body %}
<div class="text-container">
{% if not first and qr is not None %}
Expand Down Expand Up @@ -66,7 +67,7 @@
</div>
{% endif %}
{% else %}
{% ending_block request.user.current_team.hunt %}
{% hunt_ending_text request.user.current_team.hunt %}
{% translate 'Oh ho? What lieth there? Tis the light at the end of the tunnel! <br /> Congratulations valiant scavenger and thank you for playing!' %}
{% endif %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion core/templatetags/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def join_url(code):


@register.simple_tag
def ending_block(hunt):
def hunt_ending_text(hunt):
pattern = r"{{(.*?)}}"
match = re.search(pattern, hunt.ending_text)

Expand Down
6 changes: 3 additions & 3 deletions core/views/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ def qr(request, key):
if request.user.is_debuggable:
return redirect(qr_code.get_admin_url())
context["qr_code"]: QrCode
current_i = min(request.user.current_team.current_qr_i, len(codes) - 1)
if qr_code is None:
# User just tried brute-forcing keys... lol
context["offpath"] = True
return render(request, "core/qr.html", context=context)
elif (
qr_code.id == codes[request.user.current_team.current_qr_i - 1]
and len(codes) > 1
qr_code.id == codes[current_i - 1] and len(codes) > 1
): # the user reloaded the page after advancing...or there is only one qr code in the hunt
return redirect(reverse("qr_current"))
elif (
qr_code.id != codes[request.user.current_team.current_qr_i]
qr_code.id != codes[current_i]
): # fix index out of range (should have been the above anyhow)
"""
Either the user skipped ahead (is on path) or they found a random qr code (not on path)
Expand Down

0 comments on commit c389472

Please sign in to comment.