diff --git a/Cargo.lock b/Cargo.lock index da16aa4..21c0c78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" dependencies = [ "cfg-if", - "getrandom", + "getrandom 0.3.4", "once_cell", "version_check", "zerocopy", @@ -1092,7 +1092,7 @@ dependencies = [ "critical-section", "foldhash 0.2.0", "futures-channel", - "getrandom", + "getrandom 0.3.4", "hashbrown 0.16.0", "js-sys", "portable-atomic", @@ -2079,6 +2079,27 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.61.2", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -2380,6 +2401,17 @@ dependencies = [ "windows-link 0.2.1", ] +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -2783,7 +2815,7 @@ version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" dependencies = [ - "getrandom", + "getrandom 0.3.4", "libc", ] @@ -3464,6 +3496,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "orbclient" version = "0.3.48" @@ -3622,6 +3660,9 @@ dependencies = [ "bevy", "bevy_aseprite_ultra", "bevy_dev_tools", + "directories", + "serde", + "serde_json", ] [[package]] @@ -3752,7 +3793,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom", + "getrandom 0.3.4", ] [[package]] @@ -3817,6 +3858,17 @@ dependencies = [ "bitflags 2.9.4", ] +[[package]] +name = "redox_users" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" +dependencies = [ + "getrandom 0.2.16", + "libredox", + "thiserror 2.0.17", +] + [[package]] name = "regex" version = "1.12.2" @@ -4573,7 +4625,7 @@ version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ - "getrandom", + "getrandom 0.3.4", "js-sys", "serde", "wasm-bindgen", @@ -4618,6 +4670,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" diff --git a/Cargo.toml b/Cargo.toml index c72a83a..c345354 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,6 @@ lto = "thin" bevy = "0.17.2" bevy_aseprite_ultra = "0.7.0" bevy_dev_tools = "0.17.2" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +directories = "6.0" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1307958 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2025 Dominik Bernroider + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index d807459..88420ea 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,49 @@ -# bernroider-dominik +# Pomomon Garden ![Sleeping Pom](pom-sleep.gif) +Pomomon Garden is a Pomodoro game created during ["Sopra" (Softwareprojekt)](https://www.uni-ulm.de/in/sgi/lehre/softwaojekt-sopra-1/) WiSe 25/26 at the University of Ulm. +It uses the [ECS](https://en.wikipedia.org/wiki/Entity_component_system)-based Rust game engine called [Bevy](https://bevy.org/). +--- -## Getting started +## About the game -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +The game switches between the focus and pause phase. In the focus phase the player is expected to study/work/... while the timer ticks down. +After the timer runs out, the player is prompted to switch to the pause phase. +In this phase he can interact with his farm using Pom, the playable character. -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +--- -## Add your files +## Build and debug instructions -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command: +### Building -``` -cd existing_repo -git remote add origin https://gitlab.uni-ulm.de/softwaregrundprojekt/2025-2026/einzelprojekt/tutorium-moritz/bernroider-dominik/bernroider-dominik.git -git branch -M main -git push -uf origin main +#### Using [Nix Flakes](https://nixos.wiki/wiki/Flakes): + +```sh +git clone https://gitlab.uni-ulm.de/softwaregrundprojekt/2025-2026/einzelprojekt/tutorium-moritz/bernroider-dominik/bernroider-dominik pomomon-garden +cd pomomon-garden +nix develop +cargo run ``` -## Integrate with your tools +#### Other: -- [ ] [Set up project integrations](https://gitlab.uni-ulm.de/softwaregrundprojekt/2025-2026/einzelprojekt/tutorium-moritz/bernroider-dominik/bernroider-dominik/-/settings/integrations) +1. [Install Rust](https://rust-lang.org/tools/install/) +2. [Install Bevy OS depedencies](https://bevy.org/learn/quick-start/getting-started/setup/#installing-os-dependencies) -## Collaborate with your team +```sh +git clone https://gitlab.uni-ulm.de/softwaregrundprojekt/2025-2026/einzelprojekt/tutorium-moritz/bernroider-dominik/bernroider-dominik pomomon-garden +cd pomomon-garden +cargo run +``` -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/) +### Hidden binds (Only available in the debug build) -## Test and Deploy +- `Shift + Enter`: Duration of the current phase is set to 3 seconds. +- `Left Mouse Button` on Tile: Rotate tile state. -Use the built-in continuous integration in GitLab. +--- -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) +## Licensing -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +This project is released under the terms of the [MIT License](LICENSE). diff --git a/assets/config.json b/assets/config.json new file mode 100644 index 0000000..2695fb3 --- /dev/null +++ b/assets/config.json @@ -0,0 +1,5 @@ +{ + "grid_width": 12, + "grid_height": 4, + "pom_speed": 1.5 +} diff --git a/flake.nix b/flake.nix index e054130..59059c3 100644 --- a/flake.nix +++ b/flake.nix @@ -107,7 +107,7 @@ ] ++ bevyDeps; - inherit CARGO_PROFILE_RELEASE_LTO CARGO_PROFILE_RELEASE_CODEGEN_UNITS CARGO_PROFILE_RELEASE_STRIP RUSTFLAGS; + # inherit CARGO_PROFILE_RELEASE_LTO CARGO_PROFILE_RELEASE_CODEGEN_UNITS CARGO_PROFILE_RELEASE_STRIP RUSTFLAGS; shellHook = '' export RUST_SRC_PATH=${fenix.packages.${system}.stable.rust-src}/lib/rustlib/src/rust/library diff --git a/pom-sleep.gif b/pom-sleep.gif new file mode 100644 index 0000000..269ea22 Binary files /dev/null and b/pom-sleep.gif differ diff --git a/src/components/mod.rs b/src/components/mod.rs deleted file mode 100644 index 9cc5313..0000000 --- a/src/components/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod pom; -pub mod tile; diff --git a/src/features/config/components.rs b/src/features/config/components.rs new file mode 100644 index 0000000..94fb4fc --- /dev/null +++ b/src/features/config/components.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use std::fs::File; +use std::io::BufReader; + +#[derive(Resource, Deserialize, Debug)] +pub struct GameConfig { + pub grid_width: u32, + pub grid_height: u32, + pub pom_speed: f32, +} + +impl Default for GameConfig { + fn default() -> Self { + Self { + grid_width: 12, + grid_height: 4, + pom_speed: 1.5, + } + } +} + +impl GameConfig { + pub fn read_config() -> Option { + let file = File::open("assets/config.json").ok()?; + let reader = BufReader::new(file); + serde_json::from_reader(reader).ok() + } +} diff --git a/src/features/config/mod.rs b/src/features/config/mod.rs new file mode 100644 index 0000000..f188f2c --- /dev/null +++ b/src/features/config/mod.rs @@ -0,0 +1 @@ +pub mod components; diff --git a/src/plugins/core.rs b/src/features/core/mod.rs similarity index 86% rename from src/plugins/core.rs rename to src/features/core/mod.rs index fd2d174..bc0e573 100644 --- a/src/plugins/core.rs +++ b/src/features/core/mod.rs @@ -1,5 +1,6 @@ -use crate::states::*; -use bevy::prelude::*; +use crate::prelude::*; + +pub mod states; pub struct CorePlugin; diff --git a/src/features/core/states.rs b/src/features/core/states.rs new file mode 100644 index 0000000..e14ed92 --- /dev/null +++ b/src/features/core/states.rs @@ -0,0 +1,8 @@ +use crate::prelude::*; + +#[derive(States, Clone, PartialEq, Eq, Debug, Hash, Default)] +pub enum AppState { + #[default] + StartScreen, + GameScreen, +} diff --git a/src/features/game_screen/mod.rs b/src/features/game_screen/mod.rs new file mode 100644 index 0000000..2a74417 --- /dev/null +++ b/src/features/game_screen/mod.rs @@ -0,0 +1,18 @@ +use crate::prelude::*; + +pub struct GameScreenPlugin; + +impl Plugin for GameScreenPlugin { + fn build(&self, app: &mut App) { + app.add_systems(OnEnter(AppState::GameScreen), setup); + app.add_systems(OnExit(AppState::GameScreen), cleanup); + } +} + +fn setup(mut clear_color: ResMut) { + *clear_color = ClearColor(Color::srgb(0.294, 0.412, 0.184)); +} + +fn cleanup(mut clear_color: ResMut) { + *clear_color = ClearColor(Color::srgb(0.2, 0.2, 0.2)); +} diff --git a/src/components/tile.rs b/src/features/grid/components.rs similarity index 90% rename from src/components/tile.rs rename to src/features/grid/components.rs index 12d7376..6875de2 100644 --- a/src/components/tile.rs +++ b/src/features/grid/components.rs @@ -1,6 +1,5 @@ -use bevy::prelude::*; - -use crate::errors::GridError; +use super::errors::GridError; +use crate::prelude::*; #[derive(Component)] pub struct Tile { @@ -8,7 +7,7 @@ pub struct Tile { pub y: u32, } -#[derive(Component, Default)] +#[derive(Component, Default, Serialize, Deserialize, Clone, Copy, Debug)] pub enum TileState { #[default] Unclaimed, diff --git a/src/features/grid/consts.rs b/src/features/grid/consts.rs new file mode 100644 index 0000000..bc45548 --- /dev/null +++ b/src/features/grid/consts.rs @@ -0,0 +1 @@ +pub const TILE_SIZE: f32 = 32.0; diff --git a/src/errors.rs b/src/features/grid/errors.rs similarity index 100% rename from src/errors.rs rename to src/features/grid/errors.rs diff --git a/src/plugins/grid.rs b/src/features/grid/mod.rs similarity index 56% rename from src/plugins/grid.rs rename to src/features/grid/mod.rs index d8a4f75..1f06f99 100644 --- a/src/plugins/grid.rs +++ b/src/features/grid/mod.rs @@ -1,16 +1,9 @@ -use crate::{ - components::tile::{Grid, Tile, TileState}, - states::AppState, -}; -use bevy::prelude::*; -use bevy_aseprite_ultra::prelude::AseSlice; +use crate::prelude::*; -pub const TILE_SIZE: f32 = 32.0; -pub const GRID_WIDTH: u32 = 10; -pub const GRID_HEIGHT: u32 = 10; - -pub const GRID_START_X: f32 = -(GRID_WIDTH as f32 * TILE_SIZE) / 2.0 + TILE_SIZE / 2.0; -pub const GRID_START_Y: f32 = -(GRID_HEIGHT as f32 * TILE_SIZE) / 2.0 + TILE_SIZE / 2.0; +pub mod components; +pub mod consts; +pub mod errors; +pub mod utils; pub struct GridPlugin; @@ -26,13 +19,15 @@ impl Plugin for GridPlugin { } } -fn setup(mut commands: Commands, asset_server: Res) { - let mut tiles = Vec::with_capacity(GRID_WIDTH as usize); +fn setup(mut commands: Commands, asset_server: Res, config: Res) { + let grid_width = config.grid_width; + let grid_height = config.grid_height; + let mut tiles = Vec::with_capacity(grid_width as usize); - for x in 0..GRID_WIDTH { - let mut column = Vec::with_capacity(GRID_HEIGHT as usize); + for x in 0..grid_width { + let mut column = Vec::with_capacity(grid_height as usize); - for y in 0..GRID_HEIGHT { + for y in 0..grid_height { let tile_entity = commands .spawn(( Tile { x, y }, @@ -42,7 +37,13 @@ fn setup(mut commands: Commands, asset_server: Res) { aseprite: asset_server.load("tiles/tile-unclaimed.aseprite"), }, Sprite::default(), - Transform::from_translation(grid_to_world_coords(x, y, None)), + Transform::from_translation(grid_to_world_coords( + x, + y, + None, + grid_width, + grid_height, + )), )) .id(); column.push(tile_entity); @@ -51,8 +52,8 @@ fn setup(mut commands: Commands, asset_server: Res) { } commands.insert_resource(Grid { - width: GRID_WIDTH, - height: GRID_HEIGHT, + width: grid_width, + height: grid_height, tiles, }); } @@ -83,28 +84,3 @@ fn update_tile_colors( }; } } - -pub fn world_to_grid_coords(world_pos: Vec3) -> (u32, u32) { - let x = ((world_pos.x - GRID_START_X + TILE_SIZE / 2.0) / TILE_SIZE).floor(); - let y = ((world_pos.y - GRID_START_Y + TILE_SIZE / 2.0) / TILE_SIZE).floor(); - - let mut x_u32 = x as u32; - let mut y_u32 = y as u32; - - if x_u32 >= GRID_WIDTH { - x_u32 = GRID_WIDTH - 1; - } - if y_u32 >= GRID_HEIGHT { - y_u32 = GRID_HEIGHT - 1; - } - - (x_u32, y_u32) -} - -pub fn grid_to_world_coords(grid_x: u32, grid_y: u32, z: Option) -> Vec3 { - Vec3::new( - GRID_START_X + grid_x as f32 * TILE_SIZE, - GRID_START_Y + grid_y as f32 * TILE_SIZE, - z.unwrap_or(0.0), - ) -} diff --git a/src/features/grid/utils.rs b/src/features/grid/utils.rs new file mode 100644 index 0000000..3c032da --- /dev/null +++ b/src/features/grid/utils.rs @@ -0,0 +1,43 @@ +use crate::prelude::*; + +pub fn grid_start_x(grid_width: u32) -> f32 { + -(grid_width as f32 * TILE_SIZE) / 2.0 + TILE_SIZE / 2.0 +} + +pub fn grid_start_y(grid_height: u32) -> f32 { + -(grid_height as f32 * TILE_SIZE) / 2.0 + TILE_SIZE / 2.0 +} + +pub fn world_to_grid_coords(world_pos: Vec3, grid_width: u32, grid_height: u32) -> (u32, u32) { + let start_x = grid_start_x(grid_width); + let start_y = grid_start_y(grid_height); + + let x = ((world_pos.x - start_x + TILE_SIZE / 2.0) / TILE_SIZE).floor(); + let y = ((world_pos.y - start_y + TILE_SIZE / 2.0) / TILE_SIZE).floor(); + + let mut x_u32 = x as u32; + let mut y_u32 = y as u32; + + if x_u32 >= grid_width { + x_u32 = grid_width - 1; + } + if y_u32 >= grid_height { + y_u32 = grid_height - 1; + } + + (x_u32, y_u32) +} + +pub fn grid_to_world_coords( + grid_x: u32, + grid_y: u32, + z: Option, + grid_width: u32, + grid_height: u32, +) -> Vec3 { + Vec3::new( + grid_start_x(grid_width) + grid_x as f32 * TILE_SIZE, + grid_start_y(grid_height) + grid_y as f32 * TILE_SIZE, + z.unwrap_or(0.0), + ) +} diff --git a/src/features/hud/components.rs b/src/features/hud/components.rs new file mode 100644 index 0000000..6d93783 --- /dev/null +++ b/src/features/hud/components.rs @@ -0,0 +1,66 @@ +use crate::{features::phase::components::TimerSettings, prelude::*}; + +#[derive(Component)] +pub enum RootMarker { + Status, + Settings, +} + +#[derive(Component)] +pub enum TextType { + Phase, + Timer, +} + +#[derive(Component)] +pub enum ButtonType { + SettingsOpen, + SettingsClose, + SettingsExit, + SettingsSave, + SettingsTimerChange { + input: SettingsTimerInput, + amount: i32, + }, +} + +#[derive(Clone)] +pub enum TimerType { + Focus, + ShortBreak, + LongBreak, +} + +impl TimerSettings { + pub fn change(&mut self, timer_type: &TimerType, amount: i32) { + match timer_type { + TimerType::Focus => { + self.focus_duration = (self.focus_duration as i32 + amount) as u32; + if self.focus_duration > 7259 { + // 120:59 + self.focus_duration = 7259; + } + } + TimerType::LongBreak => { + self.long_break_duration = (self.long_break_duration as i32 + amount) as u32; + if self.long_break_duration > 7259 { + // 120:59 + self.long_break_duration = 7259; + } + } + TimerType::ShortBreak => { + self.short_break_duration = (self.short_break_duration as i32 + amount) as u32; + if self.short_break_duration > 7259 { + // 120:59 + self.short_break_duration = 7259; + } + } + } + } +} + +#[derive(Component, Clone)] +pub enum SettingsTimerInput { + Minutes(TimerType), + Seconds(TimerType), +} diff --git a/src/features/hud/mod.rs b/src/features/hud/mod.rs new file mode 100644 index 0000000..6091430 --- /dev/null +++ b/src/features/hud/mod.rs @@ -0,0 +1,157 @@ +use crate::features::inventory; +use crate::features::phase::components::TimerSettings; +use crate::features::savegame::messages::SavegameDumpMessage; +use crate::prelude::*; +use components::*; +use ui::*; + +pub mod components; +pub mod ui; + +pub struct HudPlugin; + +impl Plugin for HudPlugin { + fn build(&self, app: &mut App) { + app.add_systems(OnEnter(AppState::GameScreen), setup); + app.add_systems(OnExit(AppState::GameScreen), cleanup); + app.add_systems( + Update, + (update_status, buttons, update_timer_settings).run_if(in_state(AppState::GameScreen)), + ); + } +} + +fn setup(mut commands: Commands) { + commands.spawn(( + RootMarker::Status, + Node { + position_type: PositionType::Absolute, + bottom: px(0), + left: px(0), + + width: percent(100), + height: px(50), + + justify_content: JustifyContent::SpaceAround, + align_items: AlignItems::Center, + flex_direction: FlexDirection::Row, + ..default() + }, + BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)), + children![ + text_with_component(TextType::Phase, "...", 16.0, Color::WHITE), + text_with_component(TextType::Timer, "...", 16.0, Color::WHITE), + button( + inventory::components::ButtonType::InventoryOpen, + ButtonVariant::Secondary, + Node { + padding: UiRect::all(px(10)), + ..default() + }, + "Inventar", + 16.0 + ), + button( + ButtonType::SettingsOpen, + ButtonVariant::Secondary, + Node { + padding: UiRect::all(px(10)), + ..default() + }, + "Einstellungen", + 16.0 + ) + ], + )); +} + +fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, &TextType)>) { + if !phase_res.is_changed() { + return; + } + let current_phase = &phase_res.0; + + for (mut text, status_type) in text_query.iter_mut() { + text.0 = match status_type { + TextType::Phase => current_phase.display_name().into(), + TextType::Timer => current_phase.format_duration(), + }; + } +} + +fn buttons( + mut commands: Commands, + mut interaction_query: Query<(&Interaction, &ButtonType), (Changed, With