118 lines
3.1 KiB
Python
118 lines
3.1 KiB
Python
# -*- mode: python; coding: utf-8 -*-
|
|
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from django.conf import settings
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
class GameSave(models.Model):
|
|
created_at = models.DateTimeField(
|
|
verbose_name=_('created at'),
|
|
default=timezone.now,
|
|
editable=False,
|
|
)
|
|
game_master = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.CASCADE,
|
|
verbose_name=_('game master'),
|
|
help_text=_('Game master can edit and delete this game save.'),
|
|
)
|
|
current_round = models.PositiveSmallIntegerField(
|
|
verbose_name=_('current round'),
|
|
default=1,
|
|
)
|
|
game_has_ended = models.BooleanField(
|
|
verbose_name=_('game has ended'),
|
|
help_text=_('If true, then everyone will be able to see the game.'),
|
|
)
|
|
|
|
def __str__(self):
|
|
return "{} ({} {})".format(
|
|
self.created_at.strftime("%b %d %Y %H:%M:%S"),
|
|
len(self.player_set.all()),
|
|
_("players"),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _("game save")
|
|
verbose_name_plural = _("game saves")
|
|
ordering = ['-created_at']
|
|
|
|
|
|
class Player(models.Model):
|
|
# Player roles
|
|
BASE_ASTRONAUT = 'BA'
|
|
BASE_MUTANT = 'BM'
|
|
HEALER = 'HE'
|
|
PSYCHOLOGIST = 'PS'
|
|
GENO_TECHNICIAN = 'GE'
|
|
COMPUTER_SCIENTIST = 'CO'
|
|
HACKER = 'HA'
|
|
SPY = 'SP'
|
|
DETECTIVE = 'DE'
|
|
TRAITOR = 'TR'
|
|
ROLES = [
|
|
(BASE_ASTRONAUT, _('Base astronaut')),
|
|
(BASE_MUTANT, _("Base mutant")),
|
|
(HEALER, _("Healer")),
|
|
(PSYCHOLOGIST, _("Psychologist")),
|
|
(GENO_TECHNICIAN, _("Geno-technician")),
|
|
(COMPUTER_SCIENTIST, _("Computer scientist")),
|
|
(HACKER, _("Hacker")),
|
|
(SPY, _("Spy")),
|
|
(DETECTIVE, _("Detective")),
|
|
(TRAITOR, _("Traitor")),
|
|
]
|
|
|
|
# Genotypes
|
|
NEUTRAL = None
|
|
HOST = False
|
|
IMMUNIZED = True
|
|
GENOTYPES = [
|
|
(NEUTRAL, _("Neutral")),
|
|
(HOST, _("Host")),
|
|
(IMMUNIZED, _("Immunized"))
|
|
]
|
|
|
|
game = models.ForeignKey(
|
|
GameSave,
|
|
on_delete=models.CASCADE,
|
|
verbose_name=_('game'),
|
|
)
|
|
name = models.CharField(
|
|
max_length=150,
|
|
verbose_name=_('name'),
|
|
)
|
|
user = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.CASCADE,
|
|
blank=True,
|
|
null=True,
|
|
verbose_name=_('user'),
|
|
help_text=_('Optionnal mapping to an user.'),
|
|
)
|
|
role = models.CharField(
|
|
max_length=2,
|
|
choices=ROLES,
|
|
default=BASE_ASTRONAUT,
|
|
)
|
|
genotype = models.NullBooleanField(
|
|
verbose_name=_('genotype'),
|
|
choices=GENOTYPES,
|
|
)
|
|
infected = models.BooleanField(
|
|
verbose_name=_('infected'),
|
|
)
|
|
|
|
def __str__(self):
|
|
return str(self.name)
|
|
|
|
class Meta:
|
|
verbose_name = _("player")
|
|
verbose_name_plural = _("players")
|
|
ordering = ['user__username']
|
|
unique_together = ['game', 'name']
|