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

MusicList: resolves #24 #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
243 changes: 243 additions & 0 deletions config/music.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
[[music]]

category = "== Vanilla =="

[[music.songs]]
name = "01_turnabout_courtroom_-_prologue.mp3"
length = 40.099833

[[music.songs]]
name = "113 Confrontation ~ Presto 2009.mp3"
length = 186.7265

[[music.songs]]
name = "114 Pursuit(Miles).mp3"
length = 196.633167

[[music.songs]]
name = "3DKH.mp3"
length = 289.364875

[[music.songs]]
name = "Annonce The Truth(AA).mp3"
length = 79.673167

[[music.songs]]
name = "Annonce The Truth(AJ).mp3"
length = 59.4865

[[music.songs]]
name = "Annonce The Truth(JFA).mp3"
length = 98.006792

[[music.songs]]
name = "Annonce The Truth(Miles).mp3"
length = 152.659833

[[music.songs]]
name = "Annonce The Truth(T&T).mp3"
length = 126.007146

[[music.songs]]
name = "Crises of Fate.mp3"
length = 143.5265

[[music.songs]]
name = "Forgotten Legend.mp3"
length = 141.299833

[[music.songs]]
name = "Ghost Trick - 4 Minutes Before Death.mp3"
length = 124.897958

[[music.songs]]
name = "Ghost Trick - Countdown.mp3"
length = 64.790208

[[music.songs]]
name = "Ghost Trick - The World of the Dead.mp3"
length = 95.1445

[[music.songs]]
name = "Godot - The Fragrance of Dark Coffee.mp3"
length = 148.007146

[[music.songs]]
name = "Great Revival ~ Franziska von Karma.mp3"
length = 86.007063

[[music.songs]]
name = "Great Revival ~ Miles Edgeworth.mp3"
length = 89.61675

[[music.songs]]
name = "Hotline of Fate.mp3"
length = 51.006604

[[music.songs]]
name = "Interesting People.mp3"
length = 142.633167

[[music.songs]]
name = "logic_and_trick.mp3"
length = 152.379833

[[music.songs]]
name = "Luke Atmey ~ I Just Want Love.mp3"
length = 103.007417

[[music.songs]]
name = "Mystery Skulls - Ghost.mp3"
length = 259.088438

[[music.songs]]
name = "Mystery Skulls - Money.mp3"
length = 212.059

[[music.songs]]
name = "Noisy People.mp3"
length = 91.379833

[[music.songs]]
name = "OBJECTIOM(AJ).mp3"
length = 96.019833

[[music.songs]]
name = "OBJECTION (AA).mp3"
length = 73.273167

[[music.songs]]
name = "OBJECTION (JFA).mp3"
length = 93.620333

[[music.songs]]
name = "OBJECTION (T&T).mp3"
length = 118.992479

[[music.songs]]
name = "OBJECTION(Miles).mp3"
length = 175.819833

[[music.songs]]
name = "OBJECTION(trixie).mp3"
length = 129.861208

[[music.songs]]
name = "Others ~ Guilty love.mp3"
length = 98.6865

[[music.songs]]
name = "Prelude(AA).mp3"
length = 77.779833

[[music.songs]]
name = "Prelude(AJ).mp3"
length = 71.179833

[[music.songs]]
name = "Pursuit ~ I Want to Find the Truth(Orchestra).mp3"
length = 294.641625

[[music.songs]]
name = "PURSUIT(AA) - variation.mp3"
length = 90.339833

[[music.songs]]
name = "PURSUIT(AA).mp3"
length = 96.3665

[[music.songs]]
name = "PURSUIT(AJ).mp3"
length = 109.0065

[[music.songs]]
name = "PURSUIT(DS).mp3"
length = 226.672063

[[music.songs]]
name = "PURSUIT(JFA) - variation.mp3"
length = 76.006792

[[music.songs]]
name = "PURSUIT(JFA).mp3"
length = 82.007146

[[music.songs]]
name = "PURSUIT(T&T) - variation.mp3"
length = 114.007417

[[music.songs]]
name = "PURSUIT(T&T).mp3"
length = 120.006792

[[music.songs]]
name = "Questioning AJ (Allegro).mp3"
length = 103.216313

[[music.songs]]
name = "Questioning AJ (Moderato).mp3"
length = 80.306917

[[music.songs]]
name = "Questioning JFA (Allegro).mp3"
length = 103.190188

