Resolve "Fragentyp: Ort suchen" #270
@@ -232,8 +232,10 @@ class GameConsumer(AsyncWebsocketConsumer):
|
|||||||
|
|
||||||
# Parse the coordinates
|
# Parse the coordinates
|
||||||
target_location = parse_coords(target_location)
|
target_location = parse_coords(target_location)
|
||||||
|
answer_location_coords = answer_location
|
||||||
answer_location = parse_coords(answer_location)
|
answer_location = parse_coords(answer_location)
|
||||||
|
|
||||||
|
|
||||||
if not target_location or not answer_location:
|
if not target_location or not answer_location:
|
||||||
print("Invalid coordinates, cannot calculate score")
|
print("Invalid coordinates, cannot calculate score")
|
||||||
is_correct = False
|
is_correct = False
|
||||||
@@ -312,6 +314,7 @@ class GameConsumer(AsyncWebsocketConsumer):
|
|||||||
|
|
||||||
participant.last_score = score
|
participant.last_score = score
|
||||||
participant.score += score
|
participant.score += score
|
||||||
|
participant.coordinate_answer= answer_location_coords
|
||||||
participant.last_answer_correct = is_correct
|
participant.last_answer_correct = is_correct
|
||||||
participant.save()
|
participant.save()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-11-01 15:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('play', '0015_alter_quizgame_current_state'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='quizgameparticipant',
|
||||||
|
name='coordinate_answer',
|
||||||
|
field=models.CharField(blank=True, max_length=256, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -50,6 +50,7 @@ class QuizGameParticipant(models.Model):
|
|||||||
avatar = models.CharField(max_length=200, blank=True, default="")
|
avatar = models.CharField(max_length=200, blank=True, default="")
|
||||||
last_heartbeat = models.DateTimeField(auto_now_add=True)
|
last_heartbeat = models.DateTimeField(auto_now_add=True)
|
||||||
last_answer = models.IntegerField(null=True, blank=True)
|
last_answer = models.IntegerField(null=True, blank=True)
|
||||||
|
coordinate_answer = models.CharField(null=True, blank=True,max_length=256)
|
||||||
last_answer_correct = models.BooleanField(null=True, blank=True)
|
last_answer_correct = models.BooleanField(null=True, blank=True)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -20,6 +20,20 @@
|
|||||||
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
||||||
crossorigin=""></script>
|
crossorigin=""></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
const participantAnswers = [
|
||||||
|
{% for participant in participants %}
|
||||||
|
{% if participant.coordinate_answer %}
|
||||||
|
"{{ participant.coordinate_answer }}",
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
// Parse the target location from the string format "lat,lng"
|
// Parse the target location from the string format "lat,lng"
|
||||||
const targetCoords = '{{ question_data.target_location|escapejs }}'.split(',');
|
const targetCoords = '{{ question_data.target_location|escapejs }}'.split(',');
|
||||||
@@ -65,6 +79,21 @@
|
|||||||
noWrap: true
|
noWrap: true
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
|
participantAnswers.forEach(coordStr => {
|
||||||
|
const coords = coordStr.split(',').map(Number);
|
||||||
|
if (coords.length === 2 && !coords.some(isNaN)) {
|
||||||
|
const marker = L.marker(coords).addTo(map).bindPopup('Antwort eines Teilnehmers');
|
||||||
|
|
||||||
|
// Linie vom Ziel zum Teilnehmermarker
|
||||||
|
L.polyline([targetLocation, coords], {
|
||||||
|
color: '#f59e0b',
|
||||||
|
weight: 2, // Linienstärke
|
||||||
|
dashArray: '5,5', // gestrichelte Linie
|
||||||
|
opacity: 0.6
|
||||||
|
}).addTo(map);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add target marker
|
// Add target marker
|
||||||
L.marker(targetLocation, {
|
L.marker(targetLocation, {
|
||||||
icon: L.divIcon({
|
icon: L.divIcon({
|
||||||
|
|||||||
Reference in New Issue
Block a user