2022-10-31 22:32:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef __CONTROLBEHAVIORS__H__
|
|
|
|
#define __CONTROLBEHAVIORS__H__
|
|
|
|
|
2023-02-14 02:55:44 +00:00
|
|
|
#include <map>
|
2024-01-03 13:34:38 +00:00
|
|
|
#include <optional>
|
2022-10-31 22:32:07 +00:00
|
|
|
#include <string>
|
|
|
|
|
2024-01-03 13:34:38 +00:00
|
|
|
#include "BlockDefinition.h"
|
2023-02-14 02:55:44 +00:00
|
|
|
#include "Singleton.h"
|
2022-10-31 22:32:07 +00:00
|
|
|
|
|
|
|
class AMFArrayValue;
|
2023-02-14 02:55:44 +00:00
|
|
|
class Entity;
|
2022-11-27 09:24:35 +00:00
|
|
|
class ModelComponent;
|
2023-02-14 02:55:44 +00:00
|
|
|
class SystemAddress;
|
2022-10-31 22:32:07 +00:00
|
|
|
|
2023-02-14 02:55:44 +00:00
|
|
|
// Type definition to clarify what is used where
|
|
|
|
typedef std::string BlockName; //! A block name
|
|
|
|
|
2024-01-03 13:34:38 +00:00
|
|
|
struct ControlBehaviorContext {
|
2024-02-27 07:29:51 +00:00
|
|
|
ControlBehaviorContext(const AMFArrayValue& args, ModelComponent* modelComponent, Entity* modelOwner) noexcept
|
2024-02-18 06:38:26 +00:00
|
|
|
: arguments{ args }, modelComponent{ modelComponent }, modelOwner{ modelOwner } {
|
|
|
|
};
|
2024-01-03 13:34:38 +00:00
|
|
|
|
|
|
|
operator bool() const {
|
2024-02-27 07:29:51 +00:00
|
|
|
return modelComponent != nullptr && modelOwner != nullptr;
|
2024-01-03 13:34:38 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
std::reference_wrapper<const AMFArrayValue> arguments;
|
2024-01-03 13:34:38 +00:00
|
|
|
ModelComponent* modelComponent;
|
2024-02-18 06:38:26 +00:00
|
|
|
Entity* modelOwner;
|
2024-01-03 13:34:38 +00:00
|
|
|
};
|
|
|
|
|
2023-02-14 02:55:44 +00:00
|
|
|
class ControlBehaviors: public Singleton<ControlBehaviors> {
|
|
|
|
public:
|
|
|
|
ControlBehaviors();
|
2022-10-31 22:32:07 +00:00
|
|
|
/**
|
|
|
|
* @brief Main driver for processing Property Behavior commands
|
|
|
|
*
|
|
|
|
* @param modelEntity The model that sent this command
|
|
|
|
* @param arguments The arguments formatted as an AMFArrayValue
|
|
|
|
* @param command The command to perform
|
|
|
|
* @param modelOwner The owner of the model which sent this command
|
|
|
|
*/
|
2024-11-19 02:45:24 +00:00
|
|
|
void ProcessCommand(Entity* const modelEntity, const AMFArrayValue& arguments, const std::string_view command, Entity* const modelOwner);
|
2023-02-14 02:55:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets a blocks parameter values by the name
|
|
|
|
* No exception will be thrown in this function.
|
|
|
|
*
|
|
|
|
* @param blockName The block name to get the parameters of
|
|
|
|
*
|
|
|
|
* @return A pair of the block parameter name to its typing
|
|
|
|
*/
|
2024-11-19 02:45:24 +00:00
|
|
|
[[nodiscard]] std::optional<BlockDefinition> GetBlockInfo(const std::string_view blockName);
|
2023-02-14 02:55:44 +00:00
|
|
|
private:
|
2024-01-03 13:34:38 +00:00
|
|
|
void RequestUpdatedID(ControlBehaviorContext& context);
|
|
|
|
void SendBehaviorListToClient(const ControlBehaviorContext& context);
|
|
|
|
void SendBehaviorBlocksToClient(ControlBehaviorContext& context);
|
2024-02-27 07:29:51 +00:00
|
|
|
void UpdateAction(const AMFArrayValue& arguments);
|
2024-02-18 06:38:26 +00:00
|
|
|
std::map<BlockName, BlockDefinition, std::less<>> blockTypes{};
|
2023-02-14 02:55:44 +00:00
|
|
|
|
|
|
|
// If false, property behaviors will not be able to be edited.
|
|
|
|
bool isInitialized = false;
|
2022-10-31 22:32:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //!__CONTROLBEHAVIORS__H__
|