Skip to content

Commit

Permalink
#0 The Great refactoring (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat authored Feb 24, 2024
1 parent 2cd191e commit aab4ada
Show file tree
Hide file tree
Showing 73 changed files with 275 additions and 286 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/Characters/Common/Animations/TAnimation.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/Environment/Ball/BP_Ball.uasset
Binary file not shown.
Binary file modified Content/Game/BP_Cloud9Console.uasset
Binary file not shown.
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
Binary file modified Content/Modes/BP_Cloud9Campaign.uasset
Binary file not shown.
Binary file modified Content/Modes/BP_Cloud9DeathMatch.uasset
Binary file not shown.
Binary file modified Content/Modes/BP_Cloud9Default.uasset
Binary file not shown.
Binary file modified Content/Modes/BP_Cloud9Warmup.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/Widgets/HudWidget.uasset
Binary file not shown.
Binary file added Importing/tm_jungle_raider_variantb2_death.blend
Binary file not shown.
Binary file added Importing/tm_jungle_raider_variantb2_death.fbx
Binary file not shown.
34 changes: 25 additions & 9 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@
#include "Cloud9/Game/Cloud9DeveloperSettings.h"
#include "Cloud9/Contollers//Cloud9PlayerController.h"
#include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h"
#include "Cloud9/Character/Components/Cloud9Inventory.h"
#include "Components/Cloud9InventoryComponent.h"
#include "Cloud9/Character/Components/Cloud9CharacterMovement.h"
#include "Cloud9/Character/Components/Cloud9SpringArmComponent.h"
#include "Cloud9/Character/Components/Cloud9CharacterHealthComponent.h"
#include "Components/Cloud9HealthComponent.h"
#include "Components/Cloud9AnimationComponent.h"

const FName ACloud9Character::SpringArmComponentName = TEXT("CameraBoom");
const FName ACloud9Character::CameraComponentName = TEXT("TopDownCamera");
const FName ACloud9Character::DecalComponentName = TEXT("CursorToWorld");
const FName ACloud9Character::InventoryComponentName = TEXT("Inventory");
const FName ACloud9Character::InventoryComponentName = TEXT("InventoryComponent");
const FName ACloud9Character::HealthComponentName = TEXT("HealthComponent");
const FName ACloud9Character::AnimationComponentName = TEXT("AnimationComponent");

ACloud9Character::ACloud9Character(const FObjectInitializer& ObjectInitializer) : Super(
ObjectInitializer.SetDefaultSubobjectClass<UCloud9CharacterMovement>(CharacterMovementComponentName))
Expand Down Expand Up @@ -77,8 +79,11 @@ ACloud9Character::ACloud9Character(const FObjectInitializer& ObjectInitializer)
CursorToWorld = CreateDefaultSubobject<UDecalComponent>(DecalComponentName);
CursorToWorld->SetupAttachment(RootComponent);

Inventory = CreateDefaultSubobject<UCloud9Inventory>(InventoryComponentName);
HealthComponent = CreateDefaultSubobject<UCloud9CharacterHealthComponent>(HealthComponentName);
InventoryComponent = CreateDefaultSubobject<UCloud9InventoryComponent>(InventoryComponentName);
HealthComponent = CreateDefaultSubobject<UCloud9HealthComponent>(HealthComponentName);
AnimationComponent = CreateDefaultSubobject<UCloud9AnimationComponent>(AnimationComponentName);

// HealthComponent->OnCharacterDie.AddDynamic(this, &ACloud9Character::OnCharacterDie);

Score = 0;

Expand Down Expand Up @@ -231,9 +236,15 @@ void ACloud9Character::SetCameraZoomHeight(float Value) const
CameraBoom->TargetArmLength = Value;
}

UCloud9Inventory* ACloud9Character::GetInventory() const { return Inventory; }
UCloud9InventoryComponent* ACloud9Character::GetInventoryComponent() const { return InventoryComponent; }

