Better testscene

This commit is contained in:
2026-03-29 13:18:13 +02:00
parent 1fdb223f5d
commit 3f462d3482
27 changed files with 3714 additions and 3036 deletions

View File

@@ -1,8 +1,8 @@
-- ============================================================================
-- scene.lua - Scene-level script for the PSXSplash test scene
-- ============================================================================
-- Tests: onSceneCreationStart, onSceneCreationEnd, onTriggerEnter/Exit (scene),
-- Persist, UI, Audio, Controls, Cutscene, Scene, Timer, Debug, PSXMath
-- Tests: onSceneCreationStart, onSceneCreationEnd, Persist, UI, Audio,
-- Controls, Cutscene, Scene, Timer, Debug, PSXMath, Vec3
-- HUD handles (resolved in onSceneCreationEnd)
local hudCanvas = -1
@@ -48,17 +48,17 @@ function onSceneCreationEnd()
UI.SetCanvasVisible(dialogueCanvas, false)
end
-- Play ambient looping cutscene (tests loop feature)
-- Play ambient looping cutscene
Cutscene.Play("ambient_spin", {loop = true})
-- Test PSXMath functions
-- Test PSXMath functions (all integer args)
local clamped = PSXMath.Clamp(150, 0, 100)
local lerped = PSXMath.Lerp(0, 10, 1)
local lerped = PSXMath.Lerp(0, 10, 1/2)
local sign = PSXMath.Sign(-42)
local abs = PSXMath.Abs(-7)
local mn = PSXMath.Min(3, 5)
local mx = PSXMath.Max(3, 5)
Debug.Log("PSXMath tests: clamp=" .. clamped .. " lerp=" .. lerped
Debug.Log("PSXMath: clamp=" .. clamped .. " lerp=" .. lerped
.. " sign=" .. sign .. " abs=" .. abs .. " min=" .. mn .. " max=" .. mx)
-- Test Vec3 functions
@@ -67,55 +67,17 @@ function onSceneCreationEnd()
local c = Vec3.add(a, b)
local d = Vec3.cross(a, b)
local dist = Vec3.distance(a, b)
Debug.Log("Vec3 tests: add=" .. c.x .. "," .. c.y .. "," .. c.z
Debug.Log("Vec3: add=" .. c.x .. "," .. c.y .. "," .. c.z
.. " cross=" .. d.x .. "," .. d.y .. "," .. d.z
.. " dist=" .. dist)
end
-- ============================================================================
-- Scene-level trigger callbacks (PSXTriggerBox)
-- ============================================================================
function onTriggerEnter(triggerIndex)
Debug.Log("Trigger entered: " .. triggerIndex)
if triggerIndex == 0 then
-- Trigger 0: Cutscene zone
setStatus("Cutscene playing...")
Controls.SetEnabled(false)
Cutscene.Play("camera_flyover", {
onComplete = function()
Controls.SetEnabled(true)
setStatus("Cutscene complete!")
end
})
elseif triggerIndex == 1 then
-- Trigger 1: Damage zone
health = PSXMath.Clamp(health - 25, 0, 100)
updateHealthBar()
setStatus("Ouch! Health: " .. health)
if health <= 0 then
setStatus("You died! Reloading...")
Controls.SetEnabled(false)
Persist.Set("score", 0)
Scene.Load(Scene.GetIndex())
end
elseif triggerIndex == 2 then
-- Trigger 2: Scene transition portal
setStatus("Loading next scene...")
Persist.Set("came_from", Scene.GetIndex())
Scene.Load(0) -- Reload scene 0 as demo
end
end
function onTriggerExit(triggerIndex)
Debug.Log("Trigger exited: " .. triggerIndex)
if triggerIndex == 0 then
setStatus("Left cutscene zone")
elseif triggerIndex == 1 then
setStatus("Escaped damage zone")
end
local scaled = Vec3.mul(a, 3)
local dotVal = Vec3.dot(a, b)
local lenSq = Vec3.lengthSq(Vec3.new(3, 4, 0))
local norm = Vec3.normalize(Vec3.new(0, 5, 0))
Debug.Log("Vec3: mul=" .. scaled.x .. "," .. scaled.y .. "," .. scaled.z
.. " dot=" .. dotVal .. " lenSq=" .. lenSq
.. " norm=" .. norm.x .. "," .. norm.y .. "," .. norm.z)
end
-- ============================================================================
@@ -163,7 +125,27 @@ function isInDialogue()
end
-- ============================================================================
-- Helpers
-- Health system (called from trigger scripts)
-- ============================================================================
function applyDamage(amount)
health = PSXMath.Clamp(health - amount, 0, 100)
updateHealthBar()
if health <= 0 then
setStatus("You died! Reloading...")
Controls.SetEnabled(false)
Persist.Set("score", 0)
Scene.Load(Scene.GetIndex())
end
end
function applyHeal(amount)
health = PSXMath.Clamp(health + amount, 0, 100)
updateHealthBar()
end
-- ============================================================================
-- Helpers (globals accessible from other scripts)
-- ============================================================================
function updateScoreDisplay()
@@ -176,6 +158,13 @@ end
function updateHealthBar()
if healthBar >= 0 then
UI.SetProgress(healthBar, health)
if health > 50 then
UI.SetProgressColors(healthBar, 0, 40, 0, 0, 255, 0)
elseif health > 25 then
UI.SetProgressColors(healthBar, 40, 40, 0, 255, 255, 0)
else
UI.SetProgressColors(healthBar, 40, 0, 0, 255, 0, 0)
end
end
end
@@ -191,3 +180,21 @@ function addScore(amount)
Persist.Set("score", score)
updateScoreDisplay()
end
-- ============================================================================
-- Export shared functions to _G so per-object scripts can call them.
-- Each script gets its own environment with __index = _G as fallback.
-- Functions defined here live in the scene's environment, not _G itself,
-- so we must explicitly publish them.
-- ============================================================================
_G.setStatus = setStatus
_G.addScore = addScore
_G.startDialogue = startDialogue
_G.advanceDialogue = advanceDialogue
_G.isInDialogue = isInDialogue
_G.endDialogue = endDialogue
_G.applyDamage = applyDamage
_G.applyHeal = applyHeal
_G.updateScoreDisplay = updateScoreDisplay
_G.updateHealthBar = updateHealthBar