Skip to content

Commit

Permalink
refactor: Move Ability and stuff to game_logic::ability
Browse files Browse the repository at this point in the history
  • Loading branch information
futile committed Jul 24, 2024
1 parent 6ed4070 commit 12530f7
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 65 deletions.
2 changes: 2 additions & 0 deletions docs/notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Todos

## Next:
- [ ] Cast-Times for abilities

- [ ] Figure out what's next :) More complicated abilities? More units per side? AI/Enemy behavior :O?
- Cooldowns? Cast-Times? Icons for Slots/Abilities/Effects? :O

Expand Down
2 changes: 1 addition & 1 deletion src/abilities.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{ecs::system::SystemParam, prelude::*, utils::HashMap};

use crate::game_logic::{Ability, AbilityId};
use crate::game_logic::ability::{Ability, AbilityId};

pub mod needling_hex;
pub mod weapon_attack;
Expand Down
2 changes: 1 addition & 1 deletion src/abilities/needling_hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use bevy::prelude::*;
use super::AbilityCatalog;
use crate::{
game_logic::{
ability::{Ability, AbilityId, AbilitySlot},
commands::{CastAbility, CastAbilityInterface, GameCommand, GameCommandKind},
damage_resolution::{DamageInstance, DealDamage},
effects::{GameEffect, ReflectGameEffect, UniqueEffectInterface},
faction::Faction,
fight::FightInterface,
Ability, AbilityId, AbilitySlot,
},
utils::FiniteRepeatingTimer,
PerUpdateSet,
Expand Down
2 changes: 1 addition & 1 deletion src/abilities/weapon_attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use bevy::prelude::*;
use super::AbilityCatalog;
use crate::{
game_logic::{
ability::{Ability, AbilityId, AbilitySlot, AbilitySlotType},
commands::{CastAbility, CastAbilityInterface, GameCommand, GameCommandKind},
damage_resolution::{DamageInstance, DealDamage},
faction::Faction,
Ability, AbilityId, AbilitySlot, AbilitySlotType,
},
PerUpdateSet,
};
Expand Down
2 changes: 1 addition & 1 deletion src/fight_ui/render_fight_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use super::{render_effects::ReflectRenderGameEffectImmediate, FightWindow};
use crate::{
abilities::AbilityInterface,
game_logic::{
ability::{Ability, AbilitySlot},
commands::{self, CastAbilityInterface, GameCommand},
effects::{HasEffects, ReflectGameEffect},
faction::Faction,
fight::{Fight, FightInterface, FightResult, FightTime},
health::Health,
Ability, AbilitySlot,
},
utils::{egui_systems::run_ui_system, SplitDuration},
AbilitySlotType, HasAbilities, HasAbilitySlots,
Expand Down
68 changes: 10 additions & 58 deletions src/game_logic.rs
Original file line number Diff line number Diff line change
@@ -1,74 +1,26 @@
use std::borrow::Cow;

use bevy::prelude::*;

pub mod ability;
pub mod commands;
pub mod damage_resolution;
pub mod effects;
pub mod faction;
pub mod fight;
pub mod health;

#[derive(Debug, Component, Reflect)]
pub struct HasAbilitySlots {
pub holder: Entity,
}

#[derive(Debug, Component, Reflect)]
pub struct HasAbilities {
pub holder: Entity,
}

#[derive(Debug, Component, Reflect)]
pub struct AbilitySlot {
pub tpe: AbilitySlotType,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
pub enum AbilitySlotType {
WeaponAttack,
ShieldDefend,
}

#[derive(Component, Clone, Copy, Debug, PartialEq, Eq, Hash, Reflect)]
pub enum AbilityId {
Attack,
NeedlingHex,
}

#[derive(Debug, Clone, Reflect)]
pub struct Ability {
pub name: Cow<'static, str>,
pub id: AbilityId,
pub slot_type: Option<AbilitySlotType>,
pub description: Cow<'static, str>,
}

impl Ability {
pub fn can_use_slot(&self, selected_ability_slot: Option<&AbilitySlot>) -> bool {
match (self.slot_type, selected_ability_slot) {
(Some(self_tpe), Some(selected_slot)) => selected_slot.tpe == self_tpe,
(None, None) => true,
(Some(_), None) | (None, Some(_)) => false,
}
}
}

pub struct GameLogicPlugin;

impl Plugin for GameLogicPlugin {
fn build(&self, app: &mut App) {
// from https://github.com/jakobhellermann/bevy-inspector-egui/discussions/130
app.register_type::<HasAbilities>()
.register_type::<AbilityId>()
.register_type::<HasAbilitySlots>()
.add_plugins((
fight::FightPlugin,
faction::FactionPlugin,
effects::EffectsPlugin,
commands::CommandsPlugin,
damage_resolution::DamageResolutionPlugin,
health::HealthInterfacePlugin,
));
app.add_plugins((
ability::AbilityPlugin,
fight::FightPlugin,
faction::FactionPlugin,
effects::EffectsPlugin,
commands::CommandsPlugin,
damage_resolution::DamageResolutionPlugin,
health::HealthInterfacePlugin,
));
}
}
58 changes: 58 additions & 0 deletions src/game_logic/ability.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use std::borrow::Cow;

use bevy::prelude::*;

#[derive(Debug, Component, Reflect)]
pub struct HasAbilitySlots {
pub holder: Entity,
}

#[derive(Debug, Component, Reflect)]
pub struct HasAbilities {
pub holder: Entity,
}

#[derive(Debug, Component, Reflect)]
pub struct AbilitySlot {
pub tpe: AbilitySlotType,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
pub enum AbilitySlotType {
WeaponAttack,
ShieldDefend,
}

#[derive(Component, Clone, Copy, Debug, PartialEq, Eq, Hash, Reflect)]
pub enum AbilityId {
Attack,
NeedlingHex,
}

#[derive(Debug, Clone, Reflect)]
pub struct Ability {
pub name: Cow<'static, str>,
pub id: AbilityId,
pub slot_type: Option<AbilitySlotType>,
pub description: Cow<'static, str>,
}

impl Ability {
pub fn can_use_slot(&self, selected_ability_slot: Option<&AbilitySlot>) -> bool {
match (self.slot_type, selected_ability_slot) {
(Some(self_tpe), Some(selected_slot)) => selected_slot.tpe == self_tpe,
(None, None) => true,
(Some(_), None) | (None, Some(_)) => false,
}
}
}

pub struct AbilityPlugin;

impl Plugin for AbilityPlugin {
fn build(&self, app: &mut App) {
app.register_type::<HasAbilities>()
.register_type::<AbilityId>()
.register_type::<HasAbilitySlots>();
}
}
5 changes: 4 additions & 1 deletion src/game_logic/commands.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use bevy::{ecs::system::SystemParam, prelude::*};
use derive_more::From;

use super::{fight::FightInterface, AbilityId, AbilitySlot};
use super::{
ability::{AbilityId, AbilitySlot},
fight::FightInterface,
};
use crate::{abilities::AbilityInterface, game_logic::fight::FightStatus};

#[derive(Debug, Clone, Event)]
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use fight_ui::FightUiPlugin;
use game_logic::{
faction::Faction, fight::FightBundle, health::Health, AbilityId, AbilitySlot, AbilitySlotType,
GameLogicPlugin, HasAbilities, HasAbilitySlots,
ability::{AbilityId, AbilitySlot, AbilitySlotType, HasAbilities, HasAbilitySlots},
faction::Faction,
fight::FightBundle,
health::Health,
GameLogicPlugin,
};

pub mod abilities;
Expand Down

0 comments on commit 12530f7

Please sign in to comment.