lul
This commit is contained in:
36
Assets/lua/collectible.lua
Normal file
36
Assets/lua/collectible.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
-- ============================================================================
|
||||
-- collectible.lua - Pickup item
|
||||
-- ============================================================================
|
||||
-- Tests: onCreate, onDestroy, onCollideWithPlayer, onEnable, onDisable,
|
||||
-- Entity.SetActive, Audio.Play, Persist, self.active, self.position
|
||||
|
||||
local collected = false
|
||||
|
||||
function onCreate(self)
|
||||
collected = false
|
||||
Debug.Log("Collectible created at " .. self.position.x .. "," .. self.position.y .. "," .. self.position.z)
|
||||
end
|
||||
|
||||
function onDestroy(self)
|
||||
Debug.Log("Collectible destroyed")
|
||||
end
|
||||
|
||||
function onEnable(self)
|
||||
Debug.Log("Collectible enabled")
|
||||
end
|
||||
|
||||
function onDisable(self)
|
||||
Debug.Log("Collectible disabled")
|
||||
end
|
||||
|
||||
function onCollideWithPlayer(self)
|
||||
if collected then return end
|
||||
collected = true
|
||||
|
||||
Audio.Play("collect", 127, 64)
|
||||
|
||||
-- Update score via scene script global
|
||||
addScore(100)
|
||||
setStatus("Collected! +100 points")
|
||||
Entity.SetActive(self, false)
|
||||
end
|
||||
7
Assets/lua/collectible.lua.meta
Normal file
7
Assets/lua/collectible.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74b8a01f2dacabc49b55c1a6d224ba6d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/lua/door.lua
Normal file
38
Assets/lua/door.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
-- ============================================================================
|
||||
-- door.lua - Interactable door that plays an open cutscene
|
||||
-- ============================================================================
|
||||
-- Tests: onInteract, Cutscene.Play with onComplete, Entity.Find,
|
||||
-- Entity.SetActive, Controls, Audio
|
||||
|
||||
local isOpen = false
|
||||
|
||||
function onCreate(self)
|
||||
isOpen = false
|
||||
Debug.Log("Door created")
|
||||
end
|
||||
|
||||
function onInteract(self)
|
||||
if isOpen then
|
||||
setStatus("Door is already open")
|
||||
return
|
||||
end
|
||||
if Cutscene.IsPlaying() then return end
|
||||
|
||||
isOpen = true
|
||||
Audio.Play("door_open", 100, 64)
|
||||
Controls.SetEnabled(false)
|
||||
setStatus("Opening door...")
|
||||
|
||||
Cutscene.Play("door_open", {
|
||||
onComplete = function()
|
||||
Controls.SetEnabled(true)
|
||||
setStatus("Door opened! Path is clear.")
|
||||
|
||||
-- Disable the door blocker object
|
||||
local blocker = Entity.Find("DoorBlocker")
|
||||
if blocker then
|
||||
Entity.SetActive(blocker, false)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
7
Assets/lua/door.lua.meta
Normal file
7
Assets/lua/door.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c052148c52eaff418c6fcb2b3e3169e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Assets/lua/entity_scanner.lua
Normal file
34
Assets/lua/entity_scanner.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
-- ============================================================================
|
||||
-- entity_scanner.lua - Scans all entities on interact (Entity.ForEach test)
|
||||
-- ============================================================================
|
||||
-- Tests: Entity.ForEach, Entity.GetPosition, Entity.IsActive, Entity.GetCount,
|
||||
-- Entity.FindByIndex, onInteract
|
||||
|
||||
function onInteract(self)
|
||||
setStatus("Scanning all entities...")
|
||||
Debug.Log("=== Entity Scan ===")
|
||||
Debug.Log("Total entities: " .. Entity.GetCount())
|
||||
|
||||
local activeCount = 0
|
||||
local inactiveCount = 0
|
||||
|
||||
Entity.ForEach(function(obj)
|
||||
local pos = Entity.GetPosition(obj)
|
||||
local active = Entity.IsActive(obj)
|
||||
if active then
|
||||
activeCount = activeCount + 1
|
||||
else
|
||||
inactiveCount = inactiveCount + 1
|
||||
end
|
||||
end)
|
||||
|
||||
Debug.Log("Active: " .. activeCount .. " Inactive: " .. inactiveCount)
|
||||
setStatus("Scan: " .. activeCount .. " active, " .. inactiveCount .. " inactive")
|
||||
|
||||
-- Test FindByIndex
|
||||
local first = Entity.FindByIndex(0)
|
||||
if first then
|
||||
local pos = Entity.GetPosition(first)
|
||||
Debug.Log("Entity 0 at " .. pos.x .. "," .. pos.y .. "," .. pos.z)
|
||||
end
|
||||
end
|
||||
7
Assets/lua/entity_scanner.lua.meta
Normal file
7
Assets/lua/entity_scanner.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 546867c47b97ec14980a0766ec1b8781
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/lua/movable.lua
Normal file
43
Assets/lua/movable.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
-- ============================================================================
|
||||
-- movable.lua - Object that can be pushed with button presses
|
||||
-- ============================================================================
|
||||
-- Tests: onButtonPress, onButtonRelease, Entity.SetPosition, Vec3 math,
|
||||
-- Camera.GetPosition, Input constants, self.position
|
||||
|
||||
local pushing = false
|
||||
|
||||
function onCreate(self)
|
||||
pushing = false
|
||||
Debug.Log("Movable object created")
|
||||
end
|
||||
|
||||
function onButtonPress(self, button)
|
||||
if button == Input.SQUARE then
|
||||
pushing = true
|
||||
end
|
||||
end
|
||||
|
||||
function onButtonRelease(self, button)
|
||||
if button == Input.SQUARE then
|
||||
pushing = false
|
||||
end
|
||||
end
|
||||
|
||||
function onUpdate(self, dt)
|
||||
if not pushing then return end
|
||||
|
||||
-- Move toward the camera position (player) slowly
|
||||
local myPos = self.position
|
||||
local camPos = Camera.GetPosition()
|
||||
local dir = Vec3.sub(camPos, myPos)
|
||||
local dist = Vec3.length(dir)
|
||||
|
||||
if dist > 1 then
|
||||
local norm = Vec3.normalize(dir)
|
||||
local step = Vec3.mul(norm, dt)
|
||||
local newPos = Vec3.add(myPos, step)
|
||||
-- Keep Y the same (don't float)
|
||||
newPos.y = myPos.y
|
||||
Entity.SetPosition(self, newPos)
|
||||
end
|
||||
end
|
||||
7
Assets/lua/movable.lua.meta
Normal file
7
Assets/lua/movable.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75ac8896aea8c054cbad7aaada876d7a
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/lua/npc.lua
Normal file
40
Assets/lua/npc.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
-- ============================================================================
|
||||
-- npc.lua - NPC with multi-line dialogue
|
||||
-- ============================================================================
|
||||
-- Tests: onInteract, onButtonPress, Controls, UI text,
|
||||
-- scene-level dialogue system, Input constants
|
||||
|
||||
local talked = false
|
||||
|
||||
function onCreate(self)
|
||||
talked = false
|
||||
end
|
||||
|
||||
function onInteract(self)
|
||||
if isInDialogue() then return end
|
||||
|
||||
if not talked then
|
||||
talked = true
|
||||
startDialogue({
|
||||
"Hello, traveler!",
|
||||
"Welcome to the test scene.",
|
||||
"There are collectibles, a door,",
|
||||
"triggers, and a portal here.",
|
||||
"Press CROSS to advance dialogue.",
|
||||
"Good luck exploring!"
|
||||
})
|
||||
else
|
||||
startDialogue({
|
||||
"You again?",
|
||||
"Go find the collectibles!",
|
||||
"There should be three of them."
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function onButtonPress(self, button)
|
||||
if not isInDialogue() then return end
|
||||
if button == Input.CROSS then
|
||||
advanceDialogue()
|
||||
end
|
||||
end
|
||||
7
Assets/lua/npc.lua.meta
Normal file
7
Assets/lua/npc.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de833f331b443b149b403ce5e60009dc
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
193
Assets/lua/scene.lua
Normal file
193
Assets/lua/scene.lua
Normal file
@@ -0,0 +1,193 @@
|
||||
-- ============================================================================
|
||||
-- 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
|
||||
|
||||
-- HUD handles (resolved in onSceneCreationEnd)
|
||||
local hudCanvas = -1
|
||||
local scoreText = -1
|
||||
local statusText = -1
|
||||
local healthBar = -1
|
||||
local dialogueCanvas = -1
|
||||
local dialogueText = -1
|
||||
|
||||
-- State
|
||||
local health = 100
|
||||
local inDialogue = false
|
||||
local dialogueLines = {}
|
||||
local dialogueLine = 0
|
||||
|
||||
function onSceneCreationStart()
|
||||
Debug.Log("=== PSXSplash Test Scene ===")
|
||||
Debug.Log("Scene index: " .. Scene.GetIndex())
|
||||
|
||||
-- Restore score from previous scene (tests Persist)
|
||||
local score = Persist.Get("score") or 0
|
||||
Debug.Log("Loaded score from persist: " .. score)
|
||||
end
|
||||
|
||||
function onSceneCreationEnd()
|
||||
Debug.Log("Scene creation complete at frame " .. Timer.GetFrameCount())
|
||||
|
||||
-- Resolve UI handles
|
||||
hudCanvas = UI.FindCanvas("HUD")
|
||||
if hudCanvas >= 0 then
|
||||
scoreText = UI.FindElement(hudCanvas, "ScoreText")
|
||||
statusText = UI.FindElement(hudCanvas, "StatusText")
|
||||
healthBar = UI.FindElement(hudCanvas, "HealthBar")
|
||||
UI.SetCanvasVisible(hudCanvas, true)
|
||||
updateScoreDisplay()
|
||||
updateHealthBar()
|
||||
setStatus("Welcome! Explore the test room.")
|
||||
end
|
||||
|
||||
dialogueCanvas = UI.FindCanvas("Dialogue")
|
||||
if dialogueCanvas >= 0 then
|
||||
dialogueText = UI.FindElement(dialogueCanvas, "DialogueText")
|
||||
UI.SetCanvasVisible(dialogueCanvas, false)
|
||||
end
|
||||
|
||||
-- Play ambient looping cutscene (tests loop feature)
|
||||
Cutscene.Play("ambient_spin", {loop = true})
|
||||
|
||||
-- Test PSXMath functions
|
||||
local clamped = PSXMath.Clamp(150, 0, 100)
|
||||
local lerped = PSXMath.Lerp(0, 10, 1)
|
||||
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
|
||||
.. " sign=" .. sign .. " abs=" .. abs .. " min=" .. mn .. " max=" .. mx)
|
||||
|
||||
-- Test Vec3 functions
|
||||
local a = Vec3.new(1, 0, 0)
|
||||
local b = Vec3.new(0, 1, 0)
|
||||
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
|
||||
.. " 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
|
||||
end
|
||||
|
||||
-- ============================================================================
|
||||
-- Dialogue system (called from NPC scripts)
|
||||
-- ============================================================================
|
||||
|
||||
function startDialogue(lines)
|
||||
if inDialogue then return end
|
||||
inDialogue = true
|
||||
dialogueLines = lines
|
||||
dialogueLine = 1
|
||||
Controls.SetEnabled(false)
|
||||
showDialogueLine()
|
||||
end
|
||||
|
||||
function showDialogueLine()
|
||||
if dialogueCanvas >= 0 then
|
||||
UI.SetCanvasVisible(dialogueCanvas, true)
|
||||
if dialogueText >= 0 and dialogueLine <= #dialogueLines then
|
||||
UI.SetText(dialogueText, dialogueLines[dialogueLine])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function advanceDialogue()
|
||||
if not inDialogue then return end
|
||||
dialogueLine = dialogueLine + 1
|
||||
if dialogueLine > #dialogueLines then
|
||||
endDialogue()
|
||||
else
|
||||
showDialogueLine()
|
||||
end
|
||||
end
|
||||
|
||||
function endDialogue()
|
||||
inDialogue = false
|
||||
Controls.SetEnabled(true)
|
||||
if dialogueCanvas >= 0 then
|
||||
UI.SetCanvasVisible(dialogueCanvas, false)
|
||||
end
|
||||
end
|
||||
|
||||
function isInDialogue()
|
||||
return inDialogue
|
||||
end
|
||||
|
||||
-- ============================================================================
|
||||
-- Helpers
|
||||
-- ============================================================================
|
||||
|
||||
function updateScoreDisplay()
|
||||
if scoreText >= 0 then
|
||||
local score = Persist.Get("score") or 0
|
||||
UI.SetText(scoreText, "Score: " .. score)
|
||||
end
|
||||
end
|
||||
|
||||
function updateHealthBar()
|
||||
if healthBar >= 0 then
|
||||
UI.SetProgress(healthBar, health)
|
||||
end
|
||||
end
|
||||
|
||||
function setStatus(msg)
|
||||
Debug.Log("[Status] " .. msg)
|
||||
if statusText >= 0 then
|
||||
UI.SetText(statusText, msg)
|
||||
end
|
||||
end
|
||||
|
||||
function addScore(amount)
|
||||
local score = (Persist.Get("score") or 0) + amount
|
||||
Persist.Set("score", score)
|
||||
updateScoreDisplay()
|
||||
end
|
||||
7
Assets/lua/scene.lua.meta
Normal file
7
Assets/lua/scene.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ce0e258477fc2047bd97e1198b8a701
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/lua/spinner.lua
Normal file
25
Assets/lua/spinner.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
-- ============================================================================
|
||||
-- spinner.lua - Continuously rotating object (onUpdate demo)
|
||||
-- ============================================================================
|
||||
-- Tests: onUpdate, self.rotationY, Entity.GetRotationY, Entity.SetRotationY,
|
||||
-- Timer.GetFrameCount, self.position, Entity.GetPosition
|
||||
|
||||
local speed = 1 -- pi-units per frame
|
||||
|
||||
function onCreate(self)
|
||||
Debug.Log("Spinner created, initial rotY: " .. self.rotationY)
|
||||
end
|
||||
|
||||
function onUpdate(self, dt)
|
||||
-- Rotate the object by speed * dt each frame
|
||||
local current = Entity.GetRotationY(self)
|
||||
Entity.SetRotationY(self, current + speed * dt)
|
||||
|
||||
-- Every 300 frames, log position and rotation (test Timer)
|
||||
if Timer.GetFrameCount() % 300 == 0 then
|
||||
local pos = Entity.GetPosition(self)
|
||||
Debug.Log("Spinner at frame " .. Timer.GetFrameCount()
|
||||
.. " pos=" .. pos.x .. "," .. pos.y .. "," .. pos.z
|
||||
.. " rotY=" .. Entity.GetRotationY(self))
|
||||
end
|
||||
end
|
||||
7
Assets/lua/spinner.lua.meta
Normal file
7
Assets/lua/spinner.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7401857254e372469edfcd09b92d7a1
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/lua/switch.lua
Normal file
41
Assets/lua/switch.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
-- ============================================================================
|
||||
-- switch.lua - Toggle switch that activates/deactivates a target object
|
||||
-- ============================================================================
|
||||
-- Tests: onInteract, Entity.Find, Entity.IsActive, Entity.SetActive,
|
||||
-- Audio, self properties
|
||||
|
||||
local target = nil
|
||||
local switchOn = false
|
||||
|
||||
function onCreate(self)
|
||||
switchOn = false
|
||||
-- Find the object this switch controls (named "SwitchTarget")
|
||||
target = Entity.Find("SwitchTarget")
|
||||
if target then
|
||||
Entity.SetActive(target, false)
|
||||
Debug.Log("Switch: found target, initially off")
|
||||
else
|
||||
Debug.Log("Switch: WARNING - SwitchTarget not found!")
|
||||
end
|
||||
end
|
||||
|
||||
function onInteract(self)
|
||||
switchOn = not switchOn
|
||||
|
||||
if target then
|
||||
Entity.SetActive(target, switchOn)
|
||||
end
|
||||
|
||||
if switchOn then
|
||||
Audio.Play("switch_on", 100, 64)
|
||||
setStatus("Switch ON")
|
||||
else
|
||||
Audio.Play("switch_off", 100, 64)
|
||||
setStatus("Switch OFF")
|
||||
end
|
||||
|
||||
-- Test Entity queries
|
||||
local count = Entity.GetCount()
|
||||
Debug.Log("Switch toggled. Total entities: " .. count)
|
||||
Debug.Log("Target active: " .. tostring(Entity.IsActive(target)))
|
||||
end
|
||||
7
Assets/lua/switch.lua.meta
Normal file
7
Assets/lua/switch.lua.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6fb27fb693abcd4092b5bbc5e78afcb
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user