Refactored folder structure

This commit is contained in:
antopilo
2025-01-31 18:04:43 -05:00
parent a4e7e7d530
commit 1f3a5e02af
313 changed files with 2350 additions and 674 deletions

4
Data/Scripts/Audio.wren Normal file
View File

@@ -0,0 +1,4 @@
class Audio {
foreign static PlayAudio(audioFile)
}

10
Data/Scripts/Engine.wren Normal file
View File

@@ -0,0 +1,10 @@
import "Nuake:Math" for Vector3
class Engine {
foreign static Log(msg)
}

194
Data/Scripts/Input.wren Normal file
View File

@@ -0,0 +1,194 @@
import "Nuake:Math" for Vector3
import "Nuake:Engine" for Engine
class Keys {
static SPACE { 32 }
static APOSTROPHE { 39 } /* ' */
static COMMA { 44 } /* } */
static MINUS { 5 } /* - */
static PERIOD { 46 } /* . */
static SLASH { 47 } /* / */
static NUM0 { 48 }
static NUM1 { 49 }
static NUM2 { 50 }
static NUM3 { 51 }
static NUM4 { 52 }
static NUM5 { 53 }
static NUM6 { 54 }
static NUM7 { 55 }
static NUM8 { 56 }
static NUM9 { 57 }
static SEMICOLON { 59 } /* ; */
static EQUAL { 61 } /* { */
static A { 65 }
static B { 66 }
static C { 67 }
static D { 68 }
static E { 69 }
static F { 70 }
static G { 71 }
static H { 72 }
static I { 73 }
static J { 74 }
static K { 75 }
static L { 76 }
static M { 77 }
static N { 78 }
static O { 79 }
static P { 80 }
static Q { 81 }
static R { 82 }
static S { 83 }
static T { 84 }
static U { 85 }
static V { 86 }
static W { 87 }
static X { 88 }
static Y { 89 }
static Z { 90 }
static LEFT_BRACKET { 91 } /* [ */
static BACKSLASH { 92 } /* \ */
static RIGHT_BRACKET { 93 } /* ] */
static GRAVE_ACCENT { 96 } /* ` */
static WORLD_1 { 161 }/* non-US #1 */
static WORLD_2 { 162 }/* non-US #2 */
static ESCAPE { 256 }
static ENTER { 257 }
static TAB { 258 }
static BACKSPACE { 259 }
static INSERT { 260 }
static DELETE { 261 }
static RIGHT { 262 }
static LEFT { 263 }
static DOWN { 264 }
static UP { 265 }
static PAGE_UP { 266 }
static PAGE_DOWN { 267 }
static HOME { 268 }
static END { 269 }
static CAPS_LOCK { 280 }
static SCROLL_LOCK { 281 }
static NUM_LOCK { 282 }
static PRINT_SCREEN { 283 }
static PAUSE { 284 }
static F1 { 290 }
static F2 { 291 }
static F3 { 292 }
static F4 { 293 }
static F5 { 294 }
static F6 { 295 }
static F7 { 296 }
static F8 { 297 }
static F9 { 298 }
static F10 { 299 }
static F11 { 300 }
static F12 { 301 }
static F13 { 302 }
static F14 { 303 }
static F15 { 304 }
static F16 { 305 }
static F17 { 306 }
static F18 { 307 }
static F19 { 308 }
static F20 { 309 }
static F21 { 310 }
static F22 { 311 }
static F23 { 312 }
static F24 { 313 }
static F25 { 314 }
static KP_0 { 320 }
static KP_1 { 321 }
static KP_2 { 322 }
static KP_3 { 323 }
static KP_4 { 324 }
static KP_5 { 325 }
static KP_6 { 326 }
static KP_7 { 327 }
static KP_8 { 328 }
static KP_9 { 329 }
static KP_DECIMAL { 330 }
static KP_DIVIDE { 331 }
static KP_MULTIPLY { 332 }
static KP_SUBTRACT { 333 }
static KP_ADD { 334 }
static KP_ENTER { 335 }
static KP_EQUAL { 336 }
static LEFT_SHIFT { 340 }
static LEFT_CONTROL { 341 }
static LEFT_ALT { 342 }
static LEFT_SUPER { 343 }
static RIGHT_SHIFT { 344 }
static RIGHT_CONTROL { 345 }
static RIGHT_ALT { 346 }
static RIGHT_SUPER { 347 }
static MENU { 348 }
}
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()
}

136
Data/Scripts/Math.wren Normal file
View File

