Browse Source

trophies: add categories and awarding conditions

This is groundwork for categories, but not a full implementation
yet, trophy removal is not handled.
undefined
Lephe 1 month ago
parent
commit
61a8eeccba
2 changed files with 190 additions and 29 deletions
  1. 94
    10
      app/data/trophies.yaml
  2. 96
    19
      app/models/users.py

+ 94
- 10
app/data/trophies.yaml View File

@@ -1,3 +1,13 @@
# This is a list of trophies. For each trophies, the following keys may be set:
# name Trophy name as displayed on the site.
# is_title If True, the trophy can be worn as a title next to the avatar.
# ctgy Trophy category, for grouping and layout purposes.
# level Trophy level, if this is a progressive category.
#
# Trophies without categories are taken to be manually-awarded. If a trophy is
# awarded automatically, assign it a category even if it's alone.

# Manually awarded
-
name: Membre de CreativeCalc
is_title: True
@@ -13,81 +23,155 @@
-
name: Grand Maitre des traits d'esprit
is_title: True

# Number of posts of any kind
-
name: Premiers mots
is_title: False
ctgy: post_count
level: 1
-
name: Beau parleur
is_title: False
ctgy: post_count
level: 2
-
name: Jeune écrivain
name: Plume infaillible
is_title: False
ctgy: post_count
level: 3
-
name: Romancier émérite
is_title: True
-
name: Apprenti instructeur
is_title: False
ctgy: post_count
level: 4

# Number of posted tutorials
-
name: Pédagogue averti
is_title: False
ctgy: tutorial_count
level: 1
-
name: Encyclopédie vivante
is_title: False
ctgy: tutorial_count
level: 2
-
name: Guerrier du savoir
is_title: True
ctgy: tutorial_count
level: 3

# Account age (awarded on login only)
-
name: Nouveau
name: Initié
is_title: False
ctgy: account_age
level: 1
-
name: Aficionado
is_title: False
ctgy: account_age
level: 2
-
name: Veni, vidi, casii
is_title: False
ctgy: account_age
level: 3
-
name: Papy Casio
is_title: True
ctgy: account_age
level: 4
-
name: Vétéran mythique
is_title: True
ctgy: account_age
level: 5

# Number of "good" programs
-
name: Programmeur du dimanche
is_title: False
ctgy: good_programs
level: 1
-
name: Codeur invétéré
is_title: False
ctgy: good_programs
level: 2
-
name: Je code donc je suis
is_title: True
ctgy: good_programs
level: 3

# Number of posted tests
-
name: Testeur
is_title: False
ctgy: test_count
level: 1
-
name: Examinateur
name: Grand joueur
is_title: False
ctgy: test_count
level: 2
-
name: Hard tester
is_title: True
ctgy: test_count
level: 3

# Number of event participations
-
name: Participant avéré
name: Participant
is_title: False
ctgy: event_participations
level: 1
-
name: Concourant encore
is_title: False
ctgy: event_participations
level: 2
-
name: Concurrent de l’extrême
name: Concurrent de l'extrême
is_title: True
ctgy: event_participations
level: 3

# Number of posted art
-
name: Designer en herbe
name: Dessinateur en herbe
is_title: False
ctgy: art_count
level: 1
-
name: Graphiste expérimenté
name: Open pixel
is_title: False
ctgy: art_count
level: 2
-
name: Roi du pixel
is_title: True
ctgy: art_count
level: 3

# Miscellaneous automatically awarded
-
name: Actif
is_title: False
ctgy: activity
-
name: Artiste
is_title: False
ctgy: avatar
-
name: Maître du code
is_title: True
ctgy: label_count
-
name: Bourreau des cœurs
is_title: True
ctgy: heart_count

+ 96
- 19
app/models/users.py View File

@@ -243,38 +243,115 @@ class Member(User, db.Model):
- new-tutorial
- new-test
- new-event-participation
- new-picture
- on-program-reward
- new-art
- on-program-tested
- on-program-rewarded
- on-login
- on-profile-update
"""

if context == "new-post" or context is None:
pass
if context == "new-program" or context is None:
pass
if context == "new-tutorial" or context is None:
pass
if context == "new-test" or context is None:
pass
if context == "new-event-participation" or context is None:
pass
if context == "new-picture" or context is None:
pass
if context == "on-program-reward" or context is None:
pass
if context == "on-login" or context is None:
if context in ["new-post", "new-program", "new-tutorial", "new-art",
None]:
# TODO: Amount of posts by the user
post_count = 0

if post_count >= 20:
self.add_trophy("Premiers mots")
if post_count >= 250:
self.add_trophy("Beau parleur")
if post_count >= 1500:
self.add_trophy("Plume infaillible")
if post_count >= 5000:
self.add_trophy("Romancier émérite")

if context in ["new-program", None]:
# TODO: Amount of *GOOD* programs by the user
# (Criterion could be >= 7/10 for at least 3 notes/tests)
good_programs = 0

if good_programs >= 5:
self.add_trophy("Programmeur du dimanche")
if good_programs >= 10:
self.add_trophy("Codeur invétéré")
if good_programs >= 20:
self.add_trophy("Je code donc je suis")

if context in ["new-tutorial", None]:
# TODO: Number of tutorials by user
tutorial_count = 0

if tutorial_count >= 5:
self.add_trophy("Pédagogue averti")
if tutorial_count >= 10:
self.add_trophy("Encyclopédie vivante")
if tutorial_count >= 25:
self.add_trophy("Guerrier du savoir")

if context in ["new-test", None]:
# TODO: Number of tests by user
test_count = 0

if test_count >= 5:
self.add_trophy("Testeur")
if test_count >= 25:
self.add_trophy("Grand joueur")
if test_count >= 100:
self.add_trophy("Hard tester")

if context in ["new-event-participation", None]:
# TODO: Number of event participations by user
event_participations = 0

if event_participations >= 1:
self.add_trophy("Participant")
if event_participations >= 5:
self.add_trophy("Concourant encore")
if event_participations >= 15:
self.add_trophy("Concurrent de l'extrême")

if context in ["new-art", None]:
# TODO: Number of art posts by user
art_count = 0

if art_count >= 5:
self.add_trophy("Dessinateur en herbe")
if art_count >= 30:
self.add_trophy("Open pixel")
if art_count >= 100:
self.add_trophy("Roi du pixel")

if context in ["on-program-tested", None]:
# TODO: Number of "coups de coeur" of user
heart_count = 0

if heart_count >= 5:
self.add_trophy("Bourreau des cœurs")

if context in ["on-program-rewarded", None]:
# TODO: Number of programs with labels
label_count = 0

if label_count >= 5:
self.add_trophy("Maître du code")

if context in ["on-login", None]:
# Seniority-based trophies
age = date.today() - self.register_date

if age.days > 30:
self.add_trophy("Nouveau")
self.add_trophy("Inité")
if age.days > 365.25:
self.add_trophy("Aficionado")
if age.days > 365.25 * 2:
self.add_trophy("Veni, vidi, casii")
if age.days > 365.25 * 5:
self.add_trophy("Papy Casio")
if context == "on-profile-update" or context is None:
if age.days > 365.25 * 10:
self.add_trophy("Vétéran mythique")

# TODO: Trophy "actif"

if context in ["on-profile-update", None]:
# TODO: add a better condition (this is for test)
self.add_trophy("Artiste")


Loading…
Cancel
Save