Skip to content

Commit

Permalink
Separate sprite and entity animations
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenbanck committed Dec 28, 2024
1 parent f61cb4d commit 51f2ea4
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 284 deletions.
5 changes: 3 additions & 2 deletions korangar/src/input/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::graphics::Texture;
use crate::interface::application::InterfaceSettings;
use crate::interface::resource::{ItemSource, SkillSource};
use crate::inventory::Skill;
use crate::loaders::{Actions, AnimationState, ResourceMetadata, Sprite};
use crate::loaders::{ResourceMetadata, Sprite};
use crate::world::{Actions, SpriteAnimationState};

#[derive(Default)]
pub enum MouseInputMode {
Expand All @@ -27,7 +28,7 @@ pub enum MouseInputMode {

pub enum Grabbed {
Texture(Arc<Texture>),
Action(Arc<Sprite>, Arc<Actions>, AnimationState),
Action(Arc<Sprite>, Arc<Actions>, SpriteAnimationState),
}

impl MouseInputMode {
Expand Down
59 changes: 28 additions & 31 deletions korangar/src/interface/cursor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ use super::application::InterfaceSettings;
use super::layout::{ScreenClip, ScreenPosition, ScreenSize};
use crate::graphics::Color;
use crate::input::Grabbed;
use crate::loaders::{ActionLoader, Actions, AnimationState, Sprite, SpriteLoader};
use crate::loaders::{ActionLoader, Sprite, SpriteLoader};
use crate::renderer::{GameInterfaceRenderer, SpriteRenderer};
use crate::world::{Actions, SpriteAnimationState};

#[allow(dead_code)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum MouseCursorState {
Default,
Dialog,
Click,
Unsure0,
RotateCamera,
Attack,
Attack1,
Warp,
NoAction,
Grab,
Unsure1,
Unsure2,
WarpFast,
Unsure3,
Default = 0,
Dialog = 1,
Click = 2,
Unsure0 = 3,
RotateCamera = 4,
Attack = 5,
Attack1 = 6,
Warp = 7,
NoAction = 8,
Grab = 9,
Unsure1 = 10,
Unsure2 = 11,
WarpFast = 12,
Unsure3 = 13,
}

impl From<MouseCursorState> for usize {
Expand All @@ -38,20 +39,22 @@ impl From<MouseCursorState> for usize {
pub struct MouseCursor {
sprite: Arc<Sprite>,
actions: Arc<Actions>,
animation_state: AnimationState<MouseCursorState>,
cursor_state: MouseCursorState,
animation_state: SpriteAnimationState,
shown: bool,
}

impl MouseCursor {
pub fn new(sprite_loader: &mut SpriteLoader, action_loader: &mut ActionLoader) -> Self {
let sprite = sprite_loader.get("cursors.spr").unwrap();
let actions = action_loader.get("cursors.act").unwrap();
let animation_state = AnimationState::new(MouseCursorState::Default, ClientTick(0));
let animation_state = SpriteAnimationState::new(ClientTick(0));
let shown = true;

Self {
sprite,
actions,
cursor_state: MouseCursorState::Default,
animation_state,
shown,
}
Expand All @@ -69,18 +72,12 @@ impl MouseCursor {
self.animation_state.update(client_tick);
}

// TODO: this is just a workaround until i find a better solution to make the
// cursor always look correct.
pub fn set_start_time(&mut self, client_tick: ClientTick) {
self.animation_state.start_time = client_tick;
}

pub fn set_state(&mut self, state: MouseCursorState, client_tick: ClientTick) {
if self.animation_state.action != state {
if self.cursor_state != state {
self.cursor_state = state;
self.animation_state.action_base_offset = usize::from(self.cursor_state);
self.animation_state.start_time = client_tick;
}

self.animation_state.action = state;
}

#[cfg_attr(feature = "debug", korangar_debug::profile("render mouse cursor"))]
Expand All @@ -106,7 +103,7 @@ impl MouseCursor {
Color::WHITE,
false,
),
Grabbed::Action(sprite, actions, animation_state) => actions.render(
Grabbed::Action(sprite, actions, animation_state) => actions.render_sprite(
renderer,
&sprite,
&animation_state,
Expand All @@ -118,13 +115,13 @@ impl MouseCursor {
}
}

// TODO: figure out how this is actually supposed to work
let direction = match self.animation_state.action {
// TODO: Figure out how this is actually supposed to work
let direction = match self.cursor_state {
MouseCursorState::Default | MouseCursorState::Click | MouseCursorState::RotateCamera => 0,
_ => 7,
};

self.actions.render(
self.actions.render_sprite(
renderer,
&self.sprite,
&self.animation_state,
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/elements/miscellanious/skill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Element<InterfaceSettings> for SkillBox {
renderer.render_background(CornerRadius::uniform(5.0), background_color);

if let Some(skill) = &self.skill {
skill.actions.render(
skill.actions.render_sprite(
renderer.renderer,
&skill.sprite,
&skill.animation_state,
Expand Down
16 changes: 11 additions & 5 deletions korangar/src/inventory/skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::sync::Arc;
use korangar_interface::state::{PlainRemote, PlainTrackedState, TrackedState};
use ragnarok_packets::{ClientTick, SkillId, SkillInformation, SkillLevel, SkillType};

use crate::loaders::{ActionLoader, ActionType, Actions, AnimationState, Sprite, SpriteLoader};
use crate::loaders::{ActionLoader, Sprite, SpriteLoader};
use crate::world::{Actions, SpriteAnimationState};

#[derive(Clone, Debug)]
pub struct Skill {
Expand All @@ -13,7 +14,7 @@ pub struct Skill {
pub skill_name: String,
pub sprite: Arc<Sprite>,
pub actions: Arc<Actions>,
pub animation_state: AnimationState,
pub animation_state: SpriteAnimationState,
}

#[derive(Default)]
Expand All @@ -22,7 +23,13 @@ pub struct SkillTree {
}

impl SkillTree {
pub fn fill(&mut self, sprite_loader: &mut SpriteLoader, action_loader: &mut ActionLoader, skill_data: Vec<SkillInformation>) {
pub fn fill(
&mut self,
sprite_loader: &mut SpriteLoader,
action_loader: &mut ActionLoader,
skill_data: Vec<SkillInformation>,
client_tick: ClientTick,
) {
let skills = skill_data
.into_iter()
.map(|skill_data| {
Expand All @@ -37,8 +44,7 @@ impl SkillTree {
skill_name: skill_data.skill_name,
sprite,
actions,
// FIX: give correct client tick
animation_state: AnimationState::new(ActionType::Idle, ClientTick(0)),
animation_state: SpriteAnimationState::new(client_tick),
}
})
.collect();
Expand Down
Loading

0 comments on commit 51f2ea4

Please sign in to comment.