@@ -0,0 +1,136 @@
class Math {
foreign static Sqrt_(x, y, z)
foreign static Sin(s)
foreign static Cos(s)
foreign static Radians(s)
foreign static Degrees(s)
static Cross(vec1, vec2) {
var result = this.Cross_(vec1.x, vec1.y, vec1.z, vec2.x, vec2.y, vec2.z)
return Vector3.new(result[0], result[1], result[2])
}
static Dot(vec1, vec2) {
return this.Dot_(vec1.x, vec1.y, vec1.z, vec2.x, vec2.y, vec2.z)
}
static Lerp(a, b, t) {
return a + t * (b - a)
}
foreign static Dot_(x, y, z, x1, y2, z2)
foreign static Cross_(x, y, z, x1, y2, z2)
foreign static Length_(x, y, z)
}
class Vector3 {
x {_x}
y {_y}
z {_z}
x=(value) {
_x = value
}
y=(value) {
_y = value
}
z=(value) {
_z = value
}
mul(other) {
if(other is Vector3) {
return Vector3.new(_x * other.x,
_y * other.y,
_z * other.z)
} else {
return Vector3.new(_x * other, _y * other, _z * other)
}
}
*(other) {
if(other is Vector3) {
return Vector3.new(_x * other.x,
_y * other.y,
_z * other.z)
} else if(other is Num) {
return Vector3.new(_x * other, _y * other, _z * other)
}
}
/(other) {
if(other is Vector3) {
return Vector3.new(_x / other.x,
_y / other.y,
_z / other.z)
} else if(other is Num) {
return Vector3.new(_x / other, _y / other, _z / other)
}
}
+(other) {
if(other is Vector3) {
return Vector3.new(_x + other.x,
_y + other.y,
_z + other.z)
} else if(other is Num) {
return Vector3.new(_x + other,
_y + other,
_z + other)
}
}
-(other) {
if(other is Vector3) {
return Vector3.new(_x - other.x,
_y - other.y,
_z - other.z)
} else if(other is Num) {
return Vector3.new(_x - other,
_y - other,
_z - other)
}
}
construct new(x, y, z) {
_x = x
_y = y
_z = z
}
Duplicate() {
return Vector3.new(_x, _y, _z)
}
Sqrt() {
return Math.Sqrt_(_x, _y, _z)
}
Cross(vec) {
return Math.Cross(this, vec)
}
Normalize() {
var length = this.Length()
if(length > 0.0) {
var x = _x / length
var y = _y / length
var z = _z / length
return Vector3.new(x, y, z)
}
return Vector3.new(0, 0, 0)
}
Angle(vec) {
this.Normalize() * vec.Normalize()
}
Dot(vec) {
return Math.Dot(this, vec)
}
Length() {
return Math.Length_(_x, _y, _z)
}
}

28
Data/Scripts/Physics.wren Normal file
View File

@@ -0,0 +1,28 @@
import "Nuake:Math" for Vector3
class CollisionResult {
LocalPosition { _Local}
WorldPosition { _World}
Normal { _Normal}
construct new(l, w, n) {
_Local = l
_World = w
_Normal = n
}
}
class Physics {
foreign static Raycast_(x, y, z, x2, y2, z2)
static Raycast(v1, v2) {
var result = this.Raycast_(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z)
var local = Vector3.new(result[0], result[1], result[2])
var world = Vector3.new(result[3], result[4], result[5])
var normal = Vector3.new(result[6], result[7], result[8])
return CollisionResult.new(local, world, normal)
}
}

292
Data/Scripts/Scene.wren Normal file
View File

