Skip to content

Commit

Permalink
got events + goals working! Initial tutorial in beverley beck!
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-orr committed Jan 7, 2023
1 parent 0374b3e commit 795649d
Show file tree
Hide file tree
Showing 20 changed files with 1,253 additions and 271 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/temporary_levels
1,079 changes: 1,078 additions & 1 deletion assets/levels/beverley.lvl.json

Large diffs are not rendered by default.

193 changes: 1 addition & 192 deletions assets/levels/test.lvl.json
Original file line number Diff line number Diff line change
@@ -1,192 +1 @@
{
"tiles": [
[
{
"tile_type": "City",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 1
},
{
"tile_type": "City",
"contents": "None",
"is_goal": true,
"is_wet": false,
"height": 2
},
{
"tile_type": "City",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 2
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 1
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
}
],
[
{
"tile_type": "City",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 1
},
{
"tile_type": "City",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 1
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 2
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 1
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
}
],
[
{
"tile_type": "City",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
}
],
[
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 0
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 1
},
{
"tile_type": "Land",
"contents": "Canal",
"is_goal": false,
"is_wet": true,
"height": 2
},
{
"tile_type": "Land",
"contents": "Canal",
"is_goal": false,
"is_wet": true,
"height": 2
}
],
[
{
"tile_type": "Land",
"contents": "Canal",
"is_goal": false,
"is_wet": true,
"height": 1
},
{
"tile_type": "Land",
"contents": "Canal",
"is_goal": false,
"is_wet": true,
"height": 1
},
{
"tile_type": "Land",
"contents": "Canal",
"is_goal": false,
"is_wet": true,
"height": 2
},
{
"tile_type": "Land",
"contents": "Canal",
"is_goal": false,
"is_wet": true,
"height": 2
},
{
"tile_type": "Land",
"contents": "None",
"is_goal": false,
"is_wet": false,
"height": 3
}
]
],
"title": "Test Level",
"width": 5,
"height": 5
}
{"tiles":[[{"tile_type":"City","contents":"None","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"City","contents":"None","is_goal":true,"cost_modifier":"None","height":2},{"tile_type":"City","contents":"None","is_goal":false,"cost_modifier":"None","height":2},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0}],[{"tile_type":"City","contents":"None","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"City","contents":"None","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":2},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0}],[{"tile_type":"City","contents":"None","is_goal":false,"cost_modifier":"None","height":0},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0}],[{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":0},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"Land","contents":"River","is_goal":false,"cost_modifier":"None","height":2},{"tile_type":"Land","contents":"River","is_goal":false,"cost_modifier":"None","height":2}],[{"tile_type":"Land","contents":"River","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"Land","contents":"River","is_goal":false,"cost_modifier":"None","height":1},{"tile_type":"Land","contents":"River","is_goal":false,"cost_modifier":"None","height":2},{"tile_type":"Land","contents":"River","is_goal":false,"cost_modifier":"None","height":2},{"tile_type":"Land","contents":"None","is_goal":false,"cost_modifier":"None","height":3}]],"title":"Test Level","initial_description":null,"sidebar_text":null,"width":5,"height":5,"events":[]}
2 changes: 0 additions & 2 deletions src/camera_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ fn control_camera(
if ev.unit == MouseScrollUnit::Pixel {
scalar /= controller.pixels_per_line;
}
info!("Scrolling to zoom - {scalar} - {ev:?}");
scalar = 1. - scalar.clamp(-1.5, 1.5) * controller.mouse_wheel_zoom_sensitivity;
info!("Scroll result - {scalar}");
events.send(ControlEvent::Zoom(scalar));
}
}
36 changes: 2 additions & 34 deletions src/game/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ mod tile;

use bevy::{
prelude::*,
render::{
render_resource::{
AddressMode, Extent3d, FilterMode, SamplerDescriptor, TextureDimension, TextureFormat,
},
texture::{TextureFormatPixelInfo, Volume},
render::render_resource::{
AddressMode, Extent3d, FilterMode, SamplerDescriptor, TextureDimension, TextureFormat,
},
utils::HashMap,
};
Expand Down Expand Up @@ -46,13 +43,6 @@ impl Plugin for BoardPlugin {
.add_system(animate_goal.run_in_state(AppState::InGame))
.add_system(process_selection_events.run_in_state(AppState::InGame))
.add_exit_system(AppState::InGame, clear_board);
#[cfg(feature = "dev")]
app.add_plugin(bevy_inspector_egui::quick::AssetInspectorPlugin::<
TileMaterial,
>::default());
// .add_plugin(bevy_inspector_egui::quick::ResourceInspectorPlugin::<
// BoardRuntimeAssets,
// >::default());
}
}

Expand Down Expand Up @@ -216,9 +206,7 @@ fn build_tile(
);
}
if updated {
info!("Updated at least one entity!");
if let Ok(board) = boards.get_single() {
info!("We got a board!");
let width = board.width;
let height = board.height;
let mut content = vec![(0u8, false, false, 0u8); width * height];
Expand Down Expand Up @@ -267,15 +255,6 @@ fn build_tile(
]
})
.collect::<Vec<_>>();