UCloud9HealthComponent* ACloud9Character::GetHealthComponent() const { return HealthComponent; }

UCloud9CharacterHealthComponent* ACloud9Character::GetHealthComponent() const { return HealthComponent; }
UCloud9AnimationComponent* ACloud9Character::GetAnimationComponent() const
{
assertf(IsValid(AnimationComponent), "AnimationComponent isn't valid")
return AnimationComponent;
}

void ACloud9Character::AddScore()
{
Expand All @@ -246,6 +257,11 @@ void ACloud9Character::UseObject()
// TODO: Implement UseObject
}

void ACloud9Character::OnCharacterDie(AActor* Actor)
{
// AnimationComponent->PlayAnimMontage();
}

void ACloud9Character::OnConstruction(const FTransform& Transform)
{
Super::OnConstruction(Transform);
Expand Down Expand Up @@ -282,8 +298,8 @@ void ACloud9Character::Tick(float DeltaSeconds)
Super::Tick(DeltaSeconds);

// Auto select any available weapon if nothing selected
if (not Inventory->GetSelectedWeapon() and not Inventory->IsEmpty())
if (not InventoryComponent->GetSelectedWeapon() and not InventoryComponent->IsEmpty())
{
Inventory->SelectOtherAvailableWeapon(false);
InventoryComponent->SelectOtherAvailableWeapon(false);
}
}
35 changes: 25 additions & 10 deletions Source/Cloud9/Character/Cloud9Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
#include "CoreMinimal.h"
#include "GameFramework/Character.h"

#include "Components/Cloud9Inventory.h"
#include "Components/Cloud9CharacterMovement.h"

#include "Cloud9Character.generated.h"

class ACloud9PlayerController;
class UCloud9InventoryComponent;
class UCloud9AnimationComponent;

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnScoreChanged, int, Count);

class UCloud9CharacterHealthComponent;
class UCloud9HealthComponent;

UCLASS(config=Game, Blueprintable)
class ACloud9Character : public ACharacter
Expand All @@ -46,6 +49,7 @@ class ACloud9Character : public ACharacter
static const FName DecalComponentName;
static const FName InventoryComponentName;
static const FName HealthComponentName;
static const FName AnimationComponentName;

ACloud9Character(const FObjectInitializer& ObjectInitializer);

Expand Down Expand Up @@ -82,19 +86,30 @@ class ACloud9Character : public ACharacter
float GetCameraZoomHeight() const;
void SetCameraZoomHeight(float Value) const;

UCloud9Inventory* GetInventory() const;
UCloud9InventoryComponent* GetInventoryComponent() const;

UCloud9HealthComponent* GetHealthComponent() const;

UCloud9CharacterHealthComponent* GetHealthComponent() const;
UCloud9AnimationComponent* GetAnimationComponent() const;

void AddScore();

void UseObject();

public:
/** Event called when character score changed. */
UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnScoreChanged OnScoreChanged;

// Set by character movement to specify that this Character is currently sneaking.
// TODO: replicatedUsing=OnRep_IsSneaking
UPROPERTY(BlueprintReadOnly, Category=Character)
uint32 bIsSneaking : 1;

protected:
UFUNCTION(BlueprintCallable)
void OnCharacterDie(AActor* Actor);

protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
float ViewVerticalRotation;
Expand Down Expand Up @@ -122,17 +137,17 @@ class ACloud9Character : public ACharacter

/** An inventory of the character. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Inventory, meta=(AllowPrivateAccess))
UCloud9Inventory* Inventory;
UCloud9InventoryComponent* InventoryComponent;

/** A state of the character health and armor. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
UCloud9CharacterHealthComponent* HealthComponent;

/** Event called when character score changed. */
UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnScoreChanged OnScoreChanged;
UCloud9HealthComponent* HealthComponent;

