|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
use std::{sync::mpsc, thread};
|
|
|
|
|
use std::{sync::mpsc, thread, collections::HashMap};
|
|
|
|
|
|
|
|
|
|
use eframe::{
|
|
|
|
|
egui::{CentralPanel, Context, Layout, TextFormat, Visuals},
|
|
|
|
@ -7,7 +7,9 @@ use eframe::{
|
|
|
|
|
epaint::{text::LayoutJob, Color32, FontId},
|
|
|
|
|
Frame,
|
|
|
|
|
};
|
|
|
|
|
use itertools::Itertools;
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
@ -42,6 +44,7 @@ struct SfhResponse {
|
|
|
|
|
|
|
|
|
|
enum Event {
|
|
|
|
|
IdSubmit { id: String },
|
|
|
|
|
Error { description: String },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
@ -50,6 +53,7 @@ enum State {
|
|
|
|
|
|
|
|
|
|
struct App {
|
|
|
|
|
state: State,
|
|
|
|
|
error: Option<String>,
|
|
|
|
|
event_tx: mpsc::Sender<Event>,
|
|
|
|
|
event_rx: mpsc::Receiver<Event>,
|
|
|
|
|
}
|
|
|
|
@ -62,14 +66,13 @@ impl App {
|
|
|
|
|
search_string: String::new(),
|
|
|
|
|
enabled: true,
|
|
|
|
|
},
|
|
|
|
|
error: None,
|
|
|
|
|
event_tx,
|
|
|
|
|
event_rx,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update(&mut self, ctx: &Context, frame: &mut Frame) {
|
|
|
|
|
let mut events: Vec<Event> = vec![];
|
|
|
|
|
|
|
|
|
|
ctx.set_visuals(Visuals::light());
|
|
|
|
|
let mut title_text = LayoutJob::default();
|
|
|
|
|
title_text.append(
|
|
|
|
@ -96,15 +99,18 @@ impl App {
|
|
|
|
|
ui.with_layout(Layout::top_down(Align::Center), |ui| {
|
|
|
|
|
ui.label(title_text);
|
|
|
|
|
|
|
|
|
|
match &mut self.state {
|
|
|
|
|
State::IdSelect { search_string, enabled } => {
|
|
|
|
|
match (&self.error, &mut self.state) {
|
|
|
|
|
(Some(desc), _) => {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
(None, State::IdSelect { search_string, enabled }) => {
|
|
|
|
|
ui.label("Enter level ID:");
|
|
|
|
|
ui.add_enabled_ui(*enabled, |ui| {
|
|
|
|
|
ui.text_edit_singleline(search_string).request_focus();
|
|
|
|
|
});
|
|
|
|
|
if *enabled {
|
|
|
|
|
if ui.button("submit").clicked() {
|
|
|
|
|
events.push(Event::IdSubmit { id: search_string.clone() });
|
|
|
|
|
self.event_tx.send(Event::IdSubmit { id: search_string.clone() });
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ui.label("loading...");
|
|
|
|
@ -114,25 +120,51 @@ impl App {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for event in events {
|
|
|
|
|
while let Ok(event) = self.event_rx.try_recv() {
|
|
|
|
|
match event {
|
|
|
|
|
Event::IdSubmit { id } => {
|
|
|
|
|
let tx = self.event_tx.clone();
|
|
|
|
|
self.state = State::IdSelect { search_string: id.clone(), enabled: false };
|
|
|
|
|
thread::spawn(move || {
|
|
|
|
|
let res = ureq::post("http://www.boomlings.com/database/downloadGJLevel22.php")
|
|
|
|
|
.set("User-Agent", "")
|
|
|
|
|
.send_form(&[
|
|
|
|
|
("levelID", &id),
|
|
|
|
|
("secret", "Wmfd2893gb7"),
|
|
|
|
|
]);
|
|
|
|
|
match query_level_id(&tx, id) {
|
|
|
|
|
Ok(Some(song_desc)) => todo!(),
|
|
|
|
|
Ok(None) => todo!(),
|
|
|
|
|
Err(e) => todo!(),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
Event::Error { description } => self.error = Some(description),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn query_level_id(tx: &mpsc::Sender<Event>, id: String) -> Result<Option<SfhSong>> {
|
|
|
|
|
let level_desc = ureq::post("http://www.boomlings.com/database/downloadGJLevel22.php")
|
|
|
|
|
.set("User-Agent", "")
|
|
|
|
|
.send_form(&[
|
|
|
|
|
("levelID", &id),
|
|
|
|
|
("secret", "Wmfd2893gb7"),
|
|
|
|
|
])?
|
|
|
|
|
.into_string()?;
|
|
|
|
|
let level_desc_chunks = level_desc.split(':').chunks(2);
|
|
|
|
|
|
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
|
for mut pair in &level_desc_chunks {
|
|
|
|
|
let key: i32 = pair.next().unwrap().parse().unwrap();
|
|
|
|
|
let value = pair.next().unwrap();
|
|
|
|
|
map.insert(key, value.to_owned());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let song_id = map.get(&35).unwrap();
|
|
|
|
|
|
|
|
|
|
let sfh_response: SfhResponse = ureq::get(&format!("https://songfilehub.com/api/v1/nongs?id={}", song_id))
|
|
|
|
|
.call()?
|
|
|
|
|
.into_json()?;
|
|
|
|
|
|
|
|
|
|
todo!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let mut app = App::new();
|
|
|
|
|
eframe::run_simple_native("NONGfisher", Default::default(), move |ctx, frame| {
|
|
|
|
|