Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Irb tools #21

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
### Added

- Added the ability to load maps from packages by name (eg. `throneworld` or `dungeon_prophecy`) through the `-p` argument by @cohaereo
- Added draw_crosshair to the config by @Froggy618157725 in [#21](https://github.com/cohaereo/alkahest/pull/21)
- Added 'I' Key shortcut to swap to previous map by @Froggy618157725 in [#21](https://github.com/cohaereo/alkahest/pull/21)

### Fixed

Expand Down
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ macro_rules! config {
pub struct Config {
pub window: WindowConfig,
pub resources: ResourceConfig,
pub render_settings: RenderConfig,

pub update_channel: Option<UpdateChannel>,
}
Expand All @@ -72,6 +73,12 @@ impl Default for ResourceConfig {
}
}

#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct RenderConfig {
pub draw_crosshair: bool,
}

#[derive(Serialize, Deserialize)]
#[serde(default)]
pub struct WindowConfig {
Expand Down
3 changes: 3 additions & 0 deletions src/hotkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub const SHORTCUT_FOCUS: egui::KeyboardShortcut =
pub const SHORTCUT_GAZE: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::G);

pub const SHORTCUT_MAP_SWAP: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::I);

pub fn process_hotkeys(ctx: &egui::Context, resources: &mut Resources) {
if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT_UNHIDE_ALL)) {
unhide_all(resources);
Expand Down
20 changes: 18 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use crate::{
resolve_aabb,
resources::SelectedEntity,
},
hotkeys::{SHORTCUT_FOCUS, SHORTCUT_GAZE},
hotkeys::{SHORTCUT_FOCUS, SHORTCUT_GAZE, SHORTCUT_MAP_SWAP},
input::InputState,
map::MapDataList,
map_resources::MapResource,
Expand Down Expand Up @@ -418,12 +418,16 @@ pub async fn main() -> anyhow::Result<()> {
resources.insert(InputState::default());
resources.insert(MapDataList {
current_map: 0,
previous_map: 0,
updated: false,
maps: vec![],
});
resources.insert(ScopeOverrides::default());
resources.insert(DebugShapes::default());
resources.insert(EnabledShaderOverrides::default());
resources.insert(RenderSettings::default());
let mut render_settings = RenderSettings::default();
render_settings.draw_crosshair = config::with(|cfg| cfg.render_settings.draw_crosshair);
resources.insert(render_settings);
resources.insert(ShadowMapsResource::create(dcs.clone()));
resources.insert(CurrentCubemap(None, None));
resources.insert(ActivityGroupFilter::default());
Expand Down Expand Up @@ -698,6 +702,15 @@ pub async fn main() -> anyhow::Result<()> {
if d.is_finite() {
camera.focus(pos, 10.0);
}
} else if gui
.egui
.input_mut(|i| i.consume_shortcut(&SHORTCUT_MAP_SWAP))
{
let mut maps = resources.get_mut::<MapDataList>().unwrap();

(maps.current_map, maps.previous_map) =
(maps.previous_map, maps.current_map);
maps.updated = maps.previous_map != maps.current_map;
}
}
last_frame = Instant::now();
Expand Down Expand Up @@ -1098,6 +1111,9 @@ pub async fn main() -> anyhow::Result<()> {
c.resources.map_resource_label_background = gdb.map_resource_label_background;
c.resources.resource_distance_limit = gdb.map_resource_distance_limit_enabled;
c.resources.filters = resource_filters;

let render_settings = resources.get_mut::<RenderSettings>().unwrap();
c.render_settings.draw_crosshair = render_settings.draw_crosshair;
});
config::persist();
}
Expand Down
4 changes: 3 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub struct SimpleLight {
}

pub struct MapDataList {
pub current_map: usize, // TODO(cohae): Shouldn't be here
pub current_map: usize, // TODO(cohae): Shouldn't be here
pub previous_map: usize, // TODO(froggy): I guess this too then
pub updated: bool,
pub maps: Vec<(TagHash, Option<TagHash64>, MapData)>,
}

Expand Down
22 changes: 15 additions & 7 deletions src/overlays/render_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,18 @@ impl Overlay for RenderSettingsOverlay {
let mut maps = resources.get_mut::<MapDataList>().unwrap();
if !maps.maps.is_empty() {
let mut current_map = maps.current_map;
let old_map_index = current_map;
let map_changed = egui::ComboBox::from_label("Map")
.width(192.0)
.show_index(ui, &mut current_map, maps.maps.len(), |i| {
&maps.maps[i].2.name
})
.changed();
let old_map_index = if maps.updated {
maps.previous_map
} else {
current_map
};
let map_changed = maps.updated
|| egui::ComboBox::from_label("Map")
.width(192.0)
.show_index(ui, &mut current_map, maps.maps.len(), |i| {
&maps.maps[i].2.name
})
.changed();
ui.label(format!("Map hash: {}", maps.maps[maps.current_map].0));
ui.label(format!(
"Map hash64: {}",
Expand All @@ -350,6 +355,7 @@ impl Overlay for RenderSettingsOverlay {

// Move the Globals from the old scene to the new scene
if map_changed {
maps.previous_map = old_map_index;
// We have learned the power to Take worlds
let mut old_scene = take(&mut maps.map_mut(old_map_index).unwrap().scene);

Expand Down Expand Up @@ -381,6 +387,8 @@ impl Overlay for RenderSettingsOverlay {
discord::set_status_from_mapdata(&maps.maps[maps.current_map].2);
}

maps.updated = false;

let groups_in_current_scene: IntSet<u32> = maps
.current_map()
.unwrap()
Expand Down
Loading