1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 21:44:21 +00:00

more spooky stuff

This commit is contained in:
Steffo 2018-10-03 19:43:56 +02:00
parent c76b110402
commit 38ed4c292d
6 changed files with 128 additions and 193 deletions

220
db.py
View file

@ -1,6 +1,8 @@
import datetime import datetime
import logging import logging
import os import os
import typing
import coloredlogs import coloredlogs
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship, joinedload from sqlalchemy.orm import sessionmaker, relationship, joinedload
@ -902,172 +904,76 @@ class Halloween(Base):
boss_battle = Column(DateTime) boss_battle = Column(DateTime)
def __getitem__(self, item):
if not isinstance(item, int):
raise TypeError("The index should be an int")
if item == 1:
return self.puzzle_piece_a
elif item == 2:
return self.puzzle_piece_b
elif item == 3:
return self.puzzle_piece_c
elif item == 4:
return self.puzzle_piece_d
elif item == 5:
return self.puzzle_piece_e
elif item == 6:
return self.puzzle_piece_f
elif item == 7:
return self.puzzle_piece_g
elif item == 8:
return self.puzzle_piece_h
elif item == 9:
return self.puzzle_piece_i
elif item == 10:
return self.puzzle_piece_j
else:
raise ValueError("No such puzzle piece")
def __setitem__(self, key, value):
if not isinstance(key, int):
raise TypeError("The index should be an int")
if key == 1:
self.puzzle_piece_a = value
elif key == 2:
self.puzzle_piece_b = value
elif key == 3:
self.puzzle_piece_c = value
elif key == 4:
self.puzzle_piece_d = value
elif key == 5:
self.puzzle_piece_e = value
elif key == 6:
self.puzzle_piece_f = value
elif key == 7:
self.puzzle_piece_g = value
elif key == 8:
self.puzzle_piece_h = value
elif key == 9:
self.puzzle_piece_i = value
elif key == 10:
self.puzzle_piece_j = value
else:
raise ValueError("No such puzzle piece")
def pieces_completed(self) -> int: def pieces_completed(self) -> int:
count = 0 count = 0
if self.puzzle_piece_a is not None: for i in range(1, 11):
count += 1 if self[i]:
if self.puzzle_piece_b is not None:
count += 1
if self.puzzle_piece_c is not None:
count += 1
if self.puzzle_piece_d is not None:
count += 1
if self.puzzle_piece_e is not None:
count += 1
if self.puzzle_piece_f is not None:
count += 1
if self.puzzle_piece_g is not None:
count += 1
if self.puzzle_piece_h is not None:
count += 1
if self.puzzle_piece_i is not None:
count += 1
if self.puzzle_piece_j is not None:
count += 1 count += 1
return count return count
@staticmethod @staticmethod
def puzzle_is_complete() -> bool: def puzzle_status() -> typing.List[bool]:
session = Session() session = Session()
halloweens = session.query(Halloween).all() halloweens = session.query(Halloween).all()
session.close() session.close()
completed_a = False completed = [False for _ in range(10)]
completed_b = False for h in halloweens:
completed_c = False for i in range(10):
completed_d = False if h[i+1]:
completed_e = False completed[i] = True
completed_f = False return completed
completed_g = False
completed_h = False
completed_i = False
completed_j = False
for halloween in halloweens:
if halloween.puzzle_piece_a is not None:
completed_a = True
if halloween.puzzle_piece_b is not None:
completed_b = True
if halloween.puzzle_piece_c is not None:
completed_c = True
if halloween.puzzle_piece_d is not None:
completed_d = True
if halloween.puzzle_piece_d is not None:
completed_d = True
if halloween.puzzle_piece_e is not None:
completed_e = True
if halloween.puzzle_piece_f is not None:
completed_f = True
if halloween.puzzle_piece_g is not None:
completed_g = True
if halloween.puzzle_piece_h is not None:
completed_h = True
if halloween.puzzle_piece_i is not None:
completed_i = True
if halloween.puzzle_piece_j is not None:
completed_j = True
return (completed_a and completed_b and completed_c and completed_d and completed_e
and completed_f and completed_g and completed_h and completed_i and completed_j)
@staticmethod
def puzzle_piece_a_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_a is not None:
return True
return False
@staticmethod
def puzzle_piece_b_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_b is not None:
return True
return False
@staticmethod
def puzzle_piece_c_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_c is not None:
return True
return False
@staticmethod
def puzzle_piece_d_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_d is not None:
return True
return False
@staticmethod
def puzzle_piece_e_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_e is not None:
return True
return False
@staticmethod
def puzzle_piece_f_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_f is not None:
return True
return False
@staticmethod
def puzzle_piece_g_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_g is not None:
return True
return False
@staticmethod
def puzzle_piece_h_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_h is not None:
return True
return False
@staticmethod
def puzzle_piece_i_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_i is not None:
return True
return False
@staticmethod
def puzzle_piece_j_complete() -> bool:
session = Session()
halloweens = session.query(Halloween).all()
session.close()
for halloween in halloweens:
if halloween.puzzle_piece_j is not None:
return True
return False
# If run as script, create all the tables in the db # If run as script, create all the tables in the db
if __name__ == "__main__": if __name__ == "__main__":

Binary file not shown.

View file

@ -755,12 +755,11 @@ table {
padding: 18px; padding: 18px;
grid-template-columns: 100%; grid-template-columns: 100%;
.stars { .moons.game-score {
grid-column: 1; font-size: 0;
i { i {
color: yellow; font-size: 34px;
font-size: 30px;
} }
} }
} }
@ -863,21 +862,13 @@ ntry {
.lower-box { .lower-box {
text-align: center; text-align: center;
.stars a {
color: @text-color;
font-size: 64px;
&:hover {
color: @highlight-color;
}
.fas {
color: yellow;
}
}
.time-left { .time-left {
font-size: 64px; font-size: 64px;
font-family: monospace;
}
.moons {
font-size: 64px;
} }
} }
} }
@ -930,6 +921,18 @@ ntry {
} }
} }
.moons a {
color: @text-color;
&:hover {
color: @highlight-color;
}
.fas {
color: yellow;
}
}
#debug-mode { #debug-mode {
color: red; color: red;
font-weight: bold; font-weight: bold;

