69 lines
1.6 KiB
C++
69 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "authority/macros.h"
|
|
#include "core/io/resource.h"
|
|
#include "core/templates/hash_set.h"
|
|
#include "scene/3d/physics/character_body_3d.h"
|
|
|
|
class CharacterData : public Resource {
|
|
GDCLASS(CharacterData, Resource);
|
|
static void _bind_methods();
|
|
|
|
private:
|
|
float speed{};
|
|
|
|
public:
|
|
GET_SET_FNS(float, speed);
|
|
};
|
|
|
|
class Character : public CharacterBody3D {
|
|
GDCLASS(Character, CharacterBody3D);
|
|
|
|
protected:
|
|
static void _bind_methods();
|
|
void physics_process(double delta);
|
|
void _notification(int what);
|
|
PackedStringArray get_configuration_warnings() const override;
|
|
|
|
public:
|
|
void set_movement(Vector2 movement);
|
|
bool is_moving() const;
|
|
|
|
private:
|
|
Ref<CharacterData> data{};
|
|
Vector2 world_movement_direction{};
|
|
|
|
public:
|
|
GET_SET_FNS(Ref<CharacterData>, data);
|
|
};
|
|
|
|
class CharacterState : public Node {
|
|
GDCLASS(CharacterState, Node);
|
|
static void _bind_methods();
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
PackedStringArray get_configuration_warnings() const override;
|
|
void switch_to_state(String state);
|
|
void stack_state_dependent(String state);
|
|
void notify_dependent_inactive(CharacterState *dependent);
|
|
void stack_state_independent(String state);
|
|
virtual void state_entered() {}
|
|
virtual void state_exited() {}
|
|
|
|
public:
|
|
void set_state_active(bool active);
|
|
bool get_state_active() const;
|
|
Character *get_character() const;
|
|
|
|
private:
|
|
bool start_active{ false };
|
|
bool state_active{ false };
|
|
|
|
Character *character{ nullptr };
|
|
HashSet<CharacterState *> dependent_states{};
|
|
CharacterState *depending_state{ nullptr };
|
|
|
|
public:
|
|
GET_SET_FNS(bool, start_active);
|
|
};
|