Skip to content

Commit

Permalink
hint logic - styling
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Dec 13, 2022
1 parent 03287b0 commit 28ea9b1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 46 deletions.
11 changes: 8 additions & 3 deletions scavenger2022/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import random
import secrets

Expand Down Expand Up @@ -121,7 +123,6 @@ def invites(self):

def get_qr_nth(self):
"""Get the total amount of qr codes the team has completed"""
print(int(self.current_qr_i) + 1) # todo remove. this is just for debugging
return int(self.current_qr_i) + 1

def __str__(self):
Expand Down Expand Up @@ -169,5 +170,9 @@ def __str__(self):
return str(self.hint)

@classmethod
def get_hint(cls, team: Team):
return cls.objects.get(qr_index=team.get_qr_nth()).hint
def get_hint(cls, team: Team) -> str | None:
try:
hint = cls.objects.get(qr_index=team.get_qr_nth())
return hint.hint
except cls.DoesNotExist:
return None
7 changes: 6 additions & 1 deletion scavenger2022/core/static/core/qr.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main {
height: 500px;
}

.padding {
.padding {
flex-grow: 1;
}

Expand All @@ -27,3 +27,8 @@ main {
.hint-top {
font-size: 2rem;
.}


.logic {
font-size: 2rem
}
94 changes: 53 additions & 41 deletions scavenger2022/core/templates/core/qr.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,66 @@
{% load qr %}

{% block title %}
{% comment %} TODO: Create a progress bar (or some percentage indicator) {% endcomment %}
Hint
{% comment %} TODO: Create a progress bar (or some percentage indicator) {% endcomment %}
Hint
{% endblock %}

{% block head_end %}
<link rel="stylesheet" href="{% static 'core/qr.css' %}" />
{% if current %}
<script type="module">
const src = new EventSource("{% url 'qr_signal' %}")
src.onopen = (e) => console.log('signal opened')
src.onerror = console.error
src.onmessage = (e) => {
console.log('msg', e)
}
// src.onmessage = (e) => location.reload()
setInterval(() => console.log(src.readyState), 1000)
</script>
{% endif %}
<link rel="stylesheet" href="{% static 'core/qr.css' %}"/>
{% if current %}
<script type="module">
const src = new EventSource("{% url 'qr_signal' %}")
src.onopen = (e) => console.log('signal opened')
src.onerror = console.error
src.onmessage = (e) => {
console.log('msg', e)
}
// src.onmessage = (e) => location.reload()
setInterval(() => console.log(src.readyState), 1000)
</script>
{% endif %}
{% endblock %}

{% block body %}
<div class="buffer">
{% if not first %}
You got the hint: {% hint qr request.user.team %}
{% endif %}
</div>
<div class="padding"></div>
<div class="hint">
<div class="hint-top">
<div class="buffer">
{% if not first %}
You got the hint: {% hint qr request.user.team %}
{% endif %}
</div>
<div class="padding"></div>
<div class="hint">
<div class="hint-top">
{% if nextqr %}
{% if first %}
Your first hint is:
{% else %}
Your next hint is:
{% endif %}
{% else %}
<img src="https://www.hanshin.co.jp/h_common/img/taisetsu.svg" alt="rainbow-coloured heart"/>
(TODO: some colourful heart)
{% endif %}
{% if request.user.is_superuser %}
({{ nextqr }})
{% endif %}

</div>
{% if nextqr %}
{% if first %}
Your first hint is:
{% else %}
Your next hint is:
{% endif %}
{% hint nextqr request.user.team %}

{% if logic_hint %}
<div class="hint-logic">

<p>Logic Hint:</p>

<p>{{ logic_hint }}</p>

</div>
{% endif %}
{% else %}
<img src="https://www.hanshin.co.jp/h_common/img/taisetsu.svg" alt="rainbow-coloured heart" />
(TODO: some colourful heart)
Thank you for playing!
{% endif %}
{% if request.user.is_superuser %}
({{ nextqr }})
{% endif %}
</div>
{% if nextqr %}
{% hint nextqr request.user.team %}
{% else %}
Thank you for playing!
{% endif %}
</div>
<div class="padding"></div>

</div>
<div class="padding"></div>
{% endblock %}
1 change: 0 additions & 1 deletion scavenger2022/core/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def oauth_auth(q):
s2d = q2.json()
access_token = s2d["access_token"]
refresh_token = s2d["refresh_token"]
print(settings.YASOI["me_url"])
q3 = requests.get(
settings.YASOI["me_url"], headers={"Authorization": f"Bearer {access_token}"}
)
Expand Down
4 changes: 4 additions & 0 deletions scavenger2022/core/views/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ def qr_first(request):
context["qr"] = QrCode.codes(request.user.team)[0]
codes = QrCode.code_pks(request.user.team)
context["nextqr"] = QrCode.objects.get(id=codes[0])
context["logic_hint"] = LogicPuzzleHint.get_hint(
request.user.team
) # todo mayve this should be under the next two lines?
request.user.team.update_current_qr_i(0)
request.user.team.save()

return render(request, "core/qr.html", context=context)


Expand Down

0 comments on commit 28ea9b1

Please sign in to comment.