forked from 2ndbeam/evolution-rs
Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 311285693c | |||
| 0319cb5a0e |
7 changed files with 1306 additions and 907 deletions
2054
Cargo.lock
generated
2054
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
10
Cargo.toml
10
Cargo.toml
|
|
@ -1,19 +1,13 @@
|
|||
cargo-features = ["codegen-backend"]
|
||||
|
||||
[package]
|
||||
name = "evolution-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = { version = "0.15.2", features = ["dynamic_linking", "wayland"] }
|
||||
bevy-trait-query = "0.7.0"
|
||||
log = { version = "*", features = ["max_level_debug", "release_max_level_warn"] }
|
||||
bevy = "0.17.3"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
codegen-backend = "cranelift"
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
codegen-backend = "llvm"
|
||||
|
|
|
|||
4
src/animal_properties/mod.rs
Normal file
4
src/animal_properties/mod.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
use bevy::prelude::Component;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct AnimalProperty;
|
||||
88
src/lib.rs
88
src/lib.rs
|
|
@ -1,17 +1,10 @@
|
|||
use bevy::{
|
||||
ecs::system::SystemId,
|
||||
prelude::*
|
||||
};
|
||||
use crate::{
|
||||
card::Card,
|
||||
hand::Hand,
|
||||
properties::TestProperty
|
||||
};
|
||||
use crate::{animal_properties::AnimalProperty, card::Card, hand::Hand};
|
||||
use bevy::{ecs::system::SystemId, prelude::*};
|
||||
|
||||
pub mod animal;
|
||||
pub mod animal_properties;
|
||||
pub mod card;
|
||||
pub mod hand;
|
||||
pub mod animal;
|
||||
pub mod properties;
|
||||
pub mod plugins;
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
@ -19,16 +12,13 @@ pub struct JustUpdated;
|
|||
|
||||
#[derive(Resource)]
|
||||
pub struct Systems {
|
||||
pub update_hand_dimensions: SystemId
|
||||
pub update_hand_dimensions: SystemId,
|
||||
}
|
||||
|
||||
pub fn setup(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
let updhd_id = commands.register_system(update_hand_dimensions);
|
||||
commands.insert_resource(Systems {
|
||||
update_hand_dimensions: updhd_id
|
||||
update_hand_dimensions: updhd_id,
|
||||
});
|
||||
commands.spawn(Camera2d);
|
||||
commands.spawn((
|
||||
|
|
@ -37,7 +27,7 @@ pub fn setup(
|
|||
Sprite {
|
||||
image: asset_server.load("sprites/hand_9s.png"),
|
||||
image_mode: SpriteImageMode::Sliced(TextureSlicer {
|
||||
border: BorderRect::square(4.),
|
||||
border: BorderRect::all(4.),
|
||||
center_scale_mode: SliceScaleMode::Stretch,
|
||||
sides_scale_mode: SliceScaleMode::Stretch,
|
||||
..default()
|
||||
|
|
@ -50,53 +40,63 @@ pub fn setup(
|
|||
pub fn test_setup_hand(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
//systems: Res<Systems>,
|
||||
query: Single<Entity, With<Hand>>
|
||||
systems: Res<Systems>,
|
||||
query: Single<Entity, With<Hand>>,
|
||||
) {
|
||||
let hand_id = query.into_inner();
|
||||
for _ in 0..4 {
|
||||
create_card(&mut commands, &asset_server, Some(hand_id));
|
||||
create_card(&mut commands, &asset_server, Some(hand_id), &systems);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_card(
|
||||
commands: &mut Commands,
|
||||
cmd: &mut Commands,
|
||||
asset_server: &Res<AssetServer>,
|
||||
hand_entity: Option<Entity>,
|
||||
//systems: &Res<Systems>
|
||||
systems: &Res<Systems>,
|
||||
) {
|
||||
let mut card = commands.spawn((
|
||||
let card = cmd
|
||||
.spawn((
|
||||
Card,
|
||||
TestProperty,
|
||||
AnimalProperty,
|
||||
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);
|
||||
commands.entity(hand).insert(JustUpdated);
|
||||
//commands.run_system(systems.update_hand_dimensions);
|
||||
Sprite::from_image(asset_server.load("sprites/card_back_placeholder.png")),
|
||||
))
|
||||
.id();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: replace this const with getting asset dimensions from Assets<Image>
|
||||
const CARD_SPRITE_SIZE: Vec2 = Vec2::new(128., 192.);
|
||||
|
||||
pub fn update_hand_dimensions(
|
||||
mut commands: Commands,
|
||||
p_query: Single<(Entity, &mut Sprite, &Children), (Added<JustUpdated>, With<Hand>)>,
|
||||
mut c_query: Query<(&mut Transform, &Sprite), (With<Card>, Without<Hand>)>,
|
||||
assets: Res<Assets<Image>>
|
||||
) {
|
||||
let mut hand = p_query.into_inner();
|
||||
let mut counter = 0.;
|
||||
let mut hand_total_width = 0.;
|
||||
let mut hand_height = 0.;
|
||||
for &child_id in hand.2.iter() {
|
||||
let Ok(mut child) = c_query.get_mut(child_id) else { continue; };
|
||||
let sprite_size = assets.get(child.1.image.id()).unwrap().size_f32();
|
||||
let hor_margin = Vec2::new(4., 0.);
|
||||
let ver_margin = Vec2::new(0., 4.);
|
||||
hand_total_width += sprite_size.x + hor_margin.x;
|
||||
hand_height = sprite_size.y + ver_margin.y * 2.;
|
||||
child.0.translation = Vec3::from((ver_margin + (sprite_size + hor_margin) * counter, 0.));
|
||||
counter += 1.;
|
||||
let size = hand.2.iter().count();
|
||||
let hor_margin = 8.;
|
||||
let ver_margin = 8.;
|
||||
let sprite_size = CARD_SPRITE_SIZE;
|
||||
let hand_total_width = (sprite_size.x + hor_margin) * (size as f32);
|
||||
let hand_height = ver_margin * 2. + sprite_size.y;
|
||||
let hand_offset = (hand_total_width - sprite_size.x - hor_margin) / 2.;
|
||||
|
||||
for (index, child_id) in hand.2.iter().enumerate() {
|
||||
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_y = 0.;
|
||||
child.0.translation = Vec3::from((Vec2::new(offset_x, offset_y), 1.));
|
||||
}
|
||||
hand.1.custom_size = Some(Vec2::new(hand_total_width, hand_height));
|
||||
commands.entity(hand.0).remove::<JustUpdated>();
|
||||
|
|
|
|||
10
src/main.rs
10
src/main.rs
|
|
@ -1,10 +1,6 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use evolution_rs::{
|
||||
plugins::*,
|
||||
setup, test_setup_hand, update_hand_dimensions
|
||||
};
|
||||
|
||||
use evolution_rs::{plugins::*, setup, test_setup_hand};
|
||||
|
||||
// Надо придумать способ подгружать все ассеты, а затем уже исполнять программу
|
||||
// Суть в том, что есть AssetServer::wait_for_asset(handle), который возвращает Future, то есть ассинхронное вычисление или типо того
|
||||
|
|
@ -16,7 +12,7 @@ use evolution_rs::{
|
|||
// P.S. оставляю комменты в коде, потому что так надёжнее, чем сообщениями, которые можно потерять
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((DefaultPlugins,BasePropertiesPlugin))
|
||||
.add_systems(Startup, (setup, test_setup_hand, update_hand_dimensions).chain())
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_systems(Startup, (setup, test_setup_hand).chain())
|
||||
.run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, <ЗДЕСЬ ДОЛЖНА БЫТЬ СИСТЕМА ДЛЯ ТРИГГЕРА);
|
||||
}
|
||||
}
|
||||
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue