1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-01-31 14:37:24 +00:00

Load menu from file, write on menu exit (#222)

* Load menu from file, write on menu exit

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update lib.rs

* Update menu.rs

* Try response as well

* Don't hold response variable

* use static mut option

* everything in a thread

* remove brace

* Try GH actions change

* try

* try

* use container tag

* test

* try abs path

* try checkout

* try showing

* try installing

* test proj

* try stable toolchain spec

* try image

* explicit version

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Try clippy

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* Update rust.yml

* fixes

* only if the conf makes sense

* small clippy fixes
This commit is contained in:
jugeeya 2021-08-15 18:41:40 -07:00 committed by GitHub
parent e2bed25be3
commit f41bfff9f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 92 deletions

View file

@ -103,4 +103,4 @@ jobs:
uses: actions/upload-artifact@v1
with:
name: full_build
path: training_modpack_beta.zip
path: training_modpack_beta.zip

View file

@ -5,7 +5,6 @@ use skyline::info::get_program_id;
use smash::lib::lua_const::*;
use skyline_web::{Background, BootDisplay, Webpage};
use ramhorns::{Template, Content};
use strum::IntoEnumIterator;
#[derive(Content)]
struct Slider {
@ -24,18 +23,6 @@ struct Toggle<'a> {
default: &'a str,
}
impl<'a> Toggle<'a> {
pub fn new(title: &'a str, checked: bool, value: usize) -> Toggle<'a> {
Toggle{
title,
checked: if checked { "is-appear"} else { "is-hidden" },
index: 0,
value,
default: if checked { "is-appear"} else { "is-hidden" },
}
}
}
#[derive(Content)]
struct OnOffSelector<'a> {
title: &'a str,
@ -43,16 +30,6 @@ struct OnOffSelector<'a> {
default: &'a str,
}
impl <'a>OnOffSelector<'a> {
pub fn new(title: &'a str, checked: bool) -> OnOffSelector<'a> {
OnOffSelector {
title,
checked: if checked { "is-appear"} else { "is-hidden" },
default: if checked { "is-appear"} else { "is-hidden" },
}
}
}
#[derive(Content)]
struct SubMenu<'a> {
title: &'a str,
@ -193,24 +170,24 @@ macro_rules! add_bitflag_submenu {
}
}
macro_rules! add_single_option_submenu {
($menu:ident, $title:literal, $id:ident, $e:ty) => {
paste::paste!{
let [<$id _toggles>] = Vec::new();
for val in [<$e>]::iter() {
[<$id _toggles>].push((val.into_string().as_str(), val as usize));
}
// macro_rules! add_single_option_submenu {
// ($menu:ident, $title:literal, $id:ident, $e:ty) => {
// paste::paste!{
// let [<$id _toggles>] = Vec::new();
// for val in [<$e>]::iter() {
// [<$id _toggles>].push((val.into_string().as_str(), val as usize));
// }
$menu.add_sub_menu(
$title,
stringify!($id),
MENU.$id as usize,
[<$id _toggles>],
[].to_vec()
);
}
}
}
// $menu.add_sub_menu(
// $title,
// stringify!($id),
// MENU.$id as usize,
// [<$id _toggles>],
// [].to_vec()
// );
// }
// }
// }
pub fn set_menu_from_url(s: &str) {
let base_url_len = "http://localhost/?".len();
@ -382,19 +359,26 @@ pub unsafe fn write_menu() {
}
pub unsafe fn spawn_menu() {
let fname = "index.html";
let params = MENU.to_url_params();
std::thread::spawn(||{
let fname = "index.html";
let params = MENU.to_url_params();
let page_response = Webpage::new()
.background(Background::BlurredScreenshot)
.htdocs_dir("contents")
.boot_display(BootDisplay::BlurredScreenshot)
.boot_icon(true)
.start_page(&format!("{}{}", fname, params))
.open()
.unwrap();
let response = Webpage::new()
.background(Background::BlurredScreenshot)
.htdocs_dir("contents")
.boot_display(BootDisplay::BlurredScreenshot)
.boot_icon(true)
.start_page(&format!("{}{}", fname, params))
.open()
.unwrap();
let last_url = page_response
.get_last_url()
.unwrap();
let last_url = response.get_last_url().unwrap();
set_menu_from_url(last_url);
set_menu_from_url(last_url);
let menu_conf_path = "sd:/TrainingModpack/training_modpack_menu.conf";
std::fs::write(menu_conf_path, last_url)
.expect("Failed to write menu conf file");
});
}

View file

@ -19,9 +19,9 @@ extern crate bitflags;
extern crate num_derive;
use crate::common::*;
use training::combo::FRAME_ADVANTAGE;
use crate::menu::set_menu_from_url;
use skyline::libc::{c_void, fclose, fopen, fwrite, mkdir};
use skyline::libc::mkdir;
use std::fs;
use skyline::nro::{self, NroInfo};
@ -63,44 +63,9 @@ pub fn main() {
hazard_manager::hazard_manager();
training::training_mods();
nro::add_hook(nro_main).unwrap();
unsafe {
let mut buffer = format!("{:x}", &MENU as *const _ as u64);
log!(
"Writing training_modpack.log with {}...",
buffer
);
mkdir(c_str!("sd:/TrainingModpack/"), 777);
// Only necessary upon version upgrade.
// log!("[Training Modpack] Removing training_modpack_menu.conf...");
// remove(c_str!("sd:/TrainingModpack/training_modpack_menu.conf"));
let mut f = fopen(
c_str!("sd:/TrainingModpack/training_modpack.log"),
c_str!("w"),
);
if !f.is_null() {
fwrite(c_str!(buffer) as *const c_void, 1, buffer.len(), f);
fclose(f);
}
buffer = format!("{:x}", &FRAME_ADVANTAGE as *const _ as u64);
log!(
"Writing training_modpack_frame_adv.log with {}...",
buffer
);
f = fopen(
c_str!("sd:/TrainingModpack/training_modpack_frame_adv.log"),
c_str!("w"),
);
if !f.is_null() {
fwrite(c_str!(buffer) as *const c_void, 1, buffer.len(), f);
fclose(f);
}
}
let ovl_path = "sd:/switch/.overlays/ovlTrainingModpack.ovl";
@ -111,4 +76,14 @@ pub fn main() {
log!("Performing version check...");
release::version_check();
}
let menu_conf_path = "sd:/TrainingModpack/training_modpack_menu.conf";
if fs::metadata(menu_conf_path).is_ok() {
log!("Loading previous menu from training_modpack_menu.conf...");
let menu_conf = fs::read(menu_conf_path).unwrap();
if menu_conf.starts_with(b"http://localhost") {
set_menu_from_url(std::str::from_utf8(&menu_conf).unwrap());
}
}
}

View file

@ -69,6 +69,7 @@ pub unsafe fn playback() {
INPUT_RECORD_FRAME = 0;
}
#[allow(dead_code)]
pub unsafe fn handle_get_npad_state(
state: *mut NpadHandheldState,
controller_id: *const u32,