This commit is contained in:
Michael Zhang 2024-11-11 19:13:59 -06:00
parent f410eda923
commit feaf5c050b
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
11 changed files with 142 additions and 92 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
/dist
.direnv

6
Cargo.lock generated
View file

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "ab_glyph"
@ -4101,6 +4101,10 @@ dependencies = [
[[package]]
name = "server"
version = "0.1.0"
dependencies = [
"bevy",
"common",
]
[[package]]
name = "sharded-slab"

View file

@ -3,6 +3,14 @@ pub mod state;
use bevy::prelude::*;
use crate::state::GameState;
pub fn base_bevy_app() -> App {
let mut app = App::new();
app.insert_resource(GameState::default());
app
}
#[derive(Component)]
pub struct ChampionItems(Vec<ItemSlot>);

View file

@ -5,29 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
@ -41,11 +23,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1698420672,
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
"lastModified": 1721727458,
"narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=",
"owner": "nix-community",
"repo": "naersk",
"rev": "aeb58d5e8faead8980a807c840232697982d47b9",
"rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11",
"type": "github"
},
"original": {
@ -56,11 +38,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1712573573,
"narHash": "sha256-xxon7WwNm4/EadMKg1eF40/5s0O78nXUy2ILZt6vT7E=",
"owner": "NixOS",
"lastModified": 1663551060,
"narHash": "sha256-e2SR4cVx9p7aW/XnVsGsWZBplApA9ZJUjc0fejJhnYo=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0d28066770464d19d637f6e8e42e8688420b6ac6",
"rev": "8a5b9ee7b7a2b38267c9481f5c629c015108ab0d",
"type": "github"
},
"original": {
@ -70,27 +52,26 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1712573573,
"narHash": "sha256-xxon7WwNm4/EadMKg1eF40/5s0O78nXUy2ILZt6vT7E=",
"lastModified": 1731366015,
"narHash": "sha256-GA5zH1o79bHZe1+EeeQ5rAnqIAa1OzG+kCkXayxPOfo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0d28066770464d19d637f6e8e42e8688420b6ac6",
"rev": "5763214382961a36a54f259bbf80485664b9664b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1706487304,
"narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=",
"lastModified": 1728538411,
"narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "90f456026d284c22b3e3497be980b2e47d0b28ac",
"rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221",
"type": "github"
},
"original": {
@ -110,15 +91,14 @@
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1712628742,
"narHash": "sha256-FIAlt8mbPUs8jRuh6xpFtYzDsyHzmiLNPcen8HwvD00=",
"lastModified": 1731292155,
"narHash": "sha256-fYVoUUtSadbOrH0z0epVQDsStBDS/S/fAK//0ECQAAI=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e7354bb9e5f68b2074e272fd5f5ac3f4848860ba",
"rev": "7c4cd99ed7604b79e8cb721099ac99c66f656b3a",
"type": "github"
},
"original": {
@ -141,21 +121,6 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View file

@ -3,16 +3,14 @@
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
rust-overlay.url = "github:oxalica/rust-overlay";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:NixOS/nixpkgs";
};
outputs = { self, flake-utils, naersk, nixpkgs, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = (import nixpkgs) {
inherit system overlays;
};
pkgs = (import nixpkgs) { inherit system overlays; };
naersk' = pkgs.callPackage naersk { };
buildInputs = with pkgs; [
vulkan-loader
@ -25,19 +23,15 @@
];
nativeBuildInputs = with pkgs; [
libxkbcommon
(rust-bin.selectLatestNightlyWith
(toolchain: toolchain.default.override {
extensions = [ "rust-src" "clippy" ];
(rust-bin.selectLatestNightlyWith (toolchain:
toolchain.default.override {
extensions = [ "rust-src" "clippy" "rust-analyzer"];
}))
];
all_deps = with pkgs; [
cargo-flamegraph
cargo-expand
nixpkgs-fmt
cmake
] ++ buildInputs ++ nativeBuildInputs;
in
rec {
all_deps = with pkgs;
[ cargo-flamegraph cargo-expand nixpkgs-fmt cmake ] ++ buildInputs
++ nativeBuildInputs;
in rec {
# For `nix build` & `nix run`:
defaultPackage = packages.bevy_template;
packages = rec {
@ -55,12 +49,14 @@
# For `nix develop`:
devShell = pkgs.mkShell {
inputsFrom = [ packages.bevy_template ];
nativeBuildInputs = all_deps;
shellHook = ''
export CARGO_MANIFEST_DIR=$(pwd)
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath all_deps}"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${
pkgs.lib.makeLibraryPath all_deps
}"
'';
};
}
);
});
}

