1
0
Fork 0

Migrated to bevy 0.17, deleted traits in favor of built-in bevy

structures
This commit is contained in:
Rendo 2025-11-18 20:38:08 +05:00
commit 311285693c
7 changed files with 1290 additions and 894 deletions

2054
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,13 @@
cargo-features = ["codegen-backend"]
[package] [package]
name = "evolution-rs" name = "evolution-rs"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2024"
[dependencies] [dependencies]
bevy = { version = "0.15.2", features = ["dynamic_linking", "wayland"] } bevy = "0.17.3"
bevy-trait-query = "0.7.0"
log = { version = "*", features = ["max_level_debug", "release_max_level_warn"] }
[profile.dev] [profile.dev]
opt-level = 1 opt-level = 1
codegen-backend = "cranelift"
[profile.dev.package."*"] [profile.dev.package."*"]
opt-level = 3 opt-level = 3
codegen-backend = "llvm"

View file

@ -0,0 +1,4 @@
use bevy::prelude::Component;
#[derive(Component)]
pub struct AnimalProperty;

View file

@ -1,17 +1,10 @@
use bevy::{ use crate::{animal_properties::AnimalProperty, card::Card, hand::Hand};
ecs::system::SystemId, use bevy::{ecs::system::SystemId, prelude::*};
prelude::*
};
use crate::{
card::Card,
hand::Hand,
properties::TestProperty
};
pub mod animal;
pub mod animal_properties;
pub mod card; pub mod card;
pub mod hand; pub mod hand;
pub mod animal;
pub mod properties;
pub mod plugins; pub mod plugins;
#[derive(Component)] #[derive(Component)]
@ -19,16 +12,13 @@ pub struct JustUpdated;
#[derive(Resource)] #[derive(Resource)]
pub struct Systems { pub struct Systems {
pub update_hand_dimensions: SystemId pub update_hand_dimensions: SystemId,
} }
pub fn setup( pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
let updhd_id = commands.register_system(update_hand_dimensions); let updhd_id = commands.register_system(update_hand_dimensions);
commands.insert_resource(Systems { commands.insert_resource(Systems {
update_hand_dimensions: updhd_id update_hand_dimensions: updhd_id,
}); });
commands.spawn(Camera2d); commands.spawn(Camera2d);
commands.spawn(( commands.spawn((
@ -37,7 +27,7 @@ pub fn setup(
Sprite { Sprite {
image: asset_server.load("sprites/hand_9s.png"), image: asset_server.load("sprites/hand_9s.png"),
image_mode: SpriteImageMode::Sliced(TextureSlicer { image_mode: SpriteImageMode::Sliced(TextureSlicer {
border: BorderRect::square(4.), border: BorderRect::all(4.),
center_scale_mode: SliceScaleMode::Stretch, center_scale_mode: SliceScaleMode::Stretch,
sides_scale_mode: SliceScaleMode::Stretch, sides_scale_mode: SliceScaleMode::Stretch,
..default() ..default()
@ -51,7 +41,7 @@ pub fn test_setup_hand(
mut commands: Commands, mut commands: Commands,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
systems: Res<Systems>, systems: Res<Systems>,
query: Single<Entity, With<Hand>> query: Single<Entity, With<Hand>>,
) { ) {
let hand_id = query.into_inner(); let hand_id = query.into_inner();
for _ in 0..4 { for _ in 0..4 {
@ -60,21 +50,26 @@ pub fn test_setup_hand(
} }
pub fn create_card( pub fn create_card(
commands: &mut Commands, cmd: &mut Commands,
asset_server: &Res<AssetServer>, asset_server: &Res<AssetServer>,
hand_entity: Option<Entity>, hand_entity: Option<Entity>,
systems: &Res<Systems> systems: &Res<Systems>,
) { ) {
let mut card = commands.spawn(( let card = cmd
Card, .spawn((
TestProperty, Card,
Transform::from_xyz(0., 0., 0.), AnimalProperty,
Sprite::from_image(asset_server.load("sprites/card_back_placeholder.png")) Transform::from_xyz(0., 0., 0.),
)); Sprite::from_image(asset_server.load("sprites/card_back_placeholder.png")),
if let Some(hand) = hand_entity { ))
card.set_parent(hand); .id();
commands.entity(hand).insert(JustUpdated);
commands.run_system(systems.update_hand_dimensions); if let Some(hand) = hand_entity
&& let Ok(mut hand_commands) = cmd.get_entity(hand)
{
hand_commands.add_child(card);
hand_commands.insert(JustUpdated);
cmd.run_system(systems.update_hand_dimensions);
} }
} }
@ -93,10 +88,12 @@ pub fn update_hand_dimensions(
let sprite_size = CARD_SPRITE_SIZE; let sprite_size = CARD_SPRITE_SIZE;
let hand_total_width = (sprite_size.x + hor_margin) * (size as f32); let hand_total_width = (sprite_size.x + hor_margin) * (size as f32);
let hand_height = ver_margin * 2. + sprite_size.y; let hand_height = ver_margin * 2. + sprite_size.y;
let hand_offset = (hand_total_width - sprite_size.x - hor_margin) / 2.; let hand_offset = (hand_total_width - sprite_size.x - hor_margin) / 2.;
for (index, &child_id) in hand.2.iter().enumerate() { for (index, child_id) in hand.2.iter().enumerate() {
let Ok(mut child) = c_query.get_mut(child_id) else { continue; }; let Ok(mut child) = c_query.get_mut(child_id) else {
continue;
};
let offset_x = (sprite_size.x + hor_margin) * (index as f32) - hand_offset; let offset_x = (sprite_size.x + hor_margin) * (index as f32) - hand_offset;
let offset_y = 0.; let offset_y = 0.;
child.0.translation = Vec3::from((Vec2::new(offset_x, offset_y), 1.)); child.0.translation = Vec3::from((Vec2::new(offset_x, offset_y), 1.));

View file

@ -1,10 +1,6 @@
use bevy::prelude::*; use bevy::prelude::*;
use evolution_rs::{ use evolution_rs::{plugins::*, setup, test_setup_hand};
plugins::*,
setup, test_setup_hand
};
// Надо придумать способ подгружать все ассеты, а затем уже исполнять программу // Надо придумать способ подгружать все ассеты, а затем уже исполнять программу
// Суть в том, что есть AssetServer::wait_for_asset(handle), который возвращает Future, то есть ассинхронное вычисление или типо того // Суть в том, что есть AssetServer::wait_for_asset(handle), который возвращает Future, то есть ассинхронное вычисление или типо того
@ -16,7 +12,7 @@ use evolution_rs::{
// P.S. оставляю комменты в коде, потому что так надёжнее, чем сообщениями, которые можно потерять // P.S. оставляю комменты в коде, потому что так надёжнее, чем сообщениями, которые можно потерять
fn main() { fn main() {
App::new() App::new()
.add_plugins((DefaultPlugins,BasePropertiesPlugin)) .add_plugins(DefaultPlugins)
.add_systems(Startup, (setup, test_setup_hand).chain()) .add_systems(Startup, (setup, test_setup_hand).chain())
.run(); .run();
} }

View file

@ -1,19 +1 @@
use bevy::prelude::{App,Plugin};
use crate::properties::{Property, TestProperty};
pub struct BasePropertiesPlugin;
impl Plugin for BasePropertiesPlugin
{
fn build(&self, app: &mut App) {
// Моды должны будут делать кастомный плагин и подгружать его при загрузке мода
use bevy_trait_query::RegisterExt;
app
.register_component_as::<dyn Property, TestProperty>();
//.add_systems(schedule, <ЗДЕСЬ ДОЛЖНА БЫТЬ СИСТЕМА ДЛЯ УСЛОВИЯ>)
//.add_systems(schedule, <ЗДЕСЬ ДОЛЖНА БЫТЬ СИСТЕМА ДЛЯ ТРИГГЕРА);
}
}

View file

@ -1,25 +0,0 @@
use bevy_trait_query;
use bevy::prelude::Component;
// Базовый трейт для свойства животного
// Интересно, будет ли участвовать в моддинге
#[bevy_trait_query::queryable]
pub trait Property{
fn check_condition(self : &Self) -> bool;
fn trigger(self : &Self);
}
#[derive(Component)]
pub struct TestProperty;
impl Property for TestProperty
{
fn check_condition(self: &Self) -> bool {
false
}
fn trigger(self: &Self) {
println!("Testing property!");
}
}