Added various method to the .Net API
- IsKeyDown - GetMousePosition - GetEntity - HasComponent - GetComponent - Added InputKeyCode to C#
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Nuake {
|
||||
|
||||
void EngineNetAPI::RegisterMethods()
|
||||
{
|
||||
RegisterMethod("LoggerLogIcall", (void*)(&Log));
|
||||
RegisterMethod("Engine.LoggerLogIcall", (void*)(&Log));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
28
Nuake/src/Scripting/NetModules/InputNetAPI.cpp
Normal file
28
Nuake/src/Scripting/NetModules/InputNetAPI.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "InputNetAPI.h"
|
||||
|
||||
#include "src/Core/Input.h"
|
||||
|
||||
#include <Coral/NativeArray.hpp>
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
bool IsKeyDown(int keyCode)
|
||||
{
|
||||
return Input::IsKeyDown(keyCode);
|
||||
}
|
||||
|
||||
Coral::NativeArray<float> GetMousePosition()
|
||||
{
|
||||
Vector2 mousePosition = Input::GetMousePosition();
|
||||
return { mousePosition.x, mousePosition.y};
|
||||
}
|
||||
|
||||
|
||||
void InputNetAPI::RegisterMethods()
|
||||
{
|
||||
RegisterMethod("Input.IsKeyDownIcall", &IsKeyDown);
|
||||
RegisterMethod("Input.GetMousePositionIcall", &GetMousePosition);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
14
Nuake/src/Scripting/NetModules/InputNetAPI.h
Normal file
14
Nuake/src/Scripting/NetModules/InputNetAPI.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "NetAPIModule.h"
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
class InputNetAPI : public NetAPIModule
|
||||
{
|
||||
public:
|
||||
virtual const std::string GetModuleName() const override { return "Input"; }
|
||||
|
||||
virtual void RegisterMethods() override;
|
||||
|
||||
};
|
||||
}
|
||||
108
Nuake/src/Scripting/NetModules/SceneNetAPI.cpp
Normal file
108
Nuake/src/Scripting/NetModules/SceneNetAPI.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "SceneNetAPI.h"
|
||||
|
||||
#include "Engine.h"
|
||||
#include "src/Scene/Entities/Entity.h"
|
||||
#include <src/Scene/Components/ParentComponent.h>
|
||||
#include <src/Scene/Components/PrefabComponent.h>
|
||||
#include <src/Scene/Components/CameraComponent.h>
|
||||
#include <src/Scene/Components/AudioEmitterComponent.h>
|
||||
#include <src/Scene/Components/ModelComponent.h>
|
||||
#include <src/Scene/Components/SkinnedModelComponent.h>
|
||||
#include <src/Scene/Components/BoneComponent.h>
|
||||
#include <src/Scene/Components/BoxCollider.h>
|
||||
#include <src/Scene/Components/SphereCollider.h>
|
||||
#include <src/Scene/Components/CapsuleColliderComponent.h>
|
||||
#include <src/Scene/Components/CylinderColliderComponent.h>
|
||||
#include <src/Scene/Components/MeshCollider.h>
|
||||
#include <src/Scene/Components/CharacterControllerComponent.h>
|
||||
#include <src/Scene/Components/ParticleEmitterComponent.h>
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
#include <src/Scene/Components/SpriteComponent.h>
|
||||
#include <src/Scene/Components/QuakeMap.h>
|
||||
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
uint32_t GetEntity(Coral::NativeString entityName)
|
||||
{
|
||||
auto scene = Engine::GetCurrentScene();
|
||||
|
||||
std::string entityNameString = entityName.ToString();
|
||||
if (!scene->EntityExists(entityNameString))
|
||||
{
|
||||
return UINT32_MAX; // Error code: entity not found.
|
||||
}
|
||||
|
||||
return scene->GetEntity(entityNameString).GetHandle();
|
||||
}
|
||||
|
||||
static enum ComponentTypes
|
||||
{
|
||||
Unknown = -1,
|
||||
PARENT = 0,
|
||||
NAME,
|
||||
PREFAB,
|
||||
TRANSFORM,
|
||||
LIGHT,
|
||||
CAMERA,
|
||||
AUDIO_EMITTER,
|
||||
MODEL,
|
||||
SKINNED_MODEL,
|
||||
BONE,
|
||||
RIGIDBODY,
|
||||
BOX_COLLIDER,
|
||||
SPHERE_COLLIDER,
|
||||
CAPSULE_COLLIDER,
|
||||
CYLINDER_COLLIDER,
|
||||
MESH_COLLIDER,
|
||||
CHARACTER_CONTROLLER,
|
||||
PARTICLE_EMITTER,
|
||||
QUAKE_MAP,
|
||||
BSP_BRUSH,
|
||||
SPRITE
|
||||
};
|
||||
|
||||
bool EntityHasComponent(uint32_t handle, uint32_t componentEnumValue)
|
||||
{
|
||||
Entity entity = { (entt::entity)handle, Engine::GetCurrentScene().get()};
|
||||
|
||||
if (entity.IsValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (static_cast<ComponentTypes>(componentEnumValue))
|
||||
{
|
||||
case PARENT: return entity.HasComponent<ParentComponent>();
|
||||
case NAME: return entity.HasComponent<NameComponent>();
|
||||
case PREFAB: return entity.HasComponent<PrefabComponent>();
|
||||
case TRANSFORM: return entity.HasComponent<TransformComponent>();
|
||||
case LIGHT: return entity.HasComponent<LightComponent>();
|
||||
case CAMERA: return entity.HasComponent<CameraComponent>();
|
||||
case AUDIO_EMITTER: return entity.HasComponent<AudioEmitterComponent>();
|
||||
case MODEL: return entity.HasComponent<ModelComponent>();
|
||||
case SKINNED_MODEL: return entity.HasComponent<SkinnedModelComponent>();
|
||||
case BONE: return entity.HasComponent<BoneComponent>();
|
||||
case BOX_COLLIDER: return entity.HasComponent<BoxColliderComponent>();
|
||||
case SPHERE_COLLIDER: return entity.HasComponent<SphereColliderComponent>();
|
||||
case CAPSULE_COLLIDER: return entity.HasComponent<CapsuleColliderComponent>();
|
||||
case CYLINDER_COLLIDER: return entity.HasComponent<CylinderColliderComponent>();
|
||||
case MESH_COLLIDER: return entity.HasComponent<MeshColliderComponent>();
|
||||
case CHARACTER_CONTROLLER: return entity.HasComponent<CharacterControllerComponent>();
|
||||
case PARTICLE_EMITTER: return entity.HasComponent<ParticleEmitterComponent>();
|
||||
case QUAKE_MAP: return entity.HasComponent<QuakeMapComponent>();
|
||||
case BSP_BRUSH: return entity.HasComponent<BSPBrushComponent>();
|
||||
case SPRITE: return entity.HasComponent<SpriteComponent>();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Nuake::SceneNetAPI::RegisterMethods()
|
||||
{
|
||||
RegisterMethod("Entity.EntityHasComponentIcall", &EntityHasComponent);
|
||||
RegisterMethod("Scene.GetEntityIcall", &GetEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
14
Nuake/src/Scripting/NetModules/SceneNetAPI.h
Normal file
14
Nuake/src/Scripting/NetModules/SceneNetAPI.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "NetAPIModule.h"
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
class SceneNetAPI : public NetAPIModule
|
||||
{
|
||||
public:
|
||||
virtual const std::string GetModuleName() const override { return "Scene"; }
|
||||
|
||||
virtual void RegisterMethods() override;
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user