View file

@ -1 +1,2 @@
tab_spaces = 2
max_width = 80

View file

@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.14.2"
common = { path = "../common" }

View file

@ -1,3 +1,9 @@
use bevy::{prelude::*, state::app::StatesPlugin};
use common::base_bevy_app;
#[bevy_main]
fn main() {
println!("Hello, world!");
base_bevy_app()
.add_plugins((MinimalPlugins, StatesPlugin))
.run();
}

View file

@ -1,6 +1,47 @@
use bevy::prelude::*;
use bevy::{
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
#[derive(Bundle)]
pub struct BoardBundle {}
pub fn setup_board() {}
pub fn setup_board(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let num_rows = 8;
let num_cols = 7;
let hex_size: f32 = 50.0;
let hex_space = 8.0;
let hex_left = 0.0f32;
let hex_bot = 0.0f32;
let hex_width = hex_size * 3.0f32.sqrt() / 2.0;
let hex_height = hex_size * 1.5 + 1.5 * hex_space / 3.0f32.sqrt();
for y in 0..num_rows {
for x in 0..num_cols {
// TODO: Can these be shared?
let hex = Mesh2dHandle(meshes.add(RegularPolygon::new(hex_size, 6)));
let material = materials.add(Color::linear_rgb(1.0, 1.0, 1.0));
// x-offset is half a hexagon
let x_offset = hex_width + hex_space / 2.0;
let x_trans = hex_left
+ x as f32 * (2.0 * hex_width)
+ (x - 1) as f32 * hex_space
+ if y % 2 == 0 { x_offset } else { 0.0 };
let y_trans = hex_bot + y as f32 * hex_height;
commands.spawn(MaterialMesh2dBundle {
mesh: hex,
material,
transform: Transform::from_xyz(x_trans, y_trans, 0.0),
..Default::default()
});
}
}
}

View file

@ -2,38 +2,28 @@
mod board;
mod champion;
mod shop;
use bevy::{
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_egui::EguiPlugin;
use common::state::GameState;
use common::{base_bevy_app, state::GameState};
use crate::board::setup_board;
use crate::shop::shop;
#[bevy_main]
fn main() {
App::new()
base_bevy_app()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.insert_resource(GameState::default())
.add_systems(Startup, (setup, setup_board))
.add_systems(Update, shop)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
let hex = Mesh2dHandle(meshes.add(RegularPolygon::new(50.0, 6)));
let material = materials.add(Color::linear_rgb(1.0, 1.0, 1.0));
commands.spawn(MaterialMesh2dBundle {
mesh: hex,
material,
..Default::default()
});
}

36
src/shop.rs Normal file
View file

@ -0,0 +1,36 @@
use bevy::prelude::*;
use bevy_egui::{
egui::{self, Align2},
EguiContexts,
};
#[derive(Default, Resource)]
struct UiState {
label: String,
value: f32,
inverted: bool,
egui_texture_handle: Option<egui::TextureHandle>,
is_window_open: bool,
}
pub fn shop(mut contexts: EguiContexts) {
let ctx = contexts.ctx_mut();
let mut open = true;
egui::Window::new("Shop")
.default_width(600.0)
.default_height(100.0)
.open(&mut open)
.anchor(Align2::CENTER_BOTTOM, (0.0, 0.0))
.show(ctx, |ui| {
ui.label("Hellosu!");
ui.end_row();
ui.button("First");
ui.button("Second");
ui.button("Third");
ui.button("Fourth");
ui.button("Fifth");
ui.end_row();
});
}