diff --git a/Editor/resources/Interface/Testing.interface b/Editor/resources/Interface/Testing.interface index c12e00d1..90534fc3 100644 --- a/Editor/resources/Interface/Testing.interface +++ b/Editor/resources/Interface/Testing.interface @@ -3,10 +3,10 @@ groups="screen" color="25 25 25 9" > -

Hello, world

+

Hello, world!

+ - diff --git a/Editor/resources/Scripts/Engine.wren b/Editor/resources/Scripts/Engine.wren index 4ccbd944..8129176e 100644 --- a/Editor/resources/Scripts/Engine.wren +++ b/Editor/resources/Scripts/Engine.wren @@ -2,14 +2,25 @@ class Engine { foreign static Log(msg) } -class Vector3 { - construct new(x, y, z) { - _x = x - _y = y - _z = z +class Scene { + foreign static GetEntityID(name) + + static GetEntity(name) { + var entId = Scene.GetEntityID(name) + var ent = Entity.new(entId) + return ent } + + foreign static EntityHasComponent(id, name) } class Entity { - foreign GetComponent(type) -} \ No newline at end of file + construct new(id) { + _entityId = id + } + + HasComponent(component) { + return Scene.EntityHasComponent(_entityId, component) + } +} + diff --git a/Editor/resources/Scripts/test.wren b/Editor/resources/Scripts/test.wren index fc35bfea..aef4f421 100644 --- a/Editor/resources/Scripts/test.wren +++ b/Editor/resources/Scripts/test.wren @@ -1,4 +1,4 @@ -import "Scripts/Engine" for Engine +import "Scripts/Engine" for Engine, Scene, Entity class Test { init() { System.print("hello init") @@ -13,6 +13,10 @@ class Test { } static hello() { - Engine.Log("Hello from foreign") + var entity = Scene.GetEntity("Trenchbroom map") + var hasTransform = entity.HasComponent("Transform") + var hasLight = entity.HasComponent("Light") + + Engine.Log("trasnform: %(hasTransform) light:%(hasLight)") } } \ No newline at end of file diff --git a/Nuake/src/Scripting/Modules/SceneModule.h b/Nuake/src/Scripting/Modules/SceneModule.h new file mode 100644 index 00000000..624e9c66 --- /dev/null +++ b/Nuake/src/Scripting/Modules/SceneModule.h @@ -0,0 +1,78 @@ +#pragma once +#include "wren.h" +#include +#include +#include "ScriptModule.h" +#include +#include +#include "Engine.h" +#include "../Scene/Entities/Entity.h" +#include +#include +#include +#include +#include + +namespace ScriptAPI +{ + + + class SceneModule : public ScriptModule + { + std::string GetModuleName() override + { + return "Scene"; + } + + void RegisterModule(WrenVM* vm) override + { + RegisterMethod("GetEntityID(_)", (void*)GetEntity); + RegisterMethod("EntityHasComponent(_,_)", (void*)EntityHasComponent); + } + + static void GetEntity(WrenVM* vm) + { + std::string name = wrenGetSlotString(vm, 1); + int handle = Engine::GetCurrentScene()->GetEntity(name).GetHandle(); + wrenSetSlotDouble(vm, 0, handle); + } + + static void EntityHasComponent(WrenVM* vm) + { + int handle = wrenGetSlotDouble(vm, 1); + std::string name = wrenGetSlotString(vm, 2); + Entity ent = Entity((entt::entity)handle, Engine::GetCurrentScene().get()); + + if (name == "Transform") + { + bool result = ent.HasComponent(); + wrenSetSlotBool(vm, 0, result); + } + if (name == "Light") + { + bool result = ent.HasComponent(); + wrenSetSlotBool(vm, 0, result); + } + if (name == "QuakeMap") + { + bool result = ent.HasComponent(); + wrenSetSlotBool(vm, 0, result); + } + if (name == "Camera") + { + bool result = ent.HasComponent(); + wrenSetSlotBool(vm, 0, result); + } + if (name == "Script") + { + bool result = ent.HasComponent(); + wrenSetSlotBool(vm, 0, result); + } + if (name == "Rigidbody") + { + bool result = ent.HasComponent(); + wrenSetSlotBool(vm, 0, result); + } + } + }; +} \ No newline at end of file diff --git a/Nuake/src/Scripting/ScriptingEngine.cpp b/Nuake/src/Scripting/ScriptingEngine.cpp index c88a0535..7e501b88 100644 --- a/Nuake/src/Scripting/ScriptingEngine.cpp +++ b/Nuake/src/Scripting/ScriptingEngine.cpp @@ -3,6 +3,7 @@ #include "../Core/FileSystem.h" #include #include +#include WrenVM* ScriptingEngine::m_WrenVM; @@ -88,6 +89,8 @@ void ScriptingEngine::Init() Ref engineModule = CreateRef(); RegisterModule(engineModule); + Ref sceneModule = CreateRef(); + RegisterModule(sceneModule); }