Skip to content
Open
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
19 changes: 17 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use map::element::ElementLibrary;
use map::Map;
use pico_args::{Arguments, Error};
use systems::camera::{camera_controller_system, camera_system, CameraController};
use systems::navigation::NavigationInfo;
use systems::render::{animation_system, map_chunk_view_system, visibility_system};
use systems::settings::{settings_system, Settings};
use systems::setup::setup_system;
Expand All @@ -30,15 +31,24 @@ fn main() -> Result<()> {
let maps_path = game_path.join("contents").join("maps");
let gfx_path = maps_path.join("gfx.jar");

let base_map_gfx_path = maps_path.join("gfx");

match pargs.value_from_str::<&str, i32>("--map") {
Ok(map_arg) => {
let map_path = maps_path.join("gfx").join(format!("{}.jar", map_arg));
let map_path = base_map_gfx_path.join(format!("{}.jar", map_arg));
let lib_path = maps_path.join("data.jar");

let map = Map::load(File::open(map_path)?)?;
let lib = ElementLibrary::load(File::open(lib_path)?)?;

let map_ids = get_map_ids(&base_map_gfx_path)?;
let map_index = map_ids.iter().position(|id| id == &map_arg);

App::new()
.insert_resource(WindowDescriptor {
title: format!("vakfu (Map id : {})", map_arg),
..default()
})
.add_plugins_with(DefaultPlugins, |group| {
group.add_before::<bevy::asset::AssetPlugin, _>(JarAssetIo::plugin(gfx_path))
})
Expand All @@ -47,6 +57,11 @@ fn main() -> Result<()> {
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.init_asset_loader::<TgamLoader>()
.insert_resource(Settings::default())
.insert_resource(NavigationInfo {
map_ids,
current_index: map_index.unwrap(),
game_path: game_path.clone(),
})
.insert_resource(CameraController::default())
.insert_resource(lib)
.insert_resource(map)
Expand All @@ -68,7 +83,7 @@ fn main() -> Result<()> {
Ok(())
}
Err(Error::MissingOption(_) | Error::OptionWithoutAValue(_)) => {
match get_map_ids(maps_path.join("gfx")) {
match get_map_ids(&base_map_gfx_path) {
Ok(map_ids) => Err(anyhow!(
"Map isn't specified, following map ids are available :\n{:?}",
map_ids
Expand Down
1 change: 1 addition & 0 deletions src/systems/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod camera;
pub mod navigation;
pub mod render;
pub mod settings;
pub mod setup;
Expand Down
19 changes: 19 additions & 0 deletions src/systems/navigation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::{env, path::PathBuf, process::Command};

#[derive(Debug)]
pub struct NavigationInfo {
pub map_ids: Vec<i32>,
pub current_index: usize,
pub game_path: PathBuf,
}

pub fn start_other_vakfu(value: &i32, game_path: &PathBuf) {
let args: Vec<_> = env::args().collect();
Command::new(args.get(0).unwrap())
.arg("--path")
.arg(game_path)
.arg("--map")
.arg(value.to_string())
.spawn()
.ok();
}
52 changes: 50 additions & 2 deletions src/systems/ui.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use bevy::prelude::*;
use bevy::{app::AppExit, prelude::*};
use bevy_egui::{egui, EguiContext};

use crate::systems::settings::Settings;

pub fn ui_system(mut egui_context: ResMut<EguiContext>, mut settings: ResMut<Settings>) {
use super::navigation::{start_other_vakfu, NavigationInfo};

pub fn ui_system(
mut egui_context: ResMut<EguiContext>,
mut settings: ResMut<Settings>,
navigation: Res<NavigationInfo>,
mut exit: EventWriter<AppExit>,
) {
let copy = settings.clone();

egui::Window::new("Settings").show(egui_context.ctx_mut(), |ui| {
Expand All @@ -23,6 +30,47 @@ pub fn ui_system(mut egui_context: ResMut<EguiContext>, mut settings: ResMut<Set
});
});

egui::Window::new("Navigation").show(egui_context.ctx_mut(), |ui| {
ui.horizontal(|ui| {
if navigation.current_index > 0 {
let previous_value = navigation
.map_ids
.get(navigation.current_index - 1)
.unwrap();
if ui
.button(format!("Previous ({})", previous_value))
.clicked()
{
start_other_vakfu(previous_value, &navigation.game_path);
exit.send(AppExit);
};
}
if navigation.current_index < navigation.map_ids.len() - 1 {
let next_value = navigation
.map_ids
.get(navigation.current_index + 1)
.unwrap();
if ui.button(format!("Next ({})", next_value)).clicked() {
start_other_vakfu(next_value, &navigation.game_path);
exit.send(AppExit);
};
}
});
ui.separator();
ui.label("Open specific map");
let map_list = egui::ScrollArea::vertical()
.max_height(200.0)
.auto_shrink([false; 2]);
map_list.show(ui, |ui| {
for map_id in &navigation.map_ids {
if ui.button(format!("{}", map_id)).clicked() {
start_other_vakfu(map_id, &navigation.game_path);
exit.send(AppExit);
};
}
});
});

if settings.as_ref() != &copy {
settings.updated = true;
}
Expand Down