diff --git a/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.cpp b/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.cpp index 211a179..2fe2caa 100644 --- a/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.cpp +++ b/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.cpp @@ -1,2 +1,18 @@ #include "ParkourPlayerController.h" +#include "../MiniGame/MiniGameManager.h" +#include "../Utils/SingletonHelper.h" + +bool AParkourPlayerController::StartGame_Validate(TSubclassOf GameClass) +{ + return true; +} + +void AParkourPlayerController::StartGame_Implementation(TSubclassOf GameClass) +{ + AMiniGameManager* Mgr = FSingletonHelper::Static_GetSingletonObject(GetWorld()); + + if (!Mgr) return; + + Mgr->CreateGame(GameClass); +} \ No newline at end of file diff --git a/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.h b/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.h index 48d3bcb..41200d5 100644 --- a/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.h +++ b/ParkourGame/Source/ParkourGame/Private/Core/ParkourPlayerController.h @@ -4,8 +4,17 @@ #include "GameFramework/PlayerController.h" #include "ParkourPlayerController.generated.h" +class AMiniGameBase; + UCLASS() class AParkourPlayerController : public APlayerController { GENERATED_BODY() + +public: + + // Spectator Broadcast Functions + // (have to be here as spectators have no net role in a build) + UFUNCTION(Server, Unreliable, WithValidation) + void StartGame(TSubclassOf GameClass); }; diff --git a/ParkourGame/Source/ParkourGame/Private/MiniGame/MiniGameManager.cpp b/ParkourGame/Source/ParkourGame/Private/MiniGame/MiniGameManager.cpp index 13cfc05..4c682aa 100644 --- a/ParkourGame/Source/ParkourGame/Private/MiniGame/MiniGameManager.cpp +++ b/ParkourGame/Source/ParkourGame/Private/MiniGame/MiniGameManager.cpp @@ -38,7 +38,7 @@ void AMiniGameManager::BeginPlay() if(!HasAuthority()) OnGameOver.AddDynamic(this, &AMiniGameManager::OnGameEnded); - //SetNextGameTimer(); + SetNextGameTimer(); } void AMiniGameManager::CreateRandomGame() @@ -138,7 +138,7 @@ void AMiniGameManager::SetNextGameTimer() if (!HasAuthority()) return; - GetWorld()->GetTimerManager().SetTimer(NextGameTimer, this, &AMiniGameManager::CreateRandomGame, GameCreationInterval); + //GetWorld()->GetTimerManager().SetTimer(NextGameTimer, this, &AMiniGameManager::CreateRandomGame, GameCreationInterval); } void AMiniGameManager::OnGameEnded(AMiniGameBase* Game, EMiniGameEndReason Reason) diff --git a/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.cpp b/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.cpp index 1264ce2..a82c862 100644 --- a/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.cpp +++ b/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.cpp @@ -13,7 +13,14 @@ static void cmd_OpenMenu(UWorld* World) { APlayerController* PlayerCtlr = World->GetFirstPlayerController(); - AParkourSpectator* PlayerCharacter = PlayerCtlr ? Cast(PlayerCtlr->GetPawn()) : nullptr; + + // If we have become a pawn using the console command then we use GetPawn, otherwise we need to use spectator pawn + AParkourSpectator* PlayerCharacter = PlayerCtlr ? Cast(PlayerCtlr->GetSpectatorPawn()) : nullptr; + +#if WITH_EDITOR + if(!PlayerCharacter) + PlayerCharacter = Cast(PlayerCtlr->GetPawn()); +#endif if (!IsValid(PlayerCharacter)) return; @@ -78,18 +85,12 @@ void AParkourSpectator::BeginAutoCam() TargetRandomPlayer(); } -bool AParkourSpectator::StartGame_Validate(TSubclassOf GameClass) -{ - return true; -} - -void AParkourSpectator::StartGame_Implementation(TSubclassOf GameClass) +void AParkourSpectator::StartGame(TSubclassOf GameClass) { - AMiniGameManager* Mgr = FSingletonHelper::Static_GetSingletonObject(GetWorld()); - - if (!Mgr) return; + AParkourPlayerController* Controller = Cast(GetController()); - Mgr->CreateGame(GameClass); + if (Controller) + Controller->StartGame(GameClass); } void AParkourSpectator::OpenControls() diff --git a/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.h b/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.h index f0a0e00..a260a70 100644 --- a/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.h +++ b/ParkourGame/Source/ParkourGame/Private/Spectator/ParkourSpectator.h @@ -32,7 +32,7 @@ class AParkourSpectator : public ASpectatorPawn UFUNCTION(BlueprintCallable, Category = "ParkourSpectator") void BeginAutoCam(); - UFUNCTION(BlueprintCallable, Category = "ParkourSpectator", Server, Unreliable, WithValidation) + UFUNCTION(BlueprintCallable, Category = "ParkourSpectator") void StartGame(TSubclassOf GameClass); void OpenControls(); diff --git a/ParkourGame/Source/ParkourGame/Private/Utils/GameVersion.h b/ParkourGame/Source/ParkourGame/Private/Utils/GameVersion.h index 756d1d0..b3d382b 100644 --- a/ParkourGame/Source/ParkourGame/Private/Utils/GameVersion.h +++ b/ParkourGame/Source/ParkourGame/Private/Utils/GameVersion.h @@ -5,8 +5,8 @@ #include "GameVersion.generated.h" #define GAME_VERSION_MAJOR 0 -#define GAME_VERSION_MINOR 6 -#define GAME_VERSION_PATCH 0 +#define GAME_VERSION_MINOR 7 +#define GAME_VERSION_PATCH 1 USTRUCT(BlueprintType) struct FGameVersion