mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Added Wren scene module ⛏
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
groups="screen"
|
||||
color="25 25 25 9"
|
||||
>
|
||||
<p groups="hello">Hello, world</p>
|
||||
<p groups="header">Hello, world!</p>
|
||||
|
||||
<Rect onclick="hello()"
|
||||
groups="rect"
|
||||
color="128 128 255 255">
|
||||
</Rect>
|
||||
<Slider value="sliderValue"/>
|
||||
</Canvas>
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
construct new(id) {
|
||||
_entityId = id
|
||||
}
|
||||
|
||||
HasComponent(component) {
|
||||
return Scene.EntityHasComponent(_entityId, component)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)")
|
||||
}
|
||||
}
|
||||
78
Nuake/src/Scripting/Modules/SceneModule.h
Normal file
78
Nuake/src/Scripting/Modules/SceneModule.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
#include "wren.h"
|
||||
#include <string>
|
||||
#include <src/Core/Logger.h>
|
||||
#include "ScriptModule.h"
|
||||
#include <iostream>
|
||||
#include <wren.h>
|
||||
#include "Engine.h"
|
||||
#include "../Scene/Entities/Entity.h"
|
||||
#include <src/Scene/Entities/Components/TransformComponent.h>
|
||||
#include <src/Scene/Entities/Components/LightComponent.h>
|
||||
#include <src/Scene/Entities/Components/QuakeMap.h>
|
||||
#include <src/Scene/Entities/Components/CameraComponent.h>
|
||||
#include <src/Scene/Entities/Components/RigidbodyComponent.h>
|
||||
|
||||
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<TransformComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
if (name == "Light")
|
||||
{
|
||||
bool result = ent.HasComponent<LightComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
if (name == "QuakeMap")
|
||||
{
|
||||
bool result = ent.HasComponent<QuakeMapComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
if (name == "Camera")
|
||||
{
|
||||
bool result = ent.HasComponent<CameraComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
if (name == "Script")
|
||||
{
|
||||
bool result = ent.HasComponent<CameraComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
if (name == "Rigidbody")
|
||||
{
|
||||
bool result = ent.HasComponent<RigidBodyComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "../Core/FileSystem.h"
|
||||
#include <src/Scripting/Modules/ScriptModule.h>
|
||||
#include <src/Scripting/Modules/EngineModule.h>
|
||||
#include <src/Scripting/Modules/SceneModule.h>
|
||||
WrenVM* ScriptingEngine::m_WrenVM;
|
||||
|
||||
|
||||
@@ -88,6 +89,8 @@ void ScriptingEngine::Init()
|
||||
|
||||
Ref<ScriptAPI::EngineModule> engineModule = CreateRef<ScriptAPI::EngineModule>();
|
||||
RegisterModule(engineModule);
|
||||
Ref<ScriptAPI::SceneModule> sceneModule = CreateRef<ScriptAPI::SceneModule>();
|
||||
RegisterModule(sceneModule);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user