View file

@ -36,12 +36,12 @@
</div> </div>
<div class="lower-box"> <div class="lower-box">
Lune raccolte: Lune raccolte:
<div class="stars"> <div class="moons">
{% for index, star in halloween %} {% for index, star in halloween %}
{% if star %} {% if star %}
<a href="/ritual/{{ index + 1 }}" title="Passo {{ index + 1 }} completato!"><i class="fas fa-moon"></i></a> <a href="/ritual/{{ index }}" title="Luna {{ index }} ottenuta!"><i class="fas fa-moon"></i></a>
{% else %} {% else %}
<a href="/ritual/{{ index + 1 }}" title="Passo {{ index + 1 }}"><i class="far fa-moon"></i></a> <a href="/ritual/{{ index }}" title="Rituale {{ index }}"><i class="far fa-moon"></i></a>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
@ -97,6 +97,9 @@
<div class="lower-box"> <div class="lower-box">
<ul> <ul>
<li><a href="/game/ryg">Royal Games</a></li> <li><a href="/game/ryg">Royal Games</a></li>
{% if config["DEBUG"] %}
<li><a href="/game/halloween">Rituale di Halloween</a></li>
{% endif %}
<li><a href="/game/tg">Telegram</a></li> <li><a href="/game/tg">Telegram</a></li>
<li><a href="/game/discord">Discord</a></li> <li><a href="/game/discord">Discord</a></li>
<li><a href="/game/steam">Steam</a></li> <li><a href="/game/steam">Steam</a></li>
@ -105,7 +108,6 @@
<li><a href="/game/lol">League of Legends</a></li> <li><a href="/game/lol">League of Legends</a></li>
<li><a href="/game/ow">Overwatch</a></li> <li><a href="/game/ow">Overwatch</a></li>
<li><a href="/game/osu">osu!</a></li> <li><a href="/game/osu">osu!</a></li>
<!--li><a href="/game/halloween">Rituale di Halloween</a></li-->
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -3,12 +3,16 @@
<div class="player"> <div class="player">
<span class="player-name">Rituale di Halloween</span> <span class="player-name">Rituale di Halloween</span>
</div> </div>
<div class="game-title stars"> <div class="game-title moons">
Lune ottenute Lune ottenute
</div> </div>
<div class="game-score stars"> <div class="game-score moons">
{% for index in range(record.pieces_completed()) %} {% for index in range(10) %}
<i class="fas fa-moon"></i> {% if halloween[index] %}
<a href="/ritual/{{ index + 1 }}" title="Luna {{ index + 1 }} ottenuta!"><i class="fas fa-moon"></i></a>
{% else %}
<a href="/ritual/{{ index + 1 }}" title="Rituale {{ index + 1 }}"><i class="far fa-moon"></i></a>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

View file

@ -66,18 +66,7 @@ def page_main():
random_diario = db_session.query(db.Diario).order_by(db.func.random()).first() random_diario = db_session.query(db.Diario).order_by(db.func.random()).first()
next_events = db_session.query(db.Event).filter(db.Event.time > datetime.datetime.now()).order_by( next_events = db_session.query(db.Event).filter(db.Event.time > datetime.datetime.now()).order_by(
db.Event.time).all() db.Event.time).all()
halloween = [ halloween = db.Halloween.puzzle_status()
db.Halloween.puzzle_piece_a_complete(),
db.Halloween.puzzle_piece_b_complete(),
db.Halloween.puzzle_piece_c_complete(),
db.Halloween.puzzle_piece_d_complete(),
db.Halloween.puzzle_piece_e_complete(),
db.Halloween.puzzle_piece_f_complete(),
db.Halloween.puzzle_piece_g_complete(),
db.Halloween.puzzle_piece_h_complete(),
db.Halloween.puzzle_piece_i_complete(),
db.Halloween.puzzle_piece_j_complete()
]
db_session.close() db_session.close()
return render_template("main.html", royals=royals, wiki_pages=wiki_pages, entry=random_diario, return render_template("main.html", royals=royals, wiki_pages=wiki_pages, entry=random_diario,
next_events=next_events, rygconf=config, escape=escape, halloween=enumerate(halloween)) next_events=next_events, rygconf=config, escape=escape, halloween=enumerate(halloween))
@ -343,6 +332,37 @@ def page_diario():
return render_template("diario.html", rygconf=config, entries=diario_entries) return render_template("diario.html", rygconf=config, entries=diario_entries)
@app.route("/ritual/<int:n>", methods=["GET", "POST"])
def page_ritual(n: int):
user_id = fl_session.get("user_id")
if not user_id:
return redirect(url_for("page_login"))
if request.method == "GET":
return render_template("ritual.html", rygconf=config, n=n)
elif request.method == "POST":
if n == 1:
pass
elif n == 2:
pass
elif n == 3:
pass
elif n == 4:
pass
elif n == 5:
pass
elif n == 6:
pass
elif n == 7:
pass
elif n == 8:
pass
elif n == 9:
pass
elif n == 10:
pass
return redirect(url_for("page_ritual", n=n))
if __name__ == "__main__": if __name__ == "__main__":
try: try:
app.run(host="0.0.0.0", port=1235, debug=__debug__) app.run(host="0.0.0.0", port=1235, debug=__debug__)