2015-11-11 07:57:18 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Entity/KeyBind.hpp"
|
2015-11-01 00:31:46 +01:00
|
|
|
#include "Core.hpp"
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Tasks.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2015-11-01 00:31:46 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_DECL_TYPENAME(Typename, _SC("SqKeyBind"))
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
const int32_t CKeyBind::Max = SQMOD_KEYBIND_POOL;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-08-07 00:54:33 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQInteger CKeyBind::SqGetNull(HSQUIRRELVM vm)
|
2016-08-07 00:54:33 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
sq_pushobject(vm, Core::Get().GetNullKeyBind().GetObj());
|
2016-08-07 00:54:33 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
LightObj & CKeyBind::GetNull()
|
2016-08-07 00:54:33 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().GetNullKeyBind();
|
2016-08-07 00:54:33 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
CKeyBind::CKeyBind(int32_t id)
|
2016-02-20 23:25:00 +01:00
|
|
|
: m_ID(VALID_ENTITYGETEX(id, SQMOD_KEYBIND_POOL))
|
2021-01-30 07:51:39 +01:00
|
|
|
, m_Tag(fmt::format("{}", id))
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
const String & CKeyBind::ToString() const
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2015-10-29 21:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
const String & CKeyBind::GetTag() const
|
2015-10-29 21:09:53 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void CKeyBind::SetTag(StackStrF & tag)
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-11-16 13:48:28 +01:00
|
|
|
if (tag.mLen > 0)
|
|
|
|
{
|
2020-03-22 09:00:31 +01:00
|
|
|
m_Tag.assign(tag.mPtr, static_cast< size_t >(tag.mLen));
|
2016-11-16 13:48:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Tag.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
CKeyBind & CKeyBind::ApplyTag(StackStrF & tag)
|
2016-11-16 13:48:28 +01:00
|
|
|
{
|
|
|
|
SetTag(tag);
|
|
|
|
return *this;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
LightObj & CKeyBind::GetData()
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return m_Data;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
2015-10-29 21:09:53 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void CKeyBind::SetData(LightObj & data)
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Apply the specified value
|
|
|
|
m_Data = data;
|
2015-10-29 21:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
bool CKeyBind::Destroy(int32_t header, LightObj & payload) const
|
2015-10-29 21:09:53 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().DelKeyBind(m_ID, header, payload);
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
LightObj & CKeyBind::GetEvents() const
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
2017-02-21 20:24:59 +01:00
|
|
|
// Return the associated event table
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().GetKeyBind(m_ID).mEvents;
|
2015-10-29 21:09:53 +01:00
|
|
|
}
|
|
|
|
|
2016-07-26 23:13:50 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void CKeyBind::CustomEvent(int32_t header, LightObj & payload) const
|
2016-07-26 23:13:50 +02:00
|
|
|
{
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
2021-01-30 07:51:39 +01:00
|
|
|
// Perform the requested action
|
|
|
|
Core::Get().EmitKeyBindCustom(m_ID, header, payload);
|
2016-07-26 23:13:50 +02:00
|
|
|
}
|
|
|
|
|
2015-11-01 00:31:46 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t CKeyBind::GetFirst() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().GetKeyBind(m_ID).mFirst;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t CKeyBind::GetSecond() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().GetKeyBind(m_ID).mSecond;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t CKeyBind::GetThird() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().GetKeyBind(m_ID).mThird;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
bool CKeyBind::IsRelease() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2021-01-30 07:51:39 +01:00
|
|
|
return static_cast< bool >(Core::Get().GetKeyBind(m_ID).mRelease);
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static LightObj & KeyBind_CreateEx1a(int32_t slot, bool release, int32_t primary, int32_t secondary,
|
|
|
|
int32_t alternative)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().NewKeyBind(slot, release, primary, secondary, alternative,
|
2021-03-20 10:51:40 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullLightObj()).mObj;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
static LightObj & KeyBind_CreateEx1b(int32_t slot, bool release, int32_t primary, int32_t secondary,
|
|
|
|
int32_t alternative, int32_t header, LightObj & payload)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2021-03-20 10:51:40 +01:00
|
|
|
return Core::Get().NewKeyBind(slot, release, primary, secondary, alternative, header, payload).mObj;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static LightObj & KeyBind_Create1a(bool release, int32_t primary, int32_t secondary, int32_t alternative)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return Core::Get().NewKeyBind(-1, release, primary, secondary, alternative,
|
2021-03-20 10:51:40 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullLightObj()).mObj;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
static LightObj & KeyBind_Create1b(bool release, int32_t primary, int32_t secondary, int32_t alternative,
|
|
|
|
int32_t header, LightObj & payload)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2021-03-20 10:51:40 +01:00
|
|
|
return Core::Get().NewKeyBind(-1, release, primary, secondary, alternative, header, payload).mObj;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:01:59 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
static SQInteger KeyBind_UnusedSlot()
|
2016-06-20 07:01:59 +02:00
|
|
|
{
|
|
|
|
return _Func->GetKeyBindUnusedSlot();
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:09:53 +01:00
|
|
|
// ================================================================================================
|
2021-01-30 07:51:39 +01:00
|
|
|
void Register_CKeyBind(HSQUIRRELVM vm)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-11-15 20:16:24 +01:00
|
|
|
RootTable(vm).Bind(Typename::Str,
|
2021-01-30 07:51:39 +01:00
|
|
|
Class< CKeyBind, NoConstructor< CKeyBind > >(vm, Typename::Str)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-11-15 20:16:24 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
|
2021-01-30 07:51:39 +01:00
|
|
|
.Func(_SC("_tostring"), &CKeyBind::ToString)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Values
|
2021-01-30 07:51:39 +01:00
|
|
|
.SetStaticValue(_SC("MaxID"), CKeyBind::Max)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Core Properties
|
2021-01-30 07:51:39 +01:00
|
|
|
.Prop(_SC("On"), &CKeyBind::GetEvents)
|
|
|
|
.Prop(_SC("ID"), &CKeyBind::GetID)
|
|
|
|
.Prop(_SC("Tag"), &CKeyBind::GetTag, &CKeyBind::SetTag)
|
|
|
|
.Prop(_SC("Data"), &CKeyBind::GetData, &CKeyBind::SetData)
|
|
|
|
.Prop(_SC("Active"), &CKeyBind::IsActive)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Core Methods
|
2021-01-30 07:51:39 +01:00
|
|
|
.FmtFunc(_SC("SetTag"), &CKeyBind::ApplyTag)
|
|
|
|
.Func(_SC("CustomEvent"), &CKeyBind::CustomEvent)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Core Overloads
|
2021-01-30 07:51:39 +01:00
|
|
|
.Overload(_SC("Destroy"), &CKeyBind::Destroy0)
|
|
|
|
.Overload(_SC("Destroy"), &CKeyBind::Destroy1)
|
|
|
|
.Overload(_SC("Destroy"), &CKeyBind::Destroy)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Properties
|
2021-01-30 07:51:39 +01:00
|
|
|
.Prop(_SC("First"), &CKeyBind::GetFirst)
|
|
|
|
.Prop(_SC("Second"), &CKeyBind::GetSecond)
|
|
|
|
.Prop(_SC("Third"), &CKeyBind::GetThird)
|
|
|
|
.Prop(_SC("Release"), &CKeyBind::IsRelease)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Functions
|
2021-01-30 07:51:39 +01:00
|
|
|
.StaticFunc(_SC("UnusedSlot"), &KeyBind_UnusedSlot)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Static Overloads
|
2021-01-30 07:51:39 +01:00
|
|
|
.StaticOverload(_SC("CreateEx"), &KeyBind_CreateEx1a)
|
|
|
|
.StaticOverload(_SC("CreateEx"), &KeyBind_CreateEx1b)
|
|
|
|
.StaticOverload(_SC("Create"), &KeyBind_Create1a)
|
|
|
|
.StaticOverload(_SC("Create"), &KeyBind_Create1b)
|
2016-08-07 00:54:33 +02:00
|
|
|
// Raw Squirrel Methods
|
2021-01-30 07:51:39 +01:00
|
|
|
.SquirrelFunc(_SC("NullInst"), &CKeyBind::SqGetNull)
|
|
|
|
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CKeyBind, ENT_KEYBIND >)
|
|
|
|
.SquirrelFunc(_SC("DropTask"), &Tasks::DropTask< CKeyBind, ENT_KEYBIND >)
|
|
|
|
.SquirrelFunc(_SC("DoesTask"), &Tasks::DoesTask< CKeyBind, ENT_KEYBIND >)
|
|
|
|
.SquirrelFunc(_SC("FindTask"), &Tasks::FindTask< CKeyBind, ENT_KEYBIND >)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-14 02:08:06 +02:00
|
|
|
} // Namespace:: SqMod
|