Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes for replay #55

Merged
merged 3 commits into from
Apr 21, 2024
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
17 changes: 11 additions & 6 deletions assets/html/game/replay.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
<style>
.replay_viewer {
width: 100%;
height: 80%;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
margin-top: 2.5rem;
}

.event_box {
.events_main {
width: 40%;
}

.event_box {
height: 100%;
display: flex;
flex-direction: column;
Expand All @@ -25,7 +29,7 @@
.events {
display: inline-block;
width: 100%;
height: 70vh;
height: 60vh;
padding: 10px;
margin: 0;
border: 0;
Expand Down Expand Up @@ -81,6 +85,7 @@
width: 90%;
margin: auto;
margin-top: 16px;
margin-bottom: 24px;
}

.time-slider-control {
Expand Down Expand Up @@ -189,9 +194,10 @@ <h1>Loading Replay...</h1>
<div class="replay_viewer" id="replay_viewer">
<div id="teams" class="team_box">
</div>
<div class="event_box">
<div class="events" id="events">

<div class="events_main">
<div class="event_box">
<div class="events" id="events">
</div>
</div>
<div class="controls">
<button id="play" class="control">Play</button>
Expand All @@ -205,7 +211,6 @@ <h1>Loading Replay...</h1>
<button id="restart" class="control">Restart</button>
</div>
</div>

</div>

<div class="time-slider" id="time_slider">
Expand Down
5 changes: 3 additions & 2 deletions assets/js/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function finishedPlayingIntro() {
playButton.innerHTML = "Pause";
started = true;
base_timestamp = new Date().getTime();
current_starting_sound_playing = undefined;

// play the game start sfx
playAudio(alarm_start_audio);
Expand All @@ -89,7 +90,7 @@ function playPause() {

restarted = false;
if (current_starting_sound_playing != undefined) {
restartReplay();
resetGame();
restarted = false;
finishedPlayingIntro();
cancelled_starting_sound = true; // cancel the callback for the starting sound
Expand Down Expand Up @@ -275,7 +276,7 @@ function playEvents() {
});

event[4].forEach((team_score, index) => {
document.getElementById(`${team_ids[index]}_score`).innerHTML = `${team_names[index]} ${team_score}`;
document.getElementById(`${team_ids[index]}_score`).innerHTML = `${team_names[index]}: ${team_score}`;
});

event[5].forEach((sound_id) => {
Expand Down
33 changes: 28 additions & 5 deletions handlers/util/upload_tdf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from sanic import Request, exceptions, response
from shared import app
from utils import get_post
Expand Down Expand Up @@ -25,14 +27,35 @@ async def auto_upload(request: Request) -> str:
raise exceptions.BadRequest()

if type == "sm5":
open("./sm5_tdf/" + file.name, "wb").write(file.body)
await parse_sm5_game("./sm5_tdf/" + file.name)
target_path = "./sm5_tdf/" + file.name
_create_file_from_request(file, target_path)
await parse_sm5_game(target_path)
elif type == "laserball":
open("./laserball_tdf/" + file.name, "wb").write(file.body)
await parse_laserball_game("./laserball_tdf/" + file.name)
target_path = "./laserball_tdf/" + file.name
_create_file_from_request(file, target_path)
await parse_laserball_game(target_path)
else:
raise exceptions.BadRequest()

logger.info("Uploaded TDF successfully!")

return response.text("Uploaded!")
return response.text("Uploaded!")


def _create_file_from_request(request_file, target_path: str):
"""Reads the data from a request's file and stores it a local file.

Creates the path structure leading up to the target path if it doesn't
exist already.

Args:
request_file: The file from the HTTP request.
target_path: The path to store this file in. Can be relative.
"""
filepath = Path(target_path)

# Create the directory if it doesn't exist already.
filepath.parent.mkdir(parents=True, exist_ok=True)

# Copy the entire contents of the request file into the target file.
open(target_path, "wb").write(request_file.body)
12 changes: 6 additions & 6 deletions helpers/replay_sm5.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ async def create_sm5_replay(game: SM5Game) -> Replay:

start_audio = ReplaySound(
[f"{_AUDIO_PREFIX}Start.0.wav", f"{_AUDIO_PREFIX}Start.1.wav", f"{_AUDIO_PREFIX}Start.2.wav",
f"{_AUDIO_PREFIX}Start.3.wav"])
alarm_start_audio = ReplaySound([f"{_AUDIO_PREFIX}Effect/General Quarters.wav"])
f"{_AUDIO_PREFIX}Start.3.wav"], _START_AUDIO)
alarm_start_audio = ReplaySound([f"{_AUDIO_PREFIX}Effect/General Quarters.wav"], _ALARM_START_AUDIO)
resupply_audio = ReplaySound([f"{_AUDIO_PREFIX}Effect/Resupply.0.wav", f"{_AUDIO_PREFIX}Effect/Resupply.1.wav",
f"{_AUDIO_PREFIX}Effect/Resupply.2.wav", f"{_AUDIO_PREFIX}Effect/Resupply.3.wav",
f"{_AUDIO_PREFIX}Effect/Resupply.4.wav"])
f"{_AUDIO_PREFIX}Effect/Resupply.4.wav"], _RESUPPLY_AUDIO)
downed_audio = ReplaySound([f"{_AUDIO_PREFIX}Effect/Scream.0.wav", f"{_AUDIO_PREFIX}Effect/Scream.1.wav",
f"{_AUDIO_PREFIX}Effect/Scream.2.wav", f"{_AUDIO_PREFIX}Effect/Shot.0.wav",
f"{_AUDIO_PREFIX}Effect/Shot.1.wav"])
base_destroyed_audio = ReplaySound([f"{_AUDIO_PREFIX}Effect/Boom.wav"])
f"{_AUDIO_PREFIX}Effect/Shot.1.wav"], _DOWNED_AUDIO)
base_destroyed_audio = ReplaySound([f"{_AUDIO_PREFIX}Effect/Boom.wav"], _BASE_DESTROYED_AUDIO)

sound_assets = [
start_audio,
Expand Down Expand Up @@ -249,7 +249,7 @@ async def create_sm5_replay(game: SM5Game) -> Replay:

# Recompute accuracy.
cell_changes.append(ReplayCellChange(row_id=player1.row_id, column=_ACCURACY_COLUMN,
new_value="%.2f" % (
new_value="%.2f%%" % (
player1.total_shots_hit * 100 / player1.total_shots_fired)))

# Handle losing lives.
Expand Down
15 changes: 8 additions & 7 deletions tests/helpers/replay_sm5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ async def test_create_sm5_replay(self):

expected = Replay(events=[ReplayEvent(timestamp_millis=2000, message='Indy zaps Miles', team_scores=[100, -20],
cell_changes=[ReplayCellChange(row_id='r1', column=4, new_value='29'),
ReplayCellChange(row_id='r1', column=7, new_value='100.00'),
ReplayCellChange(row_id='r1', column=7,
new_value='100.00%'),
ReplayCellChange(row_id='r3', column=3, new_value='14'),
ReplayCellChange(row_id='r1', column=6, new_value='1'),
ReplayCellChange(row_id='r1', column=2, new_value='100'),
Expand All @@ -48,7 +49,7 @@ async def test_create_sm5_replay(self):
'/assets/sm5/audio/Effect/Scream.2.wav',
'/assets/sm5/audio/Effect/Shot.0.wav',
'/assets/sm5/audio/Effect/Shot.1.wav'],
id=0)]),
id=3)]),
ReplayEvent(timestamp_millis=2500, message='LoggedIn resupplies Indy', team_scores=[],
cell_changes=[ReplayCellChange(row_id='r1', column=3, new_value='19')],
row_changes=[ReplayRowChange(row_id='r1', new_css_class='fire-team-dim')],
Expand All @@ -57,7 +58,7 @@ async def test_create_sm5_replay(self):
'/assets/sm5/audio/Effect/Resupply.2.wav',
'/assets/sm5/audio/Effect/Resupply.3.wav',
'/assets/sm5/audio/Effect/Resupply.4.wav'],
id=0)])], teams=[
id=2)])], teams=[
ReplayTeam(name='Fire Team', css_class='fire-team', id='fire_team', players=[ReplayPlayer(
cells=['<img src="/assets/sm5/roles/commander.png" alt="Commander" width="30" height="30">', 'Indy',
'0', '15', '5', '0', '0', '', ''], row_id='r1'), ReplayPlayer(
Expand All @@ -68,14 +69,14 @@ async def test_create_sm5_replay(self):
'0', '0', '0', '', ''], row_id='r3')])], sounds=[ReplaySound(
asset_urls=['/assets/sm5/audio/Start.0.wav', '/assets/sm5/audio/Start.1.wav',
'/assets/sm5/audio/Start.2.wav', '/assets/sm5/audio/Start.3.wav'], id=0), ReplaySound(
asset_urls=['/assets/sm5/audio/Effect/General Quarters.wav'], id=0), ReplaySound(
asset_urls=['/assets/sm5/audio/Effect/General Quarters.wav'], id=1), ReplaySound(
asset_urls=['/assets/sm5/audio/Effect/Resupply.0.wav', '/assets/sm5/audio/Effect/Resupply.1.wav',
'/assets/sm5/audio/Effect/Resupply.2.wav', '/assets/sm5/audio/Effect/Resupply.3.wav',
'/assets/sm5/audio/Effect/Resupply.4.wav'], id=0), ReplaySound(
'/assets/sm5/audio/Effect/Resupply.4.wav'], id=2), ReplaySound(
asset_urls=['/assets/sm5/audio/Effect/Scream.0.wav', '/assets/sm5/audio/Effect/Scream.1.wav',
'/assets/sm5/audio/Effect/Scream.2.wav', '/assets/sm5/audio/Effect/Shot.0.wav',
'/assets/sm5/audio/Effect/Shot.1.wav'], id=0), ReplaySound(
asset_urls=['/assets/sm5/audio/Effect/Boom.wav'], id=0)],
'/assets/sm5/audio/Effect/Shot.1.wav'], id=3), ReplaySound(
asset_urls=['/assets/sm5/audio/Effect/Boom.wav'], id=4)],
column_headers=['Role', 'Codename', 'Score', 'Lives', 'Shots', 'Missiles', 'Spec', 'Accuracy',
'K/D'])

Expand Down
Loading