fn on_tile_click(
	tilesets: Tilesets,
	build_mode: Res<BuildMode>,
	mut event_reader: EventReader<helpers::ClickEvent>,
	mut placer: TilePlacer,
) {
	if let Some(tileset) = tilesets.get_by_name(MY_TILESET) {
		for helpers::ClickEvent(ref pos, pressed) in event_reader.iter() {
			if !pressed {
				continue;
			}

			let tileset_id = tileset.id().clone();
			let layer_id = build_mode.active_layer;
			let tile_name = &build_mode.tile_name;
			let pos: TilePos = (*pos).into();

			if let Some(group_id) = tileset.get_tile_group_id(tile_name) {
				let tile_id = TileId::new(*group_id, tileset_id);

				// Place the tile!
				let place_mode = &PLACE_MODES[build_mode.mode];
				let error = match place_mode {
					PlacementMode::Place => placer.place(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::TryPlace => placer.try_place(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::Toggle => placer.toggle(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::ToggleMatch => {
						placer.toggle_matching(tile_id, pos, 0u16, layer_id).err()
					},
					PlacementMode::Replace => placer.replace(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::Remove => placer.remove(pos, 0u16, layer_id).err(),
				};

				if let Some(err) = error {
					// Just print any errors to the console without panicking
					eprintln!("Could not place tile: {}", err);
				}
			}
		}
	}
}
/// A system that adds/removes tiles when clicked
A system that adds/removes tiles when clicked
A system that adds / removes tiles when clicked
fn on_tile_click(
	tilesets: Tilesets,
	build_mode: Res<BuildMode>,
	mut event_reader: EventReader<helpers::ClickEvent>,
	mut placer: TilePlacer,
) {
	if let Some(tileset) = tilesets.get_by_name(MY_TILESET) {
		for helpers::ClickEvent(ref pos, pressed) in event_reader.iter() {
			if !pressed {
				continue;
			}
			let tileset_id = tileset.id().clone();
			let layer_id = build_mode.active_layer;
			let tile_name = &build_mode.tile_name;
			let pos: TilePos = (*pos).into();
			if let Some(group_id) = tileset.get_tile_group_id(tile_name) {
				let tile_id = TileId::new(*group_id, tileset_id);
				// Place the tile!
				let place_mode = &PLACE_MODES[build_mode.mode];
				let error = match place_mode {
					PlacementMode::Place => placer.place(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::TryPlace => placer.try_place(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::Toggle => placer.toggle(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::ToggleMatch => {
						placer.toggle_matching(tile_id, pos, 0u16, layer_id).err()
					},
					PlacementMode::Replace => placer.replace(tile_id, pos, 0u16, layer_id).err(),
					PlacementMode::Remove => placer.remove(pos, 0u16, layer_id).err(),
				};
				if let Some(err) = error {
					// Just print any errors to the console without panicking
					eprintln!("Could not place tile: {}", err);
				}
			}
		}
	}
}
fn on_tile_click ( tilesets : Tilesets , build_mode : Res < BuildMode > , mut event_reader : EventReader < helpers :: ClickEvent > , mut placer : TilePlacer , ) { if let Some ( tileset ) = tilesets . get_by_name ( MY_TILESET ) { for helpers :: ClickEvent ( ref pos , pressed ) in event_reader . iter ( ) { if ! pressed { continue ; } let tileset_id = tileset . id ( ) . clone ( ) ; let layer_id = build_mode . active_layer ; let tile_name = & build_mode . tile_name ; let pos : TilePos = ( * pos ) . into ( ) ; if let Some ( group_id ) = tileset . get_tile_group_id ( tile_name ) { let tile_id = TileId :: new ( * group_id , tileset_id ) ; // Place the tile! let place_mode = & PLACE_MODES [ build_mode . mode ] ; let error = match place_mode { PlacementMode :: Place => placer . place ( tile_id , pos , 0u16 , layer_id ) . err ( ) , PlacementMode :: TryPlace => placer . try_place ( tile_id , pos , 0u16 , layer_id ) . err ( ) , PlacementMode :: Toggle => placer . toggle ( tile_id , pos , 0u16 , layer_id ) . err ( ) , PlacementMode :: ToggleMatch => { placer . toggle_matching ( tile_id , pos , 0u16 , layer_id ) . err ( ) } , PlacementMode :: Replace => placer . replace ( tile_id , pos , 0u16 , layer_id ) . err ( ) , PlacementMode :: Remove => placer . remove ( pos , 0u16 , layer_id ) . err ( ) , } ; if let Some ( err ) = error { // Just print any errors to the console without panicking eprintln ! ( " " err ) ; } } } } }
A system that adds/removes tiles when clicked
A system that adds / removes tiles when clicked
tilesets
Tilesets
build_mode
Res<BuildMode>
event_reader
EventReader<helpers::ClickEvent>
placer
TilePlacer
tilesets
Tilesets
build_mode
Res<BuildMode>
event_reader
EventReader<helpers::ClickEvent>
placer
TilePlacer