@@ -0,0 +1,292 @@
import "Nuake:Engine" for Engine
import "Nuake:Math" for Vector3
class Scene {
foreign static GetEntityID(name)
foreign static CreateEntity(name)
foreign static AddPrefab(prefabPath)
static GetEntity(name) {
var entId = Scene.GetEntityID(name)
var ent = Entity.new(entId)
return ent
}
foreign static EntityHasComponent(id, name)
static EntityGetComponent(id, component) {
if(this.EntityHasComponent(id, component) == false) {
Engine.Log("Tried getting a non-existent component of type: %(component) on entity with id: %(id)")
return
}
if (component == "Light") {
return Light.new(id)
} else if (component == "CharacterController") {
return CharacterController.new(id)
} else if (component == "RigidBody") {
return RigidBody.new(id)
} else if (component == "Camera") {
return Camera.new(id)
} else if (component == "Transform") {
return TransformComponent.new(id)
} else if (component == "Script") {
return this.GetScript_(id)
} else if (component == "Trigger") {
return Trigger.new(id)
} else if (component == "Brush") {
return Brush.new(id)
} else if (component == "AudioEmitter") {
return AudioEmitter.new(id)
}
}
//
// Components
//
// Transform
foreign static GetScript_(e)
foreign static GetLocalTranslation_(e)
foreign static GetTranslation_(e)
foreign static SetTranslation_(e, x, y, z)
foreign static SetRotation_(e, x, y, z)
foreign static SetLookAt_(e, x, y, z)
foreign static GetRotation_(e)
//foreign static SetScale_(e, x, y, z)
// Light
foreign static GetLightIntensity_(e) // returns a float
foreign static SetLightIntensity_(e, intensity)
//foreign static SetLightIsVolumetric_(e, bool)
//foreign static SetLightSyncDirectionWithSky_(e, bool)
//foreign static SetLightColor_(e, r, g, b)
//foreign static GetLightColor_(e)
// Camera
foreign static SetCameraDirection_(e, x, y, z)
foreign static GetCameraDirection_(e) // returns a list x,y,z
foreign static GetCameraRight_(e) // returns a list x,y,z
//foreign static SetcameraFov(e, fov)
//foreign static GetCameraFov(e) // returns a float
// Audio Emitter
foreign static SetAudioEmitterPlaying_(e, playing)
// Character controller
foreign static MoveAndSlide_(e, x, y, z)
foreign static IsCharacterControllerOnGround_(e)
//foreign static IsOnGround_(e)
// RigidBody
foreign static AddForce_(e, x, y, z)
// Physics
static RayCast(from, to) {
// Fetch results from physics manager, returns a list of floats
// that we need to unpack into vector3
var results = Scene.RayCast_(from.x, from.y, from.z, to.x, to.y, to.z)
var points = [] // Result array of vec3
var size = results.count / 3
var i = 0
while(i < size) {
// size is base 1 while array is base 0, offset by 1
var listIndex = i - 1
points.add(Vector3.new(results[listIndex], results[listIndex + 1], results[listIndex + 2]))
i = i + 1
}
return points
}
foreign static RayCast_(fromX, fromY, fromZ, toX, toY, toZ)
foreign static TriggerGetOverlappingBodyCount_(e)
foreign static TriggerGetOverlappingBodies_(e)
foreign static BrushGetTargets_(e)
foreign static BrushGetTargetsCount_(e)
}
class Entity {
construct new(id) {
_entityId = id
}
HasComponent(component) {
return Scene.EntityHasComponent(_entityId, component)
}
GetComponent(component) {
return Scene.EntityGetComponent(_entityId, component)
}
}
class TransformComponent {
construct new(id) {
_entityId = id
}
GetLocalTranslation() {
var result = Scene.GetLocalTranslation_(_entityId)
return Vector3.new(result[0], result[1], result[2])
}
GetTranslation() {
var result = Scene.GetTranslation_(_entityId)
return Vector3.new(result[0], result[1], result[2])
}
SetTranslation(t) {
Scene.SetTranslation_(_entityId, t.x, t.y, t.z)
}
SetTranslation(x, y, z) {
Scene.SetTranslation_(_entityId, x, y, z)
}
GetRotation() {
var result = Scene.GetRotation_(_entityId)
return Vector3.new(result[0], result[1], result[2])
}
SetRotation(t) {
Scene.SetRotation_(_entityId, t.x, t.y, t.z)
}
SetLookAt(t) {
Scene.SetLookAt_(_entityId, t.x, t.y, t.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)
}*/
}
class CharacterController {
construct new(id) {
_entityId = id
}
MoveAndSlide(vel) {
Scene.MoveAndSlide_(_entityId, vel.x, vel.y, vel.z)
}
IsOnGround() {
return Scene.IsCharacterControllerOnGround_(_entityId)
}
}
class RigidBody {
construct new(id) {
_entityId = id
}
AddForce(force) {
Scene.AddForce_(_entityId, force.x, force.y, force.z)
}
}
class Camera {
construct new(id) {
_entityId = id
}
SetDirection(dir) {
Scene.SetCameraDirection_(_entityId, dir.x, dir.y, dir.z)
}
GetDirection() {
var dir = Scene.GetCameraDirection_(_entityId)
return Vector3.new(dir[0], dir[1], dir[2])
}
GetRight() {
var dir = Scene.GetCameraRight_(_entityId)
return Vector3.new(dir[0], dir[1], dir[2])
}
}
class AudioEmitter {
construct new(id) {
_entityId = id
}
SetPlaying(playing) {
Scene.SetAudioEmitterPlaying_(_entityId, playing)
}
}
class Trigger {
construct new(id) {
_entityId = id
}
GetOverlappingBodyCount() {
return Scene.TriggerGetOverlappingBodyCount_(_entityId)
}
GetOverlappingBodies() {
if(this.GetOverlappingBodyCount() <= 0) {
return []
}
var bodies = Scene.TriggerGetOverlappingBodies_(_entityId)
var entities = []
for(b in bodies) {
entities.add(Entity.new(b))
}
return entities
}
}
class Brush {
construct new(id) {
_entityId = id
}
GetTargetsCount() {
return Scene.BrushGetTargetsCount_(_entityId)
}
GetTargets() {
if(this.GetTargetsCount() <= 0) {
return []
}
var entities = []
var targets = Scene.BrushGetTargets_(_entityId)
for(t in targets) {
entities.add(Entity.new(t))
}
return entities
}
}

View File

@@ -0,0 +1,15 @@
import "Nuake:Scene" for Scene
class ScriptableEntity {
SetEntityId(id) {
_EntityID = id
}
GetComponent(component) {
return Scene.EntityGetComponent(_EntityID, component)
}
HasComponent(component) {
return Scene.EntityHasComponent(_EntityID, component)
}
}