summaryrefslogtreecommitdiffstats
path: root/source/squirrelbindings
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/squirrelbindings/SquirrelArray.h36
-rw-r--r--source/squirrelbindings/SquirrelBindings.cpp129
-rw-r--r--source/squirrelbindings/cSquirrelBaseClass.h12
3 files changed, 176 insertions, 1 deletions
diff --git a/source/squirrelbindings/SquirrelArray.h b/source/squirrelbindings/SquirrelArray.h
new file mode 100644
index 000000000..0c2e34f7f
--- /dev/null
+++ b/source/squirrelbindings/SquirrelArray.h
@@ -0,0 +1,36 @@
+#pragma once
+#include <string>
+
+template <typename T>
+class SquirrelArray
+{
+public:
+ SquirrelArray()
+ {
+ }
+
+ unsigned int Size()
+ {
+ return m_Values.size();
+ }
+
+ T Get(unsigned int a_Index)
+ {
+ if(m_Values.size() < a_Index)
+ {
+ return T();
+ }
+ return m_Values.at(a_Index);
+ }
+
+ void Add(T a_Value)
+ {
+ m_Values.push_back(a_Value);
+ }
+
+protected:
+ std::vector<T> m_Values;
+
+};
+
+class SquirrelStringArray : public SquirrelArray<std::string> { }; \ No newline at end of file
diff --git a/source/squirrelbindings/SquirrelBindings.cpp b/source/squirrelbindings/SquirrelBindings.cpp
index 27a82c306..f0291b39b 100644
--- a/source/squirrelbindings/SquirrelBindings.cpp
+++ b/source/squirrelbindings/SquirrelBindings.cpp
@@ -3,6 +3,7 @@
#include "SquirrelFunctions.h"
#include "cSquirrelBaseClass.h"
+#include "SquirrelArray.h"
#include "../cPlayer.h"
@@ -15,9 +16,135 @@ void BindSquirrel(HSQUIRRELVM vm)
RootTable()
.Bind("Plugin", Class<cSquirrelBaseClass>()
.Func("AddHook", &cSquirrelBaseClass::AddHook)
+ .Func("AddCommand", &cSquirrelBaseClass::AddCommand)
+ .Func("BindCommand", &cSquirrelBaseClass::BindCommand)
);
- RootTable().Bind("cPlayer", Class<cPlayer, NoConstructor>()
+
+ RootTable().Bind("Vector3f", Class<Vector3f, NoConstructor>()
+ .Func("Set", &Vector3f::Set)
+ .Func("Normalize", &Vector3f::Normalize)
+ .Func("Length", &Vector3f::Length)
+ .Func("SqrLength", &Vector3f::SqrLength)
+ .Var("x", &Vector3f::x)
+ .Var("y", &Vector3f::y)
+ .Var("z", &Vector3f::z)
+ );
+
+ RootTable().Bind("Vector3d", Class<Vector3d, NoConstructor>()
+ .Func("Set", &Vector3d::Set)
+ .Func("Normalize", &Vector3d::Normalize)
+ .Func("Length", &Vector3d::Length)
+ .Func("SqrLength", &Vector3d::SqrLength)
+ .Var("x", &Vector3d::x)
+ .Var("y", &Vector3d::y)
+ .Var("z", &Vector3d::z)
+ );
+
+ RootTable().Bind("cEntity", Class<cEntity, NoConstructor>()
+ .Func("GetEntityType", &cEntity::GetEntityType)
+ .Func("IsA", &cEntity::IsA)
+ .Func("GetWorld", &cEntity::GetWorld)
+ .Func("GetPosition", &cEntity::GetPosition)
+ .Func("GetPosX", &cEntity::GetPosX)
+ .Func("GetPosY", &cEntity::GetPosY)
+ .Func("GetPosZ", &cEntity::GetPosZ)
+ .Func("GetRot", &cEntity::GetRot)
+ .Func("GetRotation", &cEntity::GetRotation)
+ .Func("GetPitch", &cEntity::GetPitch)
+ .Func("GetRoll", &cEntity::GetRoll)
+ .Func("SetRotation", &cEntity::SetRotation)
+ .Func("SetPitch", &cEntity::SetPitch)
+ .Func("SetRoll", &cEntity::SetRoll)
+ .Func("GetLookVector", &cEntity::GetLookVector)
+ .Func("GetChunkX", &cEntity::GetChunkX)
+ .Func("GetChunkY", &cEntity::GetChunkY)
+ .Func("GetChunkZ", &cEntity::GetChunkZ)
+ .Func("SetPosX", &cEntity::SetPosX)
+ .Func("SetPosY", &cEntity::SetPosY)
+ .Func("SetPosZ", &cEntity::SetPosZ)
+ .Func<void (cEntity::*) (const double &, const double &, const double &)>("SetPosition", &cEntity::SetPosition)
+ .Func("GetUniqueID", &cEntity::GetUniqueID)
+ .Func("IsDestroyed", &cEntity::IsDestroyed)
+ .Func("Destroy", &cEntity::Destroy)
+ .Func("SpawnOn", &cEntity::SpawnOn)
+
+ );
+
+ ConstTable().Enum("MetaData", Enumeration()
+ .Const("Normal", cPawn::NORMAL)
+ .Const("Burning", cPawn::BURNING)
+ .Const("Crouched", cPawn::CROUCHED)
+ .Const("Riding", cPawn::RIDING)
+ .Const("Sprinting", cPawn::SPRINTING)
+ .Const("Eating", cPawn::EATING)
+ .Const("Blocking", cPawn::BLOCKING)
+ );
+
+ RootTable().Bind("cPawn", DerivedClass<cPawn, cEntity, NoConstructor>()
+ .Func("TeleportToEntity", &cPawn::TeleportToEntity)
+ .Func("TeleportTo", &cPawn::TeleportTo)
+ .Func("Heal", &cPawn::Heal)
+ .Func("TakeDamage", &cPawn::TakeDamage)
+ .Func("KilledBy", &cPawn::KilledBy)
+ .Func("GetHealth", &cPawn::GetHealth)
+ .Func("SetMetaData", &cPawn::SetMetaData)
+ .Func("GetMetaData", &cPawn::GetMetaData)
+ .Func("SetMaxHealth", &cPawn::SetMaxHealth)
+ .Func("GetMaxHealth", &cPawn::GetMaxHealth)
+ .Func("GetMaxFood", &cPawn::GetMaxFood)
+ .Func("GetFood", &cPawn::GetFood)
+ .Func("GetMaxFoodSaturation", &cPawn::GetMaxFoodSaturation)
+ .Func("GetFoodSaturation", &cPawn::GetFoodSaturation)
+ .Func("SetMaxFoodLevel", &cPawn::SetMaxFoodLevel)
+ .Func("GetMaxFoodLevel", &cPawn::SetMaxFoodLevel)
+ );
+
+ RootTable().Bind("cPlayer", DerivedClass<cPlayer, cPawn, NoConstructor>()
.Func("GetName", &cPlayer::GetName)
+ .Func("SetTouchGround", &cPlayer::SetTouchGround)
+ .Func("SetStance", &cPlayer::SetStance)
+ .Func("GetEyeHeight", &cPlayer::GetEyeHeight)
+ .Func("GetEyePosition", &cPlayer::GetEyePosition)
+ .Func("GetFlying", &cPlayer::GetFlying)
+ .Func("GetStance", &cPlayer::GetStance)
+ //TODO .Func("GetInventory", &cPlayer::GetInventory)
+ .Func("TeleportTo", &cPlayer::TeleportTo)
+ .Func("GetGameMode", &cPlayer::GetGameMode)
+ .Func("GetIP", &cPlayer::GetIP)
+ .Func("GetLastBlockActionTime", &cPlayer::GetLastBlockActionTime)
+ .Func("GetLastBlockActionCnt", &cPlayer::GetLastBlockActionCnt)
+ .Func("SetLastBlockActionCnt", &cPlayer::SetLastBlockActionCnt)
+ .Func("SetLastBlockActionTime", &cPlayer::SetLastBlockActionTime)
+ .Func("SetGameMode", &cPlayer::SetGameMode)
+ .Func("LoginSetGameMode", &cPlayer::LoginSetGameMode)
+ .Func("SetIP", &cPlayer::SetIP)
+ .Func("MoveTo", &cPlayer::MoveTo)
+ .Func("GetClientHandle", &cPlayer::GetClientHandle)
+ .Func("SendMessage", &cPlayer::SendMessage)
+ .Func("AddToGroup", &cPlayer::AddToGroup)
+ .Func("CanUseCommand", &cPlayer::CanUseCommand)
+ .Func("HasPermission", &cPlayer::HasPermission)
+ .Func("IsInGroup", &cPlayer::IsInGroup)
+ .Func("GetColor", &cPlayer::GetColor)
+ .Func("TossItem", &cPlayer::TossItem)
+ .Func("Heal", &cPlayer::Heal)
+ .Func("Feed", &cPlayer::Feed)
+ .Func("TakeDamage", &cPlayer::TakeDamage)
+ .Func("KilledBy", &cPlayer::KilledBy)
+ .Func("Respawn", &cPlayer::Respawn)
+ .Func("SetVisible", &cPlayer::SetVisible)
+ .Func("IsVisible", &cPlayer::IsVisible)
+ .Func("MoveToWorld", &cPlayer::MoveToWorld)
+ .Func("GetLoadedWorldName", &cPlayer::GetLoadedWorldName)
+ .Func("UseEquippedItem", &cPlayer::UseEquippedItem)
+ .Func("EatItem", &cPlayer::EatItem)
+
+ );
+
+ RootTable().Bind("StringArray", Class<SquirrelStringArray>()
+ .Func("Get", &SquirrelStringArray::Get)
+ .Func("Add", &SquirrelStringArray::Add)
+ .Func("Size", &SquirrelStringArray::Size)
);
diff --git a/source/squirrelbindings/cSquirrelBaseClass.h b/source/squirrelbindings/cSquirrelBaseClass.h
index a66ca7ddd..279c47027 100644
--- a/source/squirrelbindings/cSquirrelBaseClass.h
+++ b/source/squirrelbindings/cSquirrelBaseClass.h
@@ -3,6 +3,7 @@
#include "../cPlugin_Squirrel.h"
#include "../cPluginManager.h"
#include "../cRoot.h"
+#include "../cSquirrelCommandBinder.h"
//The baseclass for squirrel plugins
class cSquirrelBaseClass
@@ -24,6 +25,17 @@ public:
cRoot::Get()->GetPluginManager()->AddHook(m_Instance, (cPluginManager::PluginHook) a_Hook);
}
+ void AddCommand( std::string a_Command, std::string a_Description, std::string a_Permission )
+ {
+ if(m_Instance) m_Instance->AddCommand(a_Command, a_Description, a_Permission);
+ }
+
+ bool BindCommand( const std::string a_Command, const std::string a_Permission, Sqrat::Function a_Callback)
+ {
+ if(!m_Instance) return false;
+ return cRoot::Get()->GetPluginManager()->GetSquirrelCommandBinder()->BindCommand(a_Command, a_Permission, m_Instance, a_Callback);
+ }
+
protected:
cPlugin_Squirrel *m_Instance;
}; \ No newline at end of file