[[music.songs]]
name = "Questioning JFA (Moderato).mp3"
length = 89.893854

[[music.songs]]
name = "Questioning T&T (Allegro).mp3"
length = 160.032625

[[music.songs]]
name = "Questioning T&T (Moderato).mp3"
length = 115.937938

[[music.songs]]
name = "Questioning(AA-allergo).mp3"
length = 126.8065

[[music.songs]]
name = "Questioning(AA-normal).mp3"
length = 104.633167

[[music.songs]]
name = "Sin.mp3"
length = 122.494667

[[music.songs]]
name = "Speak up, Pup!.mp3"
length = 166.9665

[[music.songs]]
name = "Super Trixie.mp3"
length = 147.57225

[[music.songs]]
name = "Suspence(AA).mp3"
length = 92.579833

[[music.songs]]
name = "The Great Truth Burglar.mp3"
length = 148.873167

[[music.songs]]
name = "Trans.mp3"
length = 199.242458

[[music.songs]]
name = "Trial(AA).mp3"
length = 108.873167

[[music.songs]]
name = "Trial(AJ).mp3"
length = 125.833167

[[music.songs]]
name = "Trial(Miles).mp3"
length = 275.619833

[[music.songs]]
name = "~stop.mp3"
length = 1.0065
1 change: 1 addition & 0 deletions rusttorney-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod client_manager;
pub mod command;
pub mod config;
pub mod master_server_client;
pub mod music_list;
pub mod networking;
pub mod server;

Expand Down
45 changes: 45 additions & 0 deletions rusttorney-server/src/music_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use serde::Deserialize;

type Category = String;

#[derive(Debug, Deserialize)]
pub struct MusicList {
pub music: Vec<Music>,
}

#[derive(Debug, Deserialize)]
pub struct Music {
category: String,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not category: Category?

songs: Vec<Song>,
}

#[derive(Debug, Deserialize)]
pub struct Song {
pub name: String,
pub length: f32,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_music_list_de() {
let music_list_str = r#"
[[music]]

category = "== Vanilla =="

[[music.songs]]
name = "01_turnabout_courtroom_-_prologue.mp3"
length = 40.099833
"#;

let music_list: MusicList = toml::from_str(music_list_str).unwrap();
assert_eq!(music_list.music[0].category, "== Vanilla ==");
assert_eq!(
music_list.music[0].songs[0].name,
"01_turnabout_courtroom_-_prologue.mp3"
);
}
}
9 changes: 7 additions & 2 deletions rusttorney-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use futures::{SinkExt, StreamExt};
use std::sync::Arc;
use tokio::net::{TcpListener, TcpStream};

use crate::music_list::MusicList;
use crate::prompt;
use futures::channel::mpsc;
use futures::channel::oneshot::{channel, Receiver, Sender};
Expand All @@ -24,6 +25,7 @@ use tokio_util::codec::{Decoder, Framed};

pub struct AOServer {
config: Arc<Config>,
music_list: Arc<MusicList>,
db: DbWrapper,
client_manager: Arc<Mutex<ClientManager>>,
}
Expand All @@ -44,12 +46,12 @@ impl AO2MessageHandler {
mut socket: Framed<TcpStream, AOMessageCodec>,
db: DbWrapper,
client_manager: Arc<Mutex<ClientManager>>,
timeout: u64,
timeout_tx: Sender<()>,
ip: IpAddr,
config: Arc<Config>,
) -> Result<Self, anyhow::Error> {
let (ch_tx, mut ch_rx) = futures::channel::mpsc::channel(1);
let timeout = config.timeout as u64;

tokio::spawn(async move {
let mut delay =
Expand Down Expand Up @@ -172,13 +174,17 @@ impl AO2MessageHandler {
impl AOServer {
pub fn new(config: Arc<Config>, db: DbWrapper) -> anyhow::Result<Self> {
let playerlimit = config.general.playerlimit;
let music_list_str = std::fs::read_to_string("./config/music.toml")?;
let music_list: Arc<MusicList> =
Arc::new(toml::from_str(&music_list_str)?);
Ok(Self {
config,
db: db.clone(),
client_manager: Arc::new(Mutex::new(ClientManager::new(
playerlimit,
db,
))),
music_list,
})
}

Expand Down Expand Up @@ -270,7 +276,6 @@ impl AOServer {
framed,
db,
client_manager,
timeout,
timeout_tx,
c.ip(),
config,
Expand Down