Un inicio
Meter primero crossterm y luego probar con imgui y mas cosas
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -16,3 +16,8 @@ target/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
|||||||
107
Cargo.lock
generated
Normal file
107
Cargo.lock
generated
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.106"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rocket-api-rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_core"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.149"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
"zmij",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.117"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zmij"
|
||||||
|
version = "1.0.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||||
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "rocket-api-rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = {version = "1.0.228", features = ["derive"]}
|
||||||
|
serde_json = "1.0.149"
|
||||||
45
src/main.rs
Normal file
45
src/main.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
mod models;
|
||||||
|
|
||||||
|
use models::{UpdateState, Event};
|
||||||
|
|
||||||
|
use std::io::{BufReader, Write};
|
||||||
|
use std::net::TcpStream;
|
||||||
|
|
||||||
|
use serde_json::{Deserializer, Value};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = read_stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_data(event: &str, data: Value) {
|
||||||
|
let inner = data
|
||||||
|
.as_str()
|
||||||
|
.unwrap_or_else(|| panic!("Expected Data to be a JSON string, got: {}", data));
|
||||||
|
match event {
|
||||||
|
"UpdateState" => {
|
||||||
|
let update_data: UpdateState =
|
||||||
|
serde_json::from_str(inner).expect("Failed to parse UpdateState");
|
||||||
|
println!("Ball speed: {:?}", update_data.game.ball.speed);
|
||||||
|
}
|
||||||
|
other => println!("Evento desconocido: {}", other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_stream() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let mut stream = TcpStream::connect("localhost:49123")?;
|
||||||
|
|
||||||
|
let request = "GET /\r\n";
|
||||||
|
stream.write_all(request.as_bytes())?;
|
||||||
|
|
||||||
|
let reader = BufReader::new(stream);
|
||||||
|
let mut stream_iter = Deserializer::from_reader(reader).into_iter::<Event>();
|
||||||
|
|
||||||
|
while let Some(result) = stream_iter.next() {
|
||||||
|
match result {
|
||||||
|
Ok(event) => handle_data(&event.event, event.data),
|
||||||
|
Err(e) => eprintln!("Error de parseo: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
13
src/models/attacker.rs
Normal file
13
src/models/attacker.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Attacker {
|
||||||
|
#[serde(rename = "Name")]
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
#[serde(rename = "Shortcut")]
|
||||||
|
pub shortcut: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "TeamNum")]
|
||||||
|
pub team_num: i32
|
||||||
|
}
|
||||||
10
src/models/ball.rs
Normal file
10
src/models/ball.rs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Ball {
|
||||||
|
#[serde(rename = "Speed")]
|
||||||
|
pub speed: f64,
|
||||||
|
|
||||||
|
#[serde(rename = "TeamNum")]
|
||||||
|
pub team_num: i32,
|
||||||
|
}
|
||||||
10
src/models/event.rs
Normal file
10
src/models/event.rs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
use serde::{Deserialize};
|
||||||
|
use serde_json::{Value};
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Event {
|
||||||
|
#[serde(rename = "Event")]
|
||||||
|
pub event: String,
|
||||||
|
#[serde(rename = "Data")]
|
||||||
|
pub data: Value,
|
||||||
|
}
|
||||||
44
src/models/game.rs
Normal file
44
src/models/game.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::team::Team;
|
||||||
|
use super::ball::Ball;
|
||||||
|
use super::target::Target;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Game {
|
||||||
|
#[serde(rename = "Teams")]
|
||||||
|
pub teams: Vec<Team>,
|
||||||
|
|
||||||
|
#[serde(rename = "TimeSeconds")]
|
||||||
|
pub time_seconds: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "bOvertime")]
|
||||||
|
pub b_overtime: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "Ball")]
|
||||||
|
pub ball: Ball,
|
||||||
|
|
||||||
|
#[serde(rename = "bReplay")]
|
||||||
|
pub b_replay: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "bHasWinner")]
|
||||||
|
pub b_has_winner: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "Winner")]
|
||||||
|
pub winner: String,
|
||||||
|
|
||||||
|
#[serde(rename = "Arena")]
|
||||||
|
pub arena: String,
|
||||||
|
|
||||||
|
#[serde(rename = "bHasTarget")]
|
||||||
|
pub b_has_target: bool,
|
||||||
|
|
||||||
|
#[serde(rename = "Target")]
|
||||||
|
pub target: Option<Target>,
|
||||||
|
|
||||||
|
#[serde(rename = "Frame")]
|
||||||
|
pub frame: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(rename = "Elapsed")]
|
||||||
|
pub elapsed: Option<f64>,
|
||||||
|
}
|
||||||
14
src/models/mod.rs
Normal file
14
src/models/mod.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
pub mod player;
|
||||||
|
pub mod team;
|
||||||
|
pub mod ball;
|
||||||
|
pub mod target;
|
||||||
|
pub mod game;
|
||||||
|
pub mod event;
|
||||||
|
pub mod update_state;
|
||||||
|
pub mod attacker;
|
||||||
|
|
||||||
|
pub use player::Player;
|
||||||
|
pub use attacker::Attacker;
|
||||||
|
pub use game::Game;
|
||||||
|
pub use update_state::UpdateState;
|
||||||
|
pub use event::Event;
|
||||||
74
src/models/player.rs
Normal file
74
src/models/player.rs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::Attacker;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Player {
|
||||||
|
#[serde(rename = "Name")]
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
#[serde(rename = "PrimaryId")]
|
||||||
|
pub primary_id: String,
|
||||||
|
|
||||||
|
#[serde(rename = "Shortcut")]
|
||||||
|
pub shortcut: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "TeamNum")]
|
||||||
|
pub team_num: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Score")]
|
||||||
|
pub score: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Goals")]
|
||||||
|
pub goals: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Shots")]
|
||||||
|
pub shots: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Assists")]
|
||||||
|
pub assists: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Saves")]
|
||||||
|
pub saves: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Touches")]
|
||||||
|
pub touches: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "CarTouches")]
|
||||||
|
pub car_touches: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Demos")]
|
||||||
|
pub demos: i32,
|
||||||
|
|
||||||
|
// Conditional
|
||||||
|
|
||||||
|
#[serde(rename = "Boost")]
|
||||||
|
pub boost: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(rename = "bBoosting")]
|
||||||
|
pub b_boosting: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(rename = "bOnGround")]
|
||||||
|
pub b_on_ground: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(rename = "bOnWall")]
|
||||||
|
pub b_on_wall: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(rename = "bHasCar")]
|
||||||
|
pub b_has_car: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(rename = "Speed")]
|
||||||
|
pub speed: Option<f64>,
|
||||||
|
|
||||||
|
#[serde(rename = "bPowersliding")]
|
||||||
|
pub b_power_sliding: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(rename = "bDemolished")]
|
||||||
|
pub b_demolished: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(rename = "bSupersonic")]
|
||||||
|
pub b_supersonic: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(rename = "Attacker")]
|
||||||
|
pub attacker: Option<Attacker>
|
||||||
|
}
|
||||||
13
src/models/target.rs
Normal file
13
src/models/target.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Target {
|
||||||
|
#[serde(rename = "Name")]
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
#[serde(rename = "Shortcut")]
|
||||||
|
pub shortcut: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "TeamNum")]
|
||||||
|
pub team_num: i32,
|
||||||
|
}
|
||||||
19
src/models/team.rs
Normal file
19
src/models/team.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Team {
|
||||||
|
#[serde(rename = "Name")]
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
#[serde(rename = "TeamNum")]
|
||||||
|
pub team_num: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "Score")]
|
||||||
|
pub score: i32,
|
||||||
|
|
||||||
|
#[serde(rename = "ColorPrimary")]
|
||||||
|
pub color_primary: String,
|
||||||
|
|
||||||
|
#[serde(rename = "ColorSecondary")]
|
||||||
|
pub color_secondary: String,
|
||||||
|
}
|
||||||
16
src/models/update_state.rs
Normal file
16
src/models/update_state.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::{Game, Player};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
// #[serde(rename_all = "camelCase")] // Opcional, pero ayuda si hay variaciones de nombres
|
||||||
|
pub struct UpdateState {
|
||||||
|
#[serde(rename = "MatchGuid")]
|
||||||
|
pub match_guid: String,
|
||||||
|
|
||||||
|
#[serde(rename = "Players")]
|
||||||
|
pub players: Vec<Player>,
|
||||||
|
|
||||||
|
#[serde(rename = "Game")]
|
||||||
|
pub game: Game,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user