info!(
"Size: {size:?} - {}, format : {format:?} - {}, data: {}, content_len: {}\n{data:?}",
size.volume(),
format.pixel_size(),
data.len(),
content.len()
);

let mut image = Image::new(size, TextureDimension::D2, data, format);
image.sampler_descriptor =
bevy::render::texture::ImageSampler::Descriptor(SamplerDescriptor {
Expand All @@ -288,12 +267,6 @@ fn build_tile(
});

let result = images.set(board_assets.tile_info_map.clone(), image);
info!(
"Set the image to {result:?} from {:?}",
board_assets.tile_info_map
);

info!("Board width {} height {}", &board.width, &board.height);

let (offset_x, offset_y) = (board.width % 2 == 0, board.height % 2 == 0);

Expand Down Expand Up @@ -493,7 +466,6 @@ fn spawn_content(
match tile.contents {
TileContents::None => {}
TileContents::Road => {
println!("Setting up road!");
let neighbours = check_neighbours(neighbours, |t| t.contents == TileContents::Road);

let n = neighbours[1];
Expand All @@ -504,7 +476,6 @@ fn spawn_content(
spawn_variant(tile, !is_wet, assets, n, w, e, s, parent, base_material);
}
TileContents::Canal => {
println!("Setting up canal!");
let neighbours = check_neighbours(neighbours, |t| {
matches!(t.contents, TileContents::Canal | TileContents::River)
&& tile.z.abs_diff(t.z) < 2
Expand All @@ -524,7 +495,6 @@ fn spawn_content(
spawn_variant(tile, !is_wet, assets, n, w, e, s, parent, base_material);
}
TileContents::River => {
println!("Setting up river!");
let neighbours = check_neighbours(neighbours, |t| {
matches!(t.contents, TileContents::Canal | TileContents::River)
&& tile.z.abs_diff(t.z) < 2
Expand All @@ -544,7 +514,6 @@ fn spawn_content(
spawn_variant(tile, !is_wet, assets, n, w, e, s, parent, base_material);
}
TileContents::Lock => {
println!("Setting up lock!");
let neighbours = check_neighbours(neighbours, |t| {
matches!(
t.contents,
Expand Down Expand Up @@ -581,7 +550,6 @@ fn spawn_content(
spawn_variant(tile, !is_wet, assets, n, w, e, s, parent, base_material);
}
TileContents::Aquaduct(h) => {
println!("Setting up aquaduct {h:?}");
let z = tile.z + h;
let neighbours = check_neighbours(neighbours, |t| {
matches!(
Expand Down
1 change: 0 additions & 1 deletion src/game/board/board_runtime_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub fn setup_board_materials(
},
info_map: tile_info_map.clone(),
};
info!("Making sure all the values aren't optimized away... {material:?}");
let decoration_material = tile_materials.add(material);

let selector = meshes.add(shape::Box::new(1., 0.5, 1.).into());
Expand Down
12 changes: 6 additions & 6 deletions src/game/board/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

use crate::assets::CanalManiaAssets;

#[derive(Component, Default, Debug, Clone, Reflect, Serialize, Deserialize)]
#[derive(Component, Default, Debug, Clone, FromReflect, Reflect, Serialize, Deserialize)]
#[reflect(Component)]
pub struct Tile {
pub x: usize,
Expand All @@ -23,7 +23,7 @@ pub struct Tile {
pub cost_modifier: TileCostModifier,
}

#[derive(Clone, Copy, Debug, Reflect, Serialize, Deserialize, Hash, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Reflect, FromReflect, Serialize, Deserialize, Hash, PartialEq, Eq)]
pub enum TileCostModifier {
None,
Multiplier(usize),
Expand All @@ -36,7 +36,7 @@ impl Default for TileCostModifier {
}
}

#[derive(Clone, Copy, Debug, Reflect, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Reflect, Serialize, FromReflect, Deserialize, PartialEq, Eq)]
pub enum Wetness {
Dry,
WaterSource,
Expand All @@ -49,10 +49,10 @@ impl Default for Wetness {
}
}

#[derive(Component, Default, Clone, Debug)]
#[derive(Component, Default, Clone, Debug, Reflect)]
pub struct TileNeighbours(pub [Option<Entity>; 8]);

#[derive(Debug, Clone, Copy, Reflect, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Reflect, FromReflect, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TileType {
Land,
Farm,
Expand All @@ -65,7 +65,7 @@ impl Default for TileType {
}
}

#[derive(Debug, Clone, Copy, Reflect, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Reflect, FromReflect, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TileContents {
None,
Road,
Expand Down
1 change: 1 addition & 0 deletions src/game/editor_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ fn save(tiles: &Query<&Tile>, level: &Level) {
level.tiles = tiles;

let mut path = FileAssetIo::get_base_path();
path.push("temporary_levels");
if let Ok(time) = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) {
let time = time.as_secs();
path.push(format!("edited_level_{time:?}.lvl.json"));
Expand Down
Loading

0 comments on commit 795649d

Please sign in to comment.