Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 311285693c |
7 changed files with 1290 additions and 894 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;
|
||||
65
src/lib.rs
65
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()
|
||||
|
|
@ -51,7 +41,7 @@ pub fn test_setup_hand(
|
|||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
systems: Res<Systems>,
|
||||
query: Single<Entity, With<Hand>>
|
||||
query: Single<Entity, With<Hand>>,
|
||||
) {
|
||||
let hand_id = query.into_inner();
|
||||
for _ in 0..4 {
|
||||
|
|
@ -60,21 +50,26 @@ pub fn test_setup_hand(
|
|||
}
|
||||
|
||||
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((
|
||||
Card,
|
||||
TestProperty,
|
||||
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);
|
||||
let card = cmd
|
||||
.spawn((
|
||||
Card,
|
||||
AnimalProperty,
|
||||
Transform::from_xyz(0., 0., 0.),
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,10 +88,12 @@ pub fn update_hand_dimensions(
|
|||
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.;
|
||||
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; };
|
||||
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.));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use evolution_rs::{
|
||||
plugins::*,
|
||||
setup, test_setup_hand
|
||||
};
|
||||
|
||||
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_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