Agrarsense
Walker.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "GameFramework/Character.h"
10
15#include "WalkerParameters.h"
16
17#include "Walker.generated.h"
18
19DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWalkerEventDelegate_ParametersChanged, FWalkerParameters, NewWalkerParameters);
20
21/*
22* Base class for all Walkers.
23* Actual movement logic is defined in BP_WalkerBase blueprint
24* and individual Walkers blueprints like BP_Reindeer.
25*/
26UCLASS()
27class AGRARSENSE_API AWalker : public ACharacter, public IInteractable, public IDestroyable, public IActorInformation
28{
29 GENERATED_BODY()
30
31public:
32
33 AWalker();
34
35 UFUNCTION(BlueprintCallable)
36 virtual void PauseWalker();
37
38 UFUNCTION(BlueprintCallable)
39 virtual void ResumeWalker();
40
41 UFUNCTION(BlueprintCallable)
42 virtual void SetIgnoreInput(bool IgnoreInput);
43
49 UFUNCTION(BlueprintCallable)
50 FString ExportToJsonFile(const FString& FileName);
51
52 UFUNCTION(BlueprintCallable)
53 void DebugDrawLinesBetweenPoints(float LifeTime = 10.0f);
54
55 UFUNCTION(BlueprintCallable)
56 void ChangeWalkerParameters(const FWalkerParameters& newParameters)
57 {
58 SetWalkerParameters(newParameters);
59 OnWalkerParametersChanged.Broadcast(WalkerParameters);
60 }
61
62 void SetWalkerParameters(const FWalkerParameters& InParameters)
63 {
64 WalkerParameters = InParameters;
65 }
66
67 UFUNCTION(BlueprintCallable)
68 virtual EWalkerType GetWalkerType() const
69 {
70 return WalkerParameters.WalkerType;
71 }
72
73 UFUNCTION(BlueprintPure)
74 FWalkerParameters GetWalkerParameters() const
75 {
76 return WalkerParameters;
77 }
78
79 UFUNCTION(BlueprintCallable)
80 FTransform GetStartTransform() const
81 {
82 if (!WalkerParameters.Points.IsEmpty())
83 {
84 return WalkerParameters.Points[0];
85 }
86
87 return FTransform::Identity;
88 }
89
90 UFUNCTION(BlueprintCallable)
91 FTransform GetEndTransform() const
92 {
93 if (!WalkerParameters.Points.IsEmpty())
94 {
95 return WalkerParameters.Points.Last();
96 }
97
98 return FTransform::Identity;
99 }
100
101 UFUNCTION(BlueprintPure)
102 bool IsWalkerPaused() const
103 {
104 return WalkerIsPaused;
105 }
106
107 virtual FText GetInteractableName_Implementation() const override
108 {
109 return InteractableName;
110 }
111
112 virtual FTransform GetInteractableWorldTransform_Implementation() const override
113 {
114 return GetActorTransform();
115 }
116
117 virtual FString GetActorID_Implementation() const override
118 {
119 return ActorID;
120 }
121
122 virtual FString GetActorName_Implementation() const override
123 {
124 return ActorName;
125 }
126
127 virtual FString GetActorInformation_Implementation() const override
128 {
129 const FString Walker = UEnumUtilities::ConvertWalkerTypeToString(WalkerParameters.WalkerType);
130 const FString ID = GetActorID_Implementation();
131 const FString Name = GetActorName_Implementation();
132 const FTransform VehicleTransform = GetActorTransform();
133 const FVector Location = VehicleTransform.GetLocation();
134 const FRotator Rotation = VehicleTransform.Rotator();
135 FString Information = FString::Printf(TEXT("Walker: %s, Name: %s, ID: %s, Location: %s, Rotation: %s"), *Walker, *Name, *ID, *Location.ToString(), *Rotation.ToString());
136
137 return Information;
138 }
139
140 virtual void SetActorName_Implementation(const FString& NewActorName) override
141 {
142 ActorName = NewActorName;
143 }
144
145 virtual void SetActorIDAndName_Implementation(const FString& NewActorName, const FString& NewID) override
146 {
147 ActorName = NewActorName;
148 ActorID = NewID;
149 SetAndValidateActorIDAndName(ActorName, ActorID, TWeakObjectPtr<AActor>(this));
150 }
151
152
153 UPROPERTY(BlueprintAssignable)
154 FWalkerEventDelegate_ParametersChanged OnWalkerParametersChanged;
155
156 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interactable")
157 FText InteractableName;
158
159protected:
160
161 virtual void BeginPlay() override;
162
163 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
164
165 UPROPERTY(VisibleAnywhere)
166 FString ActorName;
167
168 UPROPERTY(VisibleAnywhere)
169 FString ActorID;
170
171private:
172
173 UPROPERTY(VisibleAnywhere, Category = "Walker")
174 bool WalkerIsPaused = true;
175
176 UPROPERTY(VisibleAnywhere, Category = "Walker")
177 FWalkerParameters WalkerParameters;
178
179 FWalkerParameters PreviousParameters;
180
181};
EWalkerType
Definition: WalkerType.h:16
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWalkerEventDelegate_ParametersChanged, FWalkerParameters, NewWalkerParameters)
Definition: Walker.h:28
virtual FString GetActorID_Implementation() const override
Definition: Walker.h:117
virtual FTransform GetInteractableWorldTransform_Implementation() const override
Definition: Walker.h:112
void SetWalkerParameters(const FWalkerParameters &InParameters)
Definition: Walker.h:62
virtual void SetActorName_Implementation(const FString &NewActorName) override
Definition: Walker.h:140
virtual FString GetActorName_Implementation() const override
Definition: Walker.h:122
virtual void SetActorIDAndName_Implementation(const FString &NewActorName, const FString &NewID) override
Definition: Walker.h:145
virtual FString GetActorInformation_Implementation() const override
Definition: Walker.h:127
virtual FText GetInteractableName_Implementation() const override
Definition: Walker.h:107
static FString ConvertWalkerTypeToString(EWalkerType WalkerType)
TArray< FTransform > Points
EWalkerType WalkerType