/// System controlling the "Build Mode"
System controlling the "Build Mode"
System controlling the " Build Mode "
fn on_keypress(
	keys: Res<Input<KeyCode>>,
	mut build_mode: ResMut<BuildMode>,
	mut serializer: TilemapSerializer,
	mut saved: ResMut<SavedMap>,
) {
	if keys.just_pressed(KeyCode::W) {
		build_mode.tile_name = String::from("Wall");
	} else if keys.just_pressed(KeyCode::G) {
		build_mode.tile_name = String::from("Glass");
	} else if keys.just_pressed(KeyCode::D) {
		build_mode.tile_name = String::from("Dirt");
	} else if keys.just_pressed(KeyCode::E) {
		build_mode.tile_name = String::from("Empty");
	} else if keys.just_pressed(KeyCode::P) {
		build_mode.tile_name = String::from("Pipe");
	} else if keys.just_pressed(KeyCode::Up) {
		build_mode.mode = (build_mode.mode + 1) % PLACE_MODES.len();
	} else if keys.just_pressed(KeyCode::Down) {
		build_mode.mode = if build_mode.mode == 0 {
			PLACE_MODES.len() - 1
		} else {
			build_mode.mode - 1
		};
	} else if keys.just_pressed(KeyCode::Key1) {
		build_mode.active_layer = 0u16;
	} else if keys.just_pressed(KeyCode::Key2) {
		build_mode.active_layer = 1u16;
	} else if keys.just_pressed(KeyCode::Key3) {
		build_mode.active_layer = 2u16;
	} else if keys.just_pressed(KeyCode::Comma) {
		saved.map = serializer.save_maps();
		println!(
			"{}",
			serde_json::to_string(&saved.map.as_ref().unwrap()).unwrap()
		);
	} else if keys.just_pressed(KeyCode::Period) {
		if let Some(map) = &saved.map {
			serializer.load_maps(map);
		}
	}
}
fn on_keypress ( keys : Res < Input < KeyCode > > , mut build_mode : ResMut < BuildMode > , mut serializer : TilemapSerializer , mut saved : ResMut < SavedMap > , ) { if keys . just_pressed ( KeyCode :: W ) { build_mode . tile_name = String :: from ( " " ) ; } else if keys . just_pressed ( KeyCode :: G ) { build_mode . tile_name = String :: from ( " " ) ; } else if keys . just_pressed ( KeyCode :: D ) { build_mode . tile_name = String :: from ( " " ) ; } else if keys . just_pressed ( KeyCode :: E ) { build_mode . tile_name = String :: from ( " " ) ; } else if keys . just_pressed ( KeyCode :: P ) { build_mode . tile_name = String :: from ( " " ) ; } else if keys . just_pressed ( KeyCode :: Up ) { build_mode . mode = ( build_mode . mode + 1 ) % PLACE_MODES . len ( ) ; } else if keys . just_pressed ( KeyCode :: Down ) { build_mode . mode = if build_mode . mode == 0 { PLACE_MODES . len ( ) - 1 } else { build_mode . mode - 1 } ; } else if keys . just_pressed ( KeyCode :: Key1 ) { build_mode . active_layer = 0u16 ; } else if keys . just_pressed ( KeyCode :: Key2 ) { build_mode . active_layer = 1u16 ; } else if keys . just_pressed ( KeyCode :: Key3 ) { build_mode . active_layer = 2u16 ; } else if keys . just_pressed ( KeyCode :: Comma ) { saved . map = serializer . save_maps ( ) ; println ! ( " " serde_json to_string ( saved map as_ref ( ) unwrap ( ) ) unwrap ( ) ) ; } else if keys . just_pressed ( KeyCode :: Period ) { if let Some ( map ) = & saved . map { serializer . load_maps ( map ) ; } } }
System controlling the "Build Mode"
System controlling the " Build Mode "
keys
Res<Input<KeyCode>>
build_mode
ResMut<BuildMode>
serializer
TilemapSerializer
saved
ResMut<SavedMap>