Skip to content

Commit

Permalink
Change start arg parsing in client to directly change the config afte…
Browse files Browse the repository at this point in the history
…r loaded
  • Loading branch information
Jupeyy committed Jan 14, 2025
1 parent 78c29f4 commit 6292d98
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 110 deletions.
26 changes: 3 additions & 23 deletions game/client-console/src/console/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use std::collections::VecDeque;
use base::system::{self, SystemTimeInterface};
use client_containers::skins::SkinContainer;
use client_render_base::render::tee::RenderTee;
use client_types::console::{entries_to_parser, ConsoleEntry};
use client_types::console::ConsoleEntry;
use client_ui::console::{page::ConsoleUi, user_data::UserData};
use command_parser::parser::{parse, ParserCache};
use config::config::ConfigEngine;
use command_parser::parser::ParserCache;
use egui::Color32;
use game_config::config::{Config, ConfigGame};
use game_config::config::Config;
use graphics::graphics::graphics::Graphics;
use ui_base::{
types::{UiRenderPipe, UiState},
Expand Down Expand Up @@ -77,25 +76,6 @@ impl<E, T> ConsoleRender<E, T> {
}
}

pub fn parse_cmd(
&mut self,
cmd: &str,
config_game: &mut ConfigGame,
config_engine: &mut ConfigEngine,
) {
if !cmd.is_empty() {
let cmds = parse(cmd, &entries_to_parser(&self.entries), &mut self.cache);
client_ui::console::utils::run_commands(
&cmds,
&self.entries,
config_engine,
config_game,
&mut String::new(),
true,
);
}
}

#[must_use]
pub fn render(
&mut self,
Expand Down
112 changes: 64 additions & 48 deletions game/client-console/src/console/local_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,66 @@ impl super::console::ConsoleEvents<LocalConsoleEvent> for LocalConsoleEvents {

pub type LocalConsole = ConsoleRender<LocalConsoleEvent, Rc<RefCell<ParserCache>>>;

#[derive(Debug, Default)]
pub struct LocalConsoleBuilder {}
#[derive(Debug)]
pub struct LocalConsoleBuilder {
pub entries: Vec<ConsoleEntry>,
pub console_events: LocalConsoleEvents,
pub parser_cache: Rc<RefCell<ParserCache>>,
}

impl Default for LocalConsoleBuilder {
fn default() -> Self {
let console_events: LocalConsoleEvents = Default::default();
let mut entries: Vec<ConsoleEntry> = Vec::new();

let val = ConfigEngine::conf_value();
let events_var = console_events.clone();
let var_on_set = Rc::new(move |name: &str| {
events_var.push(LocalConsoleEvent::ConfigVariable {
name: name.to_string(),
});
});
parse_conf_values_as_str_list(
"".to_string(),
&mut |entry, _| {
entries.push(ConsoleEntry::Var(ConsoleEntryVariable {
full_name: entry.name,
usage: entry.usage,
description: entry.description,
args: entry.args,
on_set: var_on_set.clone(),
}));
},
val,
"".into(),
Default::default(),
);
let val = ConfigGame::conf_value();
parse_conf_values_as_str_list(
"".to_string(),
&mut |entry, _| {
entries.push(ConsoleEntry::Var(ConsoleEntryVariable {
full_name: entry.name,
usage: entry.usage,
description: entry.description,
args: entry.args,
on_set: var_on_set.clone(),
}));
},
val,
"".into(),
Default::default(),
);
let parser_cache = Rc::new(RefCell::new(ParserCache::default()));
Self::register_commands(console_events.clone(), &mut entries, parser_cache.clone());

Self {
console_events,
entries,
parser_cache,
}
}
}

impl LocalConsoleBuilder {
fn register_commands(
Expand Down Expand Up @@ -804,55 +862,13 @@ impl LocalConsoleBuilder {
}));
}

pub fn build(creator: &UiCreator) -> LocalConsole {
let console_events: LocalConsoleEvents = Default::default();
let mut entries: Vec<ConsoleEntry> = Vec::new();
let val = ConfigEngine::conf_value();
let events_var = console_events.clone();
let var_on_set = Rc::new(move |name: &str| {
events_var.push(LocalConsoleEvent::ConfigVariable {
name: name.to_string(),
});
});
parse_conf_values_as_str_list(
"".to_string(),
&mut |entry, _| {
entries.push(ConsoleEntry::Var(ConsoleEntryVariable {
full_name: entry.name,
usage: entry.usage,
description: entry.description,
args: entry.args,
on_set: var_on_set.clone(),
}));
},
val,
"".into(),
Default::default(),
);
let val = ConfigGame::conf_value();
parse_conf_values_as_str_list(
"".to_string(),
&mut |entry, _| {
entries.push(ConsoleEntry::Var(ConsoleEntryVariable {
full_name: entry.name,
usage: entry.usage,
description: entry.description,
args: entry.args,
on_set: var_on_set.clone(),
}));
},
val,
"".into(),
Default::default(),
);
let parser_cache = Rc::new(RefCell::new(ParserCache::default()));
Self::register_commands(console_events.clone(), &mut entries, parser_cache.clone());
pub fn build(self, creator: &UiCreator) -> LocalConsole {
ConsoleRender::new(
creator,
entries,
Box::new(console_events),
self.entries,
Box::new(self.console_events),
Color32::from_rgba_unmultiplied(0, 0, 0, 150),
parser_cache,
self.parser_cache,
)
}
}
Loading

0 comments on commit 6292d98

Please sign in to comment.