SkyPortal-plugin/Source/SkyPortal/Public/SkyPortalSubsystem.h

166 lines
4.2 KiB
C
Raw Normal View History

2024-09-18 13:30:30 +00:00
#pragma once
#include "Subsystems/EngineSubsystem.h"
2024-09-24 22:17:52 +00:00
#include "SkyPortalRunner.h"
2024-09-19 12:03:16 +00:00
2024-09-18 13:30:30 +00:00
#include "SkyPortalSubsystem.generated.h"
2024-09-22 21:58:01 +00:00
#pragma region Definitions
2024-09-19 12:03:16 +00:00
2024-09-21 22:01:15 +00:00
UENUM(BlueprintType)
enum EPortalSide {
LEFT UMETA(DisplayName = "Left side"),
RIGHT UMETA(DisplayName = "Right side"),
BOTH UMETA(DisplayName = "Both left and right"),
TRAP UMETA(DisplayName = "Trap")
};
2024-09-22 21:58:01 +00:00
UENUM(BlueprintType)
enum EPortalCommand {
A UMETA(DisplayName = "Activate"),
C UMETA(DisplayName = "Color"),
J UMETA(DisplayName = "Advanced color"),
L UMETA(DisplayName = "Trap color"),
M UMETA(DisplayName = "Music"),
Q UMETA(DisplayName = "Query"),
R UMETA(DisplayName = "Ready"),
S UMETA(DisplayName = "Status")
};
2024-09-23 13:48:29 +00:00
2024-09-21 22:01:15 +00:00
2024-09-24 22:17:52 +00:00
2024-09-23 13:48:29 +00:00
2024-09-23 21:55:43 +00:00
2024-09-22 21:58:01 +00:00
//// Delegates
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSkylanderAddedDelegate, int32, SkylanderID, int32, Index);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSkylanderRemovedDelegate, int32, SkylanderID, int32, Index);
#pragma endregion
2024-09-23 13:48:29 +00:00
2024-09-24 22:17:52 +00:00
/*
* Handle all the blueprints functions and game logic.
*
2024-09-22 21:58:01 +00:00
*/
2024-09-21 22:01:15 +00:00
UCLASS(MinimalAPI)
class USkyPortalSubsystem : public UEngineSubsystem
2024-09-18 13:30:30 +00:00
{
GENERATED_BODY()
public:
// Override initialization and deinitialization methods
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
2024-09-19 12:03:16 +00:00
2024-09-22 21:58:01 +00:00
/********* Portal Actions *************/
2024-09-22 21:58:01 +00:00
/* The first function to run, before anything else.
* It will re-init and prepare the portal for receiving/sending inputs
*
* return false if portal is not found
*/
UFUNCTION(BlueprintCallable, CallInEditor, meta = (Category = "SkyPortal"))
2024-09-21 22:01:15 +00:00
SKYPORTAL_API bool ConnectPortal();
2024-09-19 12:03:16 +00:00
2024-09-24 22:17:52 +00:00
UFUNCTION(BlueprintCallable, CallInEditor, meta = (Category = "SkyPortal|Commands"))
SKYPORTAL_API void Ready();
2024-09-22 21:58:01 +00:00
/*Send a **Status** command, to see if the portal is ready to receive new commands*/
UFUNCTION(BlueprintCallable, BlueprintPure, meta = (Category = "SkyPortal|NOT FUNCTIONING"))
SKYPORTAL_API bool bIsPortalReady();
2024-09-19 12:03:16 +00:00
2024-09-22 21:58:01 +00:00
UFUNCTION(BlueprintCallable, meta = (Category = "SkyPortal|NOT FUNCTIONING"))
SKYPORTAL_API void SendPortalCommand(EPortalCommand Command);
2024-09-22 21:58:01 +00:00
UFUNCTION(BlueprintCallable, meta = (Category = "SkyPortal|NOT FUNCTIONING"))
SKYPORTAL_API void SendPortalSound(USoundWave* Sound);
2024-09-21 22:01:15 +00:00
2024-09-23 21:55:43 +00:00
2024-09-22 21:58:01 +00:00
/* Change portal color, ideally should be called just at the start.For gameplay usage, use ChangePortalColorside()*/
2024-09-21 22:01:15 +00:00
UFUNCTION(BlueprintCallable, CallInEditor, meta = (AutoCreateRefTerm = "Color", Category = "SkyPortal|Cosmetic"))
SKYPORTAL_API void ChangePortalColor(const FLinearColor& Color = FLinearColor::Green);
2024-09-21 22:01:15 +00:00
/**
* Change the color of the portal, can separate side and even trap ligth
2024-09-22 21:58:01 +00:00
* @param NextColor New color
2024-09-21 22:01:15 +00:00
* @param PortalSide The actors to record
2024-09-22 21:58:01 +00:00
* @param BlendTime Blend between current color and NextColor, in milliseconds
2024-09-21 22:01:15 +00:00
*/
UFUNCTION(BlueprintCallable, CallInEditor, meta = (AutoCreateRefTerm = "NextColor", Category = "SkyPortal|Cosmetic", HideAlphaChannel))
2024-09-22 21:58:01 +00:00
SKYPORTAL_API void ChangePortalColorside(const FLinearColor& NextColor = FLinearColor::Green, const EPortalSide PortalSide = EPortalSide::BOTH, const float BlendTime = 500.0f);
// Blueprint-assignable event property
UPROPERTY(BlueprintAssignable, Category = "SkyPortal|Skylander")
FOnSkylanderAddedDelegate OnSkylanderAdded;
// Blueprint-assignable event property
UPROPERTY(BlueprintAssignable, Category = "SkyPortal|Skylander")
FOnSkylanderRemovedDelegate OnSkylanderRemoved;
2024-09-23 16:06:55 +00:00
UPROPERTY(BlueprintReadOnly)
FPortalStatusData CurrentStatusData;
2024-09-22 21:58:01 +00:00
2024-09-23 21:55:43 +00:00
UPROPERTY(BlueprintReadOnly)
FPortalStatusData OldStatusData;
2024-09-24 22:17:52 +00:00
UPROPERTY(BlueprintReadOnly)
uint32 PortalId;
2024-09-23 13:48:29 +00:00
EPortalCommand GetPortalCommandFromChar(unsigned char Char);
2024-09-22 21:58:01 +00:00
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
bool bPortalConnected = false;
2024-09-21 22:01:15 +00:00
2024-09-24 22:17:52 +00:00
UFUNCTION()
TArray<uint8> QueryBlock(uint8 characterIndex, uint8 block = 0x00);
2024-09-24 22:17:52 +00:00
USkyPortalIO* PortalHandle;
2024-09-23 16:06:55 +00:00
private:
2024-09-24 22:17:52 +00:00
FPortalStatusData ParsePortalStatus(const WriteBlock& ResponseBlock);
2024-09-19 12:03:16 +00:00
2024-09-23 13:48:29 +00:00
static void Sleep(int sleepMs);
void ActivatePortal(int active);
2024-09-24 22:17:52 +00:00
// Block/byte related data write/read functions
2024-09-24 22:17:52 +00:00
2024-09-23 21:55:43 +00:00
FigureDataBlock ReadFigureBlocks(uint8 FigureIndex);
bool FalsePositive() const;
2024-09-19 12:03:16 +00:00
2024-09-23 13:48:29 +00:00
// Pointer to the status checker thread
FPortalStatusChecker* StatusChecker;
FRunnableThread* StatusCheckerThread;
2024-09-19 12:03:16 +00:00
protected:
2024-09-18 13:30:30 +00:00
};
2024-09-19 12:03:16 +00:00
2024-09-23 13:48:29 +00:00