1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-07-27 07:20:51 +00:00

Compare commits

..

1 commit

Author SHA1 Message Date
biroder e8065debdb
Merge 91c35a25f9 into 896f43dc1e 2025-07-02 13:58:39 +00:00
5 changed files with 39 additions and 41 deletions

View file

@ -8,7 +8,6 @@ use std::time::{Duration, Instant};
use clap::clap_derive::Parser;
use lazy_static::lazy_static;
use log::LevelFilter as LogLevel;
use scripting::tsc::text_script::ScriptMode;
use crate::framework::backend::WindowParams;
@ -39,7 +38,7 @@ pub mod shared_game_state;
pub mod stage;
pub mod weapon;
#[derive(Debug, Parser)]
#[derive(Debug, Default, Parser)]
#[command(version, about, long_about = None)]
pub struct LaunchOptions {
#[arg(long, hide = cfg!(not(feature = "netplay")))]
@ -61,25 +60,6 @@ pub struct LaunchOptions {
#[arg(long)]
/// Startup in fullscreen mode.
pub window_fullscreen: bool,
#[arg(long, default_value_t = Self::default().log_level)]
/// The minimum level of records that will be written to the log file.
///
/// Possible values: error, warn, info, debug, trace.
pub log_level: LogLevel,
}
impl Default for LaunchOptions {
fn default() -> Self {
Self {
server_mode: false,
editor: false,
window_height: None,
window_width: None,
window_fullscreen: false,
log_level: if cfg!(debug_assertions) { LogLevel::Debug } else { LogLevel::Info },
}
}
}
impl LaunchOptions {
@ -280,13 +260,14 @@ impl Game {
}
}
// For the most part this is just a copy-paste of the code from FilesystemContainer because it logs
// For the most part this is just a copy-paste of the code from FilesystemContainer because it logs
// some messages during init, but the default logger cannot be replaced with another
// one or deinited(so we can't create the console-only logger and replace it by the
// console&file logger after FilesystemContainer has been initialized)
fn get_logs_dir() -> GameResult<PathBuf> {
let mut logs_dir: PathBuf;
#[cfg(target_os = "android")]
{
logs_dir = PathBuf::from(ndk_glue::native_activity().internal_data_path().to_string_lossy().to_string());
@ -314,28 +295,45 @@ fn get_logs_dir() -> GameResult<PathBuf> {
logs_dir.push("logs");
Ok(logs_dir)
}
fn init_logger(options: &LaunchOptions) -> GameResult {
fn init_logger() -> GameResult {
let logs_dir = get_logs_dir()?;
let _ = std::fs::create_dir_all(&logs_dir);
let mut dispatcher = fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!("{} [{}] {}", record.level(), record.module_path().unwrap().to_owned(), message))
out.finish(format_args!(
"{} [{}] {}",
record.level(),
record.module_path().unwrap().to_owned(),
message
))
})
.chain(fern::Dispatch::new().chain(std::io::stderr()));
.level(log::LevelFilter::Debug)
.chain(
fern::Dispatch::new()
.chain(std::io::stderr())
);
let date = chrono::Utc::now();
let mut file = logs_dir.clone();
file.push(format!("log_{}", date.format("%Y-%m-%d")));
file.set_extension("txt");
dispatcher =
dispatcher.chain(fern::Dispatch::new().level(options.log_level).chain(fern::log_file(file).unwrap()));
dispatcher = dispatcher.chain(
fern::Dispatch::new()
.level(log::LevelFilter::Info)
.chain(fern::log_file(file).unwrap())
);
dispatcher.apply()?;
//log::info!("===GAME LAUNCH===");
Ok(())
}
@ -352,7 +350,7 @@ fn panic_hook(info: &PanicInfo<'_>) {
}
pub fn init(mut options: LaunchOptions) -> GameResult {
let _ = init_logger(&options);
let _ = init_logger();
std::panic::set_hook(Box::new(panic_hook));
let mut context = Box::pin(Context::new());

View file

@ -46,7 +46,7 @@ impl TextScript {
}
let bytecode = TextScript::compile_event(&mut iter, strict, encoding)?;
log::debug!("Successfully compiled event #{} ({} bytes generated).", event_num, bytecode.len());
log::info!("Successfully compiled event #{} ({} bytes generated).", event_num, bytecode.len());
event_map.insert(event_num, bytecode);
}
b'\r' | b'\n' | b' ' | b'\t' => {

View file

@ -1,7 +1,7 @@
pub fn decrypt_tsc(buf: &mut [u8]) {
let half = buf.len() / 2;
let key = if let Some(0) = buf.get(half) { 0x7 } else { *buf.get(half).unwrap() };
log::debug!("Decrypting TSC using key {:#x}", key);
log::info!("Decrypting TSC using key {:#x}", key);
for (idx, byte) in buf.iter_mut().enumerate() {
if idx == half {

View file

@ -15,7 +15,7 @@ fn main() {
let result = doukutsu_rs::game::init(options);
#[cfg(target_os = "windows")]
unsafe {
unsafe {
use std::ffi::OsStr;
use std::os::windows::prelude::*;
use winapi::_core::ptr::null_mut;
@ -24,13 +24,13 @@ fn main() {
use winapi::um::winuser::MB_OK;
if let Err(e) = result {
let title = OsStr::new("Error!").encode_wide().chain(Some(0)).collect::<Vec<u16>>();
let message = OsStr::new(format!("Whoops, doukutsu-rs crashed: {}", e).as_str())
let title: LPCWSTR = OsStr::new("Error!").encode_wide().chain(Some(0)).collect::<Vec<u16>>().as_ptr();
let message: LPCWSTR = OsStr::new(format!("Whoops, doukutsu-rs crashed: {}", e).as_str())
.encode_wide()
.chain(Some(0))
.collect::<Vec<u16>>();
MessageBoxW(null_mut(), message.as_ptr() as LPCWSTR, title.as_ptr() as LPCWSTR, MB_OK);
.collect::<Vec<u16>>()
.as_ptr();
MessageBoxW(null_mut(), message, title, MB_OK);
exit(1);
}
}

View file

@ -1671,7 +1671,7 @@ impl Scene for GameScene {
let npcs = self.stage.load_npcs(&state.constants.base_paths, ctx)?;
for npc_data in npcs.iter() {
log::debug!("creating npc: {:?}", npc_data);
log::info!("creating npc: {:?}", npc_data);
let mut npc = NPC::create_from_data(npc_data, &state.npc_table, state.tile_size);
if npc.npc_flags.appear_when_flag_set() {