Skip to content

Commit

Permalink
Weather implementation (#260)
Browse files Browse the repository at this point in the history
<!-- Please make sure that your PR is aligned with the guidelines in
CONTRIBUTING.md to the best of your ability. -->
<!-- Good PRs have tests! Make sure you have sufficient test coverage.
-->

## Description

<!-- Describe the changes you've made. You may include any justification
you want here. -->

An implementation of basic weather systems.

The weather component attached to a world instance would be handled for
all clients, except those that have their own weather component; these
clients would be handled separately.

## Test Plan

<!-- Explain how you tested your changes, and include any code that you
used to test this. -->
<!-- If there is an example that is sufficient to use in place of a
playground, replace the playground section with a note that indicates
this. -->

<details>

<summary>Playground</summary>

```rust
fn handle_command_events(
    instances: Query<Entity, With<Instance>>,
    mut exec_cmds: EventReader<CommandExecution>,
    mut commands: Commands,
) {
    for cmd in exec_cmds.iter() {
        let msg = cmd.command.to_string();
        let ent = instances.single();

        match msg.as_str() {
            "ar" => {
                commands.entity(ent).insert(Rain(WEATHER_LEVEL.end));
            }
            "rr" => {
                commands.entity(ent).remove::<Rain>();
            }
            "at" => {
                commands.entity(ent).insert(Thunder(WEATHER_LEVEL.end));
            }
            "rt" => {
                commands.entity(ent).remove::<Thunder>();
            }
            _ => (),
        };
    }
}
```

</details>

<!-- You need to include steps regardless of whether or not you are
using a playground. -->
Steps:
1. Run `cargo test --package valence --lib -- weather::test`

#### Related
Part of #210
Past approach #106

<!-- Link to any issues that have context for this or that this PR
fixes. -->
  • Loading branch information
qualterz authored Mar 16, 2023
1 parent 2c0fb2d commit c9fbd1a
Show file tree
Hide file tree
Showing 3 changed files with 421 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/valence/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub mod server;
mod unit_test;
pub mod util;
pub mod view;
pub mod weather;

pub mod prelude {
pub use async_trait::async_trait;
Expand Down
4 changes: 3 additions & 1 deletion crates/valence/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::player_list::PlayerListPlugin;
use crate::prelude::event::ClientEventPlugin;
use crate::prelude::ComponentPlugin;
use crate::server::connect::do_accept_loop;
use crate::weather::WeatherPlugin;

mod byte_channel;
mod connect;
Expand Down Expand Up @@ -335,7 +336,8 @@ pub fn build_plugin(
.add_plugin(EntityPlugin)
.add_plugin(InstancePlugin)
.add_plugin(InventoryPlugin)
.add_plugin(PlayerListPlugin);
.add_plugin(PlayerListPlugin)
.add_plugin(WeatherPlugin);

/*
println!(
Expand Down
Loading

0 comments on commit c9fbd1a

Please sign in to comment.