Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
env/
venv/
.git
.gitignore
.DS_Store
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/

WORKDIR /app

COPY . .

RUN uv sync --locked --no-dev

EXPOSE 5000

CMD ["uv", "run", "clonenames"]
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ dev = [
"ruff>=0.12.0",
]

# BUILDING
[tool.setuptools]
packages = ["clonenames"]
# # BUILDING
# [tool.setuptools]
# packages = ["clonenames"]

# FORMATTING
[tool.ruff]
Expand Down
4 changes: 2 additions & 2 deletions src/clonenames/clonenames.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def check_size(self, size: int) -> None:
self.length = int(self.size ** 0.5)

def load_words(self) -> None:
from time import clock
random.seed(clock())
from time import perf_counter
random.seed(perf_counter())

self.COLORS = [u'red', u'blue', u'green', u'yellow']
random.shuffle(self.COLORS)
Expand Down
133 changes: 70 additions & 63 deletions src/clonenames/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,116 +25,123 @@
games = dict()


@app.route(u'/')
@app.route("/")
def home_page():
return render_template(u'index.html')
return render_template("index.html")


@app.route(u'/start', methods = [u'GET', u'POST'])
@app.route("/start", methods=["GET", "POST"])
def start_page():
if request.method == u'POST':
game = clonenames.Board(request.form.get(u'words'))
if request.method == "POST":
game = clonenames.Board(request.form.get("words"))

success = game.load_settings(
teams = int(request.form.get(u'number')),
size = int(request.form.get(u'size')))
teams=int(request.form.get("number")), size=int(request.form.get("size"))
)

if success:
room = generate_room_code()

games[room] = game

return redirect(url_for(u'game_page', room = room))
return redirect(url_for("game_page", room=room))

else:
return render_template(
u'start.html',
words = clonenames.wordlists,
alert = u'The word list selected must be played on a smaller game board... Sorry!')
"start.html",
words=clonenames.wordlists,
alert="The word list selected must be played on a smaller game board... Sorry!",
)

elif request.method == u'GET':
return render_template(u'start.html', words = wordlists)
elif request.method == "GET":
return render_template("start.html", words=wordlists)


@app.route(u'/game', methods = [u'GET', u'POST'])
@app.route("/game", methods=["GET", "POST"])
def game_page():
if request.args.get(u'room'):
room = request.args.get(u'room')
if request.args.get("room"):
room = request.args.get("room")
return render_template(
u'game.html',
show_input = False,
room = room,
host = True,
words = games[room].table(),
start = games[room].order[0],
remnants = games[room].remnants)
"game.html",
show_input=False,
room=room,
host=True,
words=games[room].table(),
start=games[room].order[0],
remnants=games[room].remnants,
)

else:
try:
if request.method == u'GET':
return render_template(
u'game.html',
show_input = True)
if request.method == "GET":
return render_template("game.html", show_input=True)

elif request.method == u'POST':
room = request.form.get(u'room', False).upper()
elif request.method == "POST":
room = request.form.get("room", False).upper()
if check_room_code(room):
return render_template(
u'game.html',
show_input = False,
room = room,
host = request.form.get(u'host', False) == u'on',
words = games[room].table(),
start = games[room].order[0],
remnants = games[room].remnants)
"game.html",
show_input=False,
room=room,
host=request.form.get("host", False) == "on",
words=games[room].table(),
start=games[room].order[0],
remnants=games[room].remnants,
)

else:
return render_template(
u'game.html',
show_input = True,
alert = u'The room code you entered does not exist. Please try again!')
"game.html",
show_input=True,
alert="The room code you entered does not exist. Please try again!",
)

except AttributeError:
return redirect(url_for(u'home_page'))
return redirect(url_for("home_page"))


# @app.route(u'/statistics')
# def stats_page():
# return render_template(u'statistics.html',
# rooms = [games[game].statistics() for game in games])


@socketio.on(u'join')
@socketio.on("join")
def join(data):
join_room(data[u'room'])
join_room(data["room"])


@socketio.on(u'clicked')
@socketio.on("clicked")
def handle_host_click(json):
response = games[json[u'room']].get(json[u'id'])
socketio.emit(u'revealed', {
u'text': u'Host clicked on {word}'.format(
word = response[u'word']),
u'id': u'#{id}'.format(id = json[u'id']),
u'remnant': response[u'remnant'],
u'class': u'btn-{team}'.format(
team = response[u'team'])}, room = json['room'])


@socketio.on(u'ended_turn')
response = games[json["room"]].get(json["id"])
socketio.emit(
"revealed",
{
"text": "Host clicked on {word}".format(word=response["word"]),
"id": "#{id}".format(id=json["id"]),
"remnant": response["remnant"],
"class": "btn-{team}".format(team=response["team"]),
},
room=json["room"],
)


@socketio.on("ended_turn")
def handle_end_turn(json):
team = games[json[u'room']].advance_turn()
team = games[json["room"]].advance_turn()

alert = u'alert {team}-start alert-start'.format(team = team)
button = u'btn btn-{team} float-right'.format(team = team)
alert = "alert {team}-start alert-start".format(team=team)
button = "btn btn-{team} float-right".format(team=team)

socketio.emit(u'change_turn', {
u'alert': alert,
u'text': team,
u'button': button}, room = json[u'room'])
socketio.emit(
"change_turn",
{"alert": alert, "text": team, "button": button},
room=json["room"],
)


def generate_room_code():
letters = u''.join(random.sample(list(u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 5))
letters = "".join(random.sample(list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 5))
while letters in games.keys():
return generate_room_code()

Expand All @@ -146,4 +153,4 @@ def check_room_code(code):


def run():
socketio.run(app, debug=True, host=u'0.0.0.0', port=12345)
socketio.run(app, debug=False, host="0.0.0.0")
Loading