mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 12:25:02 +01:00
Add arg parsing, support multiple worlds
This commit is contained in:
parent
83f35e51ee
commit
129585ba64
5 changed files with 140 additions and 22 deletions
|
|
@ -18,6 +18,7 @@ use crate::{
|
|||
input::Input,
|
||||
math::{center_offset, TILE_SIZE},
|
||||
res::Res,
|
||||
CliArgs,
|
||||
};
|
||||
|
||||
/// Application level state (includes game and ui state, etc.)
|
||||
|
|
@ -38,7 +39,7 @@ pub struct App {
|
|||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
pub fn new(args: CliArgs) -> anyhow::Result<Self> {
|
||||
let rw = graphics::make_window();
|
||||
let sf_egui = SfEgui::new(&rw);
|
||||
let mut res = Res::load()?;
|
||||
|
|
@ -53,7 +54,7 @@ impl App {
|
|||
Ok(Self {
|
||||
rw,
|
||||
should_quit: false,
|
||||
game: GameState::default(),
|
||||
game: GameState::new(args.world_name),
|
||||
res,
|
||||
sf_egui,
|
||||
input: Input::default(),
|
||||
|
|
|
|||
36
src/game.rs
36
src/game.rs
|
|
@ -113,6 +113,23 @@ impl GameState {
|
|||
lightmap.draw(&s);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new(world_name: String) -> GameState {
|
||||
let mut spawn_point = WorldPos::SURFACE_CENTER;
|
||||
spawn_point.y -= 1104;
|
||||
Self {
|
||||
camera_offset: spawn_point,
|
||||
world: World::new(spawn_point, &world_name),
|
||||
gravity: 0.55,
|
||||
tile_to_place: 1,
|
||||
current_biome: Biome::Surface,
|
||||
prev_biome: Biome::Surface,
|
||||
worldgen: Worldgen::default(),
|
||||
ambient_light: 0,
|
||||
light_sources: Vec::new(),
|
||||
tile_db: TileDb::load_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_each_tile_on_screen(
|
||||
|
|
@ -135,22 +152,3 @@ pub fn for_each_tile_on_screen(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GameState {
|
||||
fn default() -> Self {
|
||||
let mut spawn_point = WorldPos::SURFACE_CENTER;
|
||||
spawn_point.y -= 1104;
|
||||
Self {
|
||||
camera_offset: spawn_point,
|
||||
world: World::new(spawn_point, "TestWorld"),
|
||||
gravity: 0.55,
|
||||
tile_to_place: 1,
|
||||
current_biome: Biome::Surface,
|
||||
prev_biome: Biome::Surface,
|
||||
worldgen: Worldgen::default(),
|
||||
ambient_light: 0,
|
||||
light_sources: Vec::new(),
|
||||
tile_db: TileDb::load_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/main.rs
10
src/main.rs
|
|
@ -13,10 +13,18 @@ mod world;
|
|||
mod worldgen;
|
||||
|
||||
use app::App;
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct CliArgs {
|
||||
#[arg(default_value = "TestWorld")]
|
||||
world_name: String,
|
||||
}
|
||||
|
||||
fn try_main() -> anyhow::Result<()> {
|
||||
gamedebug_core::set_enabled(true);
|
||||
let mut app = App::new()?;
|
||||
let cli_args = CliArgs::parse();
|
||||
let mut app = App::new(cli_args)?;
|
||||
app.do_game_loop();
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue