mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Major scripting update🕹
- Added Input wren module - Added Math wren module - Added Entity wren module - Changed camera API
This commit is contained in:
@@ -1,26 +1,10 @@
|
||||
import "Scripts/Math" for Vector3
|
||||
|
||||
class Engine {
|
||||
foreign static Log(msg)
|
||||
}
|
||||
|
||||
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 {
|
||||
construct new(id) {
|
||||
_entityId = id
|
||||
}
|
||||
|
||||
HasComponent(component) {
|
||||
return Scene.EntityHasComponent(_entityId, component)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
70
Editor/resources/Scripts/Input.wren
Normal file
70
Editor/resources/Scripts/Input.wren
Normal file
@@ -0,0 +1,70 @@
|
||||
import "Scripts/Math" for Vector3
|
||||
import "Scripts/Engine" for Engine
|
||||
class Input {
|
||||
foreign static GetMouseX()
|
||||
foreign static GetMouseY()
|
||||
|
||||
// Gets the mouse position of X & Y and returns a Vector3
|
||||
static GetMousePos() {
|
||||
var result = Vector3.new(this.GetMouseX_(), this.GetMouseY_(), 0)
|
||||
return result
|
||||
}
|
||||
|
||||
// Keys
|
||||
foreign static IsKeyDown_(key)
|
||||
static IsKeyDown(key) {
|
||||
if(key is Num) {
|
||||
return this.IsKeyDown_(key)
|
||||
}
|
||||
Engine.Log("IsKeyDown expects a number. Got: %(key.type)")
|
||||
}
|
||||
|
||||
foreign static IsKeyPressed_(key)
|
||||
static IsKeyPressed(key) {
|
||||
if(key is Num){
|
||||
return this.IsKeyPressed_(key)
|
||||
}
|
||||
|
||||
Engine.Log("IsKeyPressed expects a number. Got: %(key.type)")
|
||||
}
|
||||
|
||||
foreign static IsKeyReleased_(key)
|
||||
static IsKeyReleased(key) {
|
||||
if(key is Num) {
|
||||
return this.IsKeyReleased_(key)
|
||||
}
|
||||
|
||||
Engine.Log("IsKeyReleased expects a number. Got: %(key.type)")
|
||||
}
|
||||
|
||||
// Mouse
|
||||
foreign static IsMouseButtonDown_(button)
|
||||
static IsMouseButtonDown(button) {
|
||||
if(button is Num){
|
||||
return this.IsMouseButtonDown_(button)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreign static IsMouseButtonPressed_(button)
|
||||
static IsMouseButtonPressed(button) {
|
||||
if(button is Num) {
|
||||
Engine.Log("IsmouseButtonPressed: %(button)")
|
||||
return this.IsMouseButtonPressed_(button)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreign static IsMouseButtonReleased_(button)
|
||||
static IsMouseButtonReleased(button) {
|
||||
if(button is Num){
|
||||
return this.IsMouseButtonReleased_(button)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreign static HideMouse()
|
||||
foreign static ShowMouse()
|
||||
foreign static IsMouseHidden()
|
||||
|
||||
}
|
||||
23
Editor/resources/Scripts/Math.wren
Normal file
23
Editor/resources/Scripts/Math.wren
Normal file
@@ -0,0 +1,23 @@
|
||||
class Math {
|
||||
foreign static Sqrt_(x, y, z)
|
||||
}
|
||||
|
||||
class Vector3 {
|
||||
construct new(x, y, z) {
|
||||
_x = x
|
||||
_y = y
|
||||
_z = z
|
||||
}
|
||||
|
||||
Sqrt() {
|
||||
return Math.Sqrt_(_x, _y, _z)
|
||||
}
|
||||
|
||||
Normalize() {
|
||||
var length = this.Sqrt()
|
||||
var x = _x / length
|
||||
var y = _y / length
|
||||
var z = _z / length
|
||||
return Vector3.new(x, y, z)
|
||||
}
|
||||
}
|
||||
126
Editor/resources/Scripts/Scene.wren
Normal file
126
Editor/resources/Scripts/Scene.wren
Normal file
@@ -0,0 +1,126 @@
|
||||
import "Scripts/Engine" for Engine
|
||||
|
||||
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)
|
||||
|
||||
// Component specific private setter and getter.
|
||||
foreign static GetLightIntensity_(e)
|
||||
foreign static SetLightIntensity_(e, intensity)
|
||||
|
||||
|
||||
/*
|
||||
// Transform
|
||||
foreign static SetTranslation_(e, x, y, z)
|
||||
foreign static SetRotation_(e, x, y, z)
|
||||
foreign static SetScale_(e, x, y, z)
|
||||
|
||||
// Character controller
|
||||
foreign static SetVelocity(e, x, y, z)
|
||||
foreign static SetStepHeight(e, x, y, z)
|
||||
foreign static IsOnGround(e)
|
||||
*/
|
||||
// Light
|
||||
//
|
||||
/*
|
||||
foreign static SetLightIsVolumetric_(e, bool)
|
||||
foreign static SetLightSyncDirectionWithSky_(e, bool)
|
||||
foreign static SetLightColor_(e, r, g, b)
|
||||
|
||||
// Camera
|
||||
foreign static SetCameraFov_(e, fov)
|
||||
foreign static SetCameraType(e, type)
|
||||
foreign static SetCameraDirection_(e, x, y, z)
|
||||
*/
|
||||
}
|
||||
|
||||
class Entity {
|
||||
construct new(id) {
|
||||
_entityId = id
|
||||
}
|
||||
|
||||
HasComponent(component) {
|
||||
return Scene.EntityHasComponent(_entityId, component)
|
||||
}
|
||||
|
||||
GetComponent(component) {
|
||||
if(this.HasComponent(component) == false) {
|
||||
Engine.Log("Tried getting a non-existent component of type: %(component) on entity with id: %(_entityId)")
|
||||
return
|
||||
}
|
||||
|
||||
if (component == "Light") {
|
||||
return Light.new(_entityId)
|
||||
}
|
||||
}
|
||||
|
||||
// Foreign engine functions
|
||||
/*
|
||||
// Transform
|
||||
foreign static SetTranslation_(e, x, y, z)
|
||||
foreign static SetRotation_(e, x, y, z)
|
||||
foreign static SetScale_(e, x, y, z)
|
||||
|
||||
// Character controller
|
||||
foreign static SetVelocity(e, x, y, z)
|
||||
foreign static SetStepHeight(e, x, y, z)
|
||||
foreign static IsOnGround(e)
|
||||
*/
|
||||
// Light
|
||||
//
|
||||
/*
|
||||
foreign static SetLightIsVolumetric_(e, bool)
|
||||
foreign static SetLightSyncDirectionWithSky_(e, bool)
|
||||
foreign static SetLightColor_(e, r, g, b)
|
||||
|
||||
// Camera
|
||||
foreign static SetCameraFov_(e, fov)
|
||||
foreign static SetCameraType(e, type)
|
||||
foreign static SetCameraDirection_(e, x, y, z)
|
||||
*/
|
||||
}
|
||||
|
||||
class Light {
|
||||
construct new(id) {
|
||||
_entityId = id
|
||||
}
|
||||
|
||||
|
||||
SetIntensity(intensity) {
|
||||
Scene.SetLightIntensity_(_entityId, intensity)
|
||||
}
|
||||
|
||||
GetIntensity() {
|
||||
return Scene.GetLightIntensity_(_entityId)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
SetType(type) {
|
||||
this.SetType_(_entityId, type)
|
||||
}
|
||||
|
||||
SetColor(color) {
|
||||
this.SetColor_(_entityId, color.r, color.g, color.b, color.a)
|
||||
}
|
||||
|
||||
SetDirection(direction) {
|
||||
var normalized = direction.Normalize()
|
||||
this.SetDirection_(_entityId, normalized.x, normalized.y, normalized.z)
|
||||
}
|
||||
|
||||
foreign static SetType_(id, type)
|
||||
foreign static SetColor_(id, r, g, b)
|
||||
|
||||
foreign static SetDirection_(id, x, y, z)
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import "Scripts/Engine" for Engine, Scene, Entity
|
||||
import "Scripts/Engine" for Engine
|
||||
import "Scripts/Input" for Input
|
||||
import "Scripts/Scene" for Scene, Entity
|
||||
|
||||
class Test {
|
||||
init() {
|
||||
System.print("hello init")
|
||||
@@ -13,10 +16,12 @@ class Test {
|
||||
}
|
||||
|
||||
static hello() {
|
||||
var entity = Scene.GetEntity("Trenchbroom map")
|
||||
var hasTransform = entity.HasComponent("Transform")
|
||||
var hasLight = entity.HasComponent("Light")
|
||||
var entity = Scene.GetEntity("Light")
|
||||
var light = entity.GetComponent("Light")
|
||||
light.SetIntensity(1.0)
|
||||
|
||||
Engine.Log("trasnform: %(hasTransform) light:%(hasLight)")
|
||||
if(Input.IsMouseButtonPressed(2) == true) {
|
||||
Engine.Log("RIGHT CLICK!!!!!!")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user