/** Current number of frags made by character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
int Score;

/** Helper to play animation montages for character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Utility, meta=(AllowPrivateAccess))
UCloud9AnimationComponent* AnimationComponent;
};
69 changes: 69 additions & 0 deletions Source/Cloud9/Character/Components/Cloud9AnimationComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) 2024 Alexei Gladkikh

#include "Cloud9AnimationComponent.h"

#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Tools/Macro/Logging.h"

#include "Cloud9/Character/Cloud9Character.h"

UCloud9AnimationComponent::UCloud9AnimationComponent() {}

UAnimInstance* UCloud9AnimationComponent::GetAnimInstance() const
{
let Character = GetOwner<ACloud9Character>();

if (not IsValid(Character))
{
log(Error, "[Component='%s'] Character is invalid", *GetName());
return nullptr;
}

let Mesh = Character->GetMesh();

if (not IsValid(Mesh))
{
log(Error, "[Component='%s'] Mesh is invalid", *GetName());
return nullptr;
}

return Mesh->GetAnimInstance();
}

bool UCloud9AnimationComponent::PlayMontage(UAnimMontage* Montage, float StartTime, float Rate) const
{
if (not IsValid(Montage))
{
log(Error, "[Component='%s'] Montage is invalid", *GetName());
return false;
}

let AnimInstance = GetAnimInstance();

if (not IsValid(AnimInstance))
{
log(Error, "[Component='%s'] AnimInstance is invalid for montage '%s'", *GetName(), *Montage->GetName());
return false;
}

if (not AnimInstance->Montage_Play(Montage, Rate, EMontagePlayReturnType::MontageLength, StartTime))
{
log(Error, "[Component='%s'] Can't play montage '%s'", *GetName(), *Montage->GetName());
return false;
}

return true;
}

bool UCloud9AnimationComponent::IsAnyMontagePlaying() const
{
let AnimInstance = GetAnimInstance();

if (not IsValid(AnimInstance))
{
log(Error, "[Component='%s'] AnimInstance is invalid", *GetName());
return false;
}

return AnimInstance->IsAnyMontagePlaying();
}
24 changes: 24 additions & 0 deletions Source/Cloud9/Character/Components/Cloud9AnimationComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024 Alexei Gladkikh

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Cloud9AnimationComponent.generated.h"

class ACloud9Character;

UCLASS(Blueprintable)
class CLOUD9_API UCloud9AnimationComponent : public UActorComponent
{
GENERATED_BODY()

public:
UCloud9AnimationComponent();

UAnimInstance* GetAnimInstance() const;

bool PlayMontage(UAnimMontage* Montage, float StartTime = 0.0f, float Rate = 1.0f) const;

bool IsAnyMontagePlaying() const;
};
48 changes: 0 additions & 48 deletions Source/Cloud9/Character/Components/Cloud9CharacterComponent.cpp

This file was deleted.

48 changes: 0 additions & 48 deletions Source/Cloud9/Character/Components/Cloud9CharacterComponent.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// OTHER DEALINGS IN THE SOFTWARE.

#include "Cloud9CharacterMovement.h"
#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Character/Cloud9Character.h"

UCloud9CharacterMovement::UCloud9CharacterMovement()
Expand Down
6 changes: 1 addition & 5 deletions Source/Cloud9/Character/Components/Cloud9CharacterMovement.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@
#include "CoreMinimal.h"
#include "GameFramework/CharacterMovementComponent.h"

#include "Cloud9/Character/Components/Cloud9CharacterComponent.h"

#include "Cloud9CharacterMovement.generated.h"

class ACloud9Character;

UCLASS(Blueprintable)
class CLOUD9_API UCloud9CharacterMovement
: public UCharacterMovementComponent
, public ICloud9CharacterComponent
class CLOUD9_API UCloud9CharacterMovement : public UCharacterMovementComponent
{
GENERATED_BODY()

Expand Down
Loading

0 comments on commit aab4ada

Please sign in to comment.