/************************************************************************************//*!
\file Component.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 27, 2021
\brief Contains the definition of the managed Component classes with the
declaration of functions for working with it.
Note: This file is written in C++17/CLI.
Copyright (C) 2021 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "Engine/ECS_Base/Components/SHComponent.h"
// Project Includes
#include "Engine/Entity.hxx"
#include "Scripts/Script.hxx"
namespace SHADE
{
///
/// Class that serves as the base for a wrapper class to Components in native code.
///
public ref class BaseComponent : public System::IEquatable
{
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
///
/// Retrieves the GameObject that this Component belongs to.
///
property GameObject Owner
{
GameObject get() { return owner; }
}
/*-----------------------------------------------------------------------------*/
/* Component Access Functions */
/*-----------------------------------------------------------------------------*/
///
/// Adds a Component to this GameObject.
///
/// Type of the Component to add.
/// Reference to the Component that was added.
generic where T : BaseComponent
T AddComponent();
///
/// Gets a Component from this GameObject.
///
/// Type of the Component to get.
///
/// Reference to the Component or null if this GameObject does not have the
/// specified Component.
///
generic where T : BaseComponent
T GetComponent();
///
/// Removes a Component from this GameObject. If no Component exists to begin
/// with, nothing happens.
///
/// Type of the Component to get.
generic where T : BaseComponent
void RemoveComponent();
/*-----------------------------------------------------------------------------*/
/* Script Access Functions */
/*-----------------------------------------------------------------------------*/
///
/// Adds a PlushieScript of the specified type to this GameObject.
///
/// Type of PlushieScript to add.
/// Reference to the created PlushieScript.
generic where T : ref class, PlushieScript
T AddScript();
///
/// Retrieves a PlushieScript of the specified type from this GameObject.
/// If multiple PlushieScripts of the same specified type are added on the same
/// GameObject, this will retrieve the first one added.
///
/// Type of PlushieScript to add.
/// Reference to the PlushieScript to retrieve.
generic where T : ref class, PlushieScript
T GetScript();
///
/// Retrieves a immutable list of PlushieScripts of the specified type from this
/// GameObject.
///
/// Type of PlushieScripts to Get.
/// Immutable list of PlushieScripts of the specified type.
generic where T : ref class, PlushieScript
System::Collections::Generic::IEnumerable^ GetScripts();
///
/// Removes all PlushieScripts of the specified type from this GameObject.
///
/// Type of PLushieScripts to remove.
generic where T : ref class, PlushieScript
void RemoveScript();
protected:
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
///
/// Constructor for BaseComponent to tie it to a specific Entity.
/// Constructors of derived Components should call this Constructor.
///
/// Entity that this Component will be tied to.
BaseComponent(Entity entity);
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
///
/// Entity that this Component belongs to.
///
GameObject owner;
public:
/*-----------------------------------------------------------------------------*/
/* IEquatable */
/*-----------------------------------------------------------------------------*/
///
/// Compares equality with an object of the same type.
///
/// The object to compare with.
/// True if both objects are the same.
virtual bool Equals(BaseComponent^ other);
/*-----------------------------------------------------------------------------*/
/* Object */
/*-----------------------------------------------------------------------------*/
///
/// Compares equality with another unboxed object.
///
/// The unboxed object to compare with.
/// True if both objects are the same.
bool Equals(Object^ o) override;
///
/// Gets a unique hash for this object.
///
/// Unique hash for this object.
int GetHashCode() override;
};
///
/// C++ template for the BaseComponent class used to generate common template-able
/// functions and types.
///
///
/// Type of the native component that this Component wraps.
///
template
public ref class Component : public BaseComponent
{
internal:
/*-----------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------*/
///
/// Type of the native component that this Component wraps.
///
using NativeComponent = NativeType;
/*-----------------------------------------------------------------------------*/
/* Helper Functions */
/*-----------------------------------------------------------------------------*/
///
/// Retrieves a pointer to the native unmanaged component that is tied to the
/// Entity described by the owner value.
///
///
/// Pointer to the native component. Will be nullptr if it does not exist.
///
///
/// Thrown if the internal ID stored by this native component is invalid.
///
///
/// Thrown if an attempt to retrieve the native component fails.
///
NativeComponent* GetNativeComponent();
protected:
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
///
/// Constructor for Component to tie it to a specific Entity.
/// Constructors of derived Components should call this Constructor.
///
/// Entity that this Component will be tied to.
Component(Entity entity);
};
}
#include "Component.h++"