mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
Merge branch 'master' into very_experimental_input_stuff
This commit is contained in:
commit
9c8da1c712
282 changed files with 4886 additions and 3718 deletions
|
@ -1,7 +1,10 @@
|
|||
-----
|
||||
--- Event sequence - a chain of functions to call at specified times, modeled after TRNG's organizers.
|
||||
--
|
||||
-- Works atop the Timer, and so is updated automatically pre-OnControlPhase, and saved automatically when the game is saved.
|
||||
--
|
||||
-- Example usage:
|
||||
-- local EventSequence = require("EventSequence")
|
||||
-- local EventSequence = require("Engine.EventSequence")
|
||||
--
|
||||
-- -- These will be called by the sequence
|
||||
-- LevelFuncs.HealLara = function()
|
||||
|
@ -23,34 +26,30 @@
|
|||
-- false, -- does not loop
|
||||
-- {seconds = true, deciseconds = true}, -- timer format, see Timer for details
|
||||
-- 6, -- seconds until call the function specified in next arg
|
||||
-- "HealLara", -- first function to call. If we don't need to pass any arguments, we can just give the func name as a string
|
||||
-- LevelFuncs.HealLara, -- first function to call. If we don't need to pass any arguments, we can just pass the function
|
||||
-- 2.1, -- seconds until the next function, after the previous one has been called
|
||||
-- {"SpawnBaddy", TEN.Objects.ObjID.BADDY1, "steve", posSteve}, -- if we DO want to pass arguments to the function to be called, we give a table with the name of the function ("SpawnBaddy" in this case) followed by the args to pass to it
|
||||
-- {LevelFuncs.SpawnBaddy, TEN.Objects.ObjID.BADDY1, "steve", posSteve}, -- if we DO want to pass arguments to the function to be called, we give a table with the function (LevelFuncs.SpawnBaddy in this case) followed by the args to pass to it
|
||||
-- 0.5,
|
||||
-- {"SpawnBaddy", TEN.Objects.ObjID.SAS_CAIRO, "chris", posChris},
|
||||
-- {LevelFuncs.SpawnBaddy, TEN.Objects.ObjID.SAS_CAIRO, "chris", posChris},
|
||||
-- 1,
|
||||
-- "HealLara")
|
||||
-- LevelFuncs.HealLara)
|
||||
--
|
||||
-- -- event sequences are inactive to begin with and so need to be started
|
||||
-- mySeq:Start()
|
||||
-- end
|
||||
--
|
||||
-- -- EventSequence runs on Timer, so this call is required
|
||||
-- LevelFuncs.OnControlPhase = function(dt)
|
||||
-- Timer.UpdateAll(dt)
|
||||
-- end
|
||||
--
|
||||
-- @luautil EventSequence
|
||||
|
||||
local Timer = require("Timer")
|
||||
|
||||
local EventSequence
|
||||
|
||||
LevelVars.__TEN_eventSequence = {sequences = {}}
|
||||
LevelFuncs.Engine.EventSequence = {}
|
||||
LevelVars.Engine.EventSequence = {sequences = {}}
|
||||
|
||||
LevelFuncs.__TEN_eventSequence_callNext = function(sequenceName, nextTimerName, func, ...)
|
||||
local thisES = LevelVars.__TEN_eventSequence.sequences[sequenceName]
|
||||
LevelFuncs[func](...)
|
||||
LevelFuncs.Engine.EventSequence.CallNext = function(sequenceName, nextTimerName, func, ...)
|
||||
local thisES = LevelVars.Engine.EventSequence.sequences[sequenceName]
|
||||
func(...)
|
||||
|
||||
thisES.currentTimer = thisES.currentTimer + 1
|
||||
if thisES.currentTimer <= #thisES.timers then
|
||||
|
@ -82,9 +81,8 @@ EventSequence = {
|
|||
setmetatable(obj, mt)
|
||||
|
||||
obj.name = name
|
||||
|
||||
LevelVars.__TEN_eventSequence.sequences[name] = {}
|
||||
local thisES = LevelVars.__TEN_eventSequence.sequences[name]
|
||||
LevelVars.Engine.EventSequence.sequences[name] = {}
|
||||
local thisES = LevelVars.Engine.EventSequence.sequences[name]
|
||||
thisES.name = name
|
||||
thisES.timesFuncsAndArgs = {...}
|
||||
thisES.loop = loop
|
||||
|
@ -99,7 +97,6 @@ EventSequence = {
|
|||
local nextTimer = i + 2
|
||||
local timerIndex = #thisES.timers + 1
|
||||
|
||||
local funcName = "__TEN_eventSequence_" .. name .. "_func" .. timerIndex
|
||||
local timerName = "__TEN_eventSequence_" .. name .. "_timer" .. timerIndex
|
||||
local nextTimerName = "__TEN_eventSequence_" .. name .. "_timer" .. timerIndex + 1
|
||||
|
||||
|
@ -110,7 +107,7 @@ EventSequence = {
|
|||
thisES.firstTimerName = timerName
|
||||
end
|
||||
|
||||
if type(funcAndArgs) == "string" then
|
||||
if type(funcAndArgs) == "userdata" then
|
||||
-- we only have a function
|
||||
func = funcAndArgs
|
||||
funcAndArgs = {}
|
||||
|
@ -123,7 +120,7 @@ EventSequence = {
|
|||
tfa[i], -- time
|
||||
false,
|
||||
timerFormat,
|
||||
"__TEN_eventSequence_callNext",
|
||||
LevelFuncs.Engine.EventSequence.CallNext,
|
||||
name,
|
||||
nextTimerName,
|
||||
func,
|
||||
|
@ -140,7 +137,7 @@ EventSequence = {
|
|||
-- @string name The label that was given to the sequence when it was created
|
||||
-- @return The sequence
|
||||
Get = function(name)
|
||||
if LevelVars.__TEN_eventSequence.sequences[name] then
|
||||
if LevelVars.Engine.EventSequence.sequences[name] then
|
||||
local obj = {}
|
||||
local mt = {}
|
||||
mt.__index = EventSequence
|
||||
|
@ -155,7 +152,7 @@ EventSequence = {
|
|||
-- @function mySequence:SetPaused
|
||||
-- @bool p if true, the sequence will be paused; if false, it will be unpaused
|
||||
SetPaused = function(t, p)
|
||||
local thisES = LevelVars.__TEN_eventSequence.sequences[t.name]
|
||||
local thisES = LevelVars.Engine.EventSequence.sequences[t.name]
|
||||
Timer.Get(thisES.timers[thisES.currentTimer]):SetPaused(p)
|
||||
end;
|
||||
|
||||
|
@ -163,21 +160,21 @@ EventSequence = {
|
|||
-- @function mySequence:IsPaused
|
||||
-- @return true if the timer is paused, false if otherwise
|
||||
IsPaused = function(t)
|
||||
local thisES = LevelVars.__TEN_eventSequence.sequences[t.name]
|
||||
local thisES = LevelVars.Engine.EventSequence.sequences[t.name]
|
||||
return Timer.Get(thisES.timers[thisES.currentTimer]):IsPaused()
|
||||
end;
|
||||
|
||||
--- Begin or unpause a sequence. If showing the remaining time on-screen, its color will be set to white.
|
||||
-- @function mySequence:Start
|
||||
Start = function(t)
|
||||
local thisES = LevelVars.__TEN_eventSequence.sequences[t.name]
|
||||
local thisES = LevelVars.Engine.EventSequence.sequences[t.name]
|
||||
Timer.Get(thisES.timers[thisES.currentTimer]):Start()
|
||||
end;
|
||||
|
||||
--- Stop the sequence.
|
||||
--@function mySequence:Stop
|
||||
Stop = function(t)
|
||||
local thisES = LevelVars.__TEN_eventSequence.sequences[t.name]
|
||||
local thisES = LevelVars.Engine.EventSequence.sequences[t.name]
|
||||
Timer.Get(thisES.timers[thisES.currentTimer]):Stop()
|
||||
end;
|
||||
|
||||
|
@ -185,7 +182,7 @@ EventSequence = {
|
|||
-- @function mySequence:IsActive
|
||||
-- @return true if the sequence is active, false if otherwise
|
||||
IsActive = function(t)
|
||||
local thisES = LevelVars.__TEN_eventSequence.sequences[t.name]
|
||||
local thisES = LevelVars.Engine.EventSequence.sequences[t.name]
|
||||
return Timer.Get(thisES.timers[thisES.currentTimer]):IsActive()
|
||||
end;
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
-----
|
||||
--- Basic timer - after a specified number of seconds, the specified thing happens.
|
||||
--
|
||||
-- Timers are updated automatically every frame before OnControlPhase.
|
||||
--
|
||||
-- Example usage:
|
||||
-- local Timer = require("Timer")
|
||||
-- local Timer = require("Engine.Timer")
|
||||
--
|
||||
-- -- This will be called when the timer runs out
|
||||
-- LevelFuncs.FinishTimer = function(healthWhenStarted, victoryMessage)
|
||||
|
@ -15,19 +18,16 @@
|
|||
-- 5.0,
|
||||
-- false,
|
||||
-- {minutes = false, seconds = true, deciseconds = true},
|
||||
-- "FinishTimer",
|
||||
-- LevelFuncs.FinishTimer,
|
||||
-- Lara:GetHP(),
|
||||
-- "Well done!")
|
||||
-- myTimer:Start()
|
||||
-- end
|
||||
--
|
||||
-- LevelFuncs.OnControlPhase = function(dt)
|
||||
-- Timer.UpdateAll(dt)
|
||||
-- end
|
||||
--
|
||||
-- @luautil Timer
|
||||
|
||||
LevelVars.__TEN_timer = {timers = {}}
|
||||
LevelFuncs.Engine.Timer = {}
|
||||
LevelVars.Engine.Timer = {timers = {}}
|
||||
|
||||
local Timer
|
||||
|
||||
|
@ -35,6 +35,7 @@ local unpausedColor = TEN.Color(255, 255, 255)
|
|||
local pausedColor = TEN.Color(255, 255, 0)
|
||||
local str = TEN.Strings.DisplayString("TIMER", 0, 0, unpausedColor, false, {TEN.Strings.DisplayStringOption.CENTER, TEN.Strings.DisplayStringOption.SHADOW} )
|
||||
|
||||
|
||||
Timer = {
|
||||
--- Create (but do not start) a new timer.
|
||||
--
|
||||
|
@ -56,13 +57,15 @@ Timer = {
|
|||
--
|
||||
--__At any given time, only one timer can show its countdown__.
|
||||
--
|
||||
--__Do not give your timers a name beginning with __TEN, as this is reserved for timers used by other internal libaries__.
|
||||
--
|
||||
--Use this sparingly; in the classics, timed challenges did not have visible countdowns. For shorter timers, the gameplay benefit from showing the remaining time might not be necessary, and could interfere with the atmosphere of the level.
|
||||
--
|
||||
-- @string name A label to give this timer; used to retrieve the timer later
|
||||
-- @number totalTime The duration of the timer, in seconds
|
||||
-- @bool loop if true, the timer will start again immediately after the time has elapsed
|
||||
-- @tparam ?table|bool timerFormat If a table is given, the remaining time will be shown as a string, formatted according to the values in the table. If true, the remaining seconds, rounded up, will show at the bottom of the screen. If false, the remaining time will not be shown on screen.
|
||||
-- @string func The name of the LevelFunc member to call when the time is upssss
|
||||
-- @function func The LevelFunc function to call when the time is up
|
||||
-- @param[opt] ... a variable number of arguments with which the above function will be called
|
||||
-- @return The timer in its paused state
|
||||
--
|
||||
|
@ -73,8 +76,13 @@ Timer = {
|
|||
setmetatable(obj, mt)
|
||||
|
||||
obj.name = name
|
||||
LevelVars.__TEN_timer.timers[name] ={}
|
||||
local thisTimer = LevelVars.__TEN_timer.timers[name]
|
||||
|
||||
if LevelVars.Engine.Timer.timers[name] then
|
||||
print("Warning: a timer with name " .. name .. " already exists.")
|
||||
end
|
||||
|
||||
LevelVars.Engine.Timer.timers[name] ={}
|
||||
local thisTimer = LevelVars.Engine.Timer.timers[name]
|
||||
thisTimer.name = name
|
||||
thisTimer.totalTime = totalTime
|
||||
thisTimer.remainingTime = totalTime
|
||||
|
@ -95,7 +103,7 @@ Timer = {
|
|||
-- @string name The label that was given to the timer when it was created
|
||||
-- @return The timer
|
||||
Get = function(name)
|
||||
if LevelVars.__TEN_timer.timers[name] then
|
||||
if LevelVars.Engine.Timer.timers[name] then
|
||||
local obj = {}
|
||||
local mt = {}
|
||||
mt.__index = Timer
|
||||
|
@ -112,8 +120,7 @@ Timer = {
|
|||
t.remainingTime = t.remainingTime - dt
|
||||
|
||||
if t.remainingTime <= 0 then
|
||||
LevelFuncs[t.func](table.unpack(t.funcArgs))
|
||||
|
||||
t.func(table.unpack(t.funcArgs))
|
||||
if not t.loop then
|
||||
t.active = false
|
||||
else
|
||||
|
@ -190,21 +197,16 @@ Timer = {
|
|||
end
|
||||
end;
|
||||
|
||||
--- Update all active timers.
|
||||
-- Should be called in LevelFuncs.OnControlPhase
|
||||
-- @number dt The time in seconds since the last frame
|
||||
UpdateAll = function(dt)
|
||||
for _, t in pairs(LevelVars.__TEN_timer.timers) do
|
||||
Timer.Update(t, dt)
|
||||
end
|
||||
print("Timer.UpdateAll is deprecated; timers and event sequences now get updated automatically pre-control phase.")
|
||||
end;
|
||||
|
||||
--- Give the timer a new function and args
|
||||
-- @function myTimer:SetFunction
|
||||
-- @string func The name of the LevelFunc member to call when the time is up
|
||||
-- @tparam function func The LevelFunc member to call when the time is up
|
||||
-- @param[opt] ... a variable number of arguments with which the above function will be called
|
||||
SetFunction = function(t, func, ...)
|
||||
local thisTimer = LevelVars.__TEN_timer.timers[t.name]
|
||||
local thisTimer = LevelVars.Engine.Timer.timers[t.name]
|
||||
thisTimer.func = func
|
||||
thisTimer.funcArgs = {...}
|
||||
end;
|
||||
|
@ -212,7 +214,7 @@ Timer = {
|
|||
--- Begin or unpause a timer. If showing the remaining time on-screen, its color will be set to white.
|
||||
-- @function myTimer:Start
|
||||
Start = function(t)
|
||||
local thisTimer = LevelVars.__TEN_timer.timers[t.name]
|
||||
local thisTimer = LevelVars.Engine.Timer.timers[t.name]
|
||||
if not thisTimer.active then
|
||||
thisTimer.active = true
|
||||
end
|
||||
|
@ -227,21 +229,21 @@ Timer = {
|
|||
--- Stop the timer.
|
||||
-- @function myTimer:Stop
|
||||
Stop = function(t)
|
||||
LevelVars.__TEN_timer.timers[t.name].active = false
|
||||
LevelVars.Engine.Timer.timers[t.name].active = false
|
||||
end;
|
||||
|
||||
--- Get whether or not the timer is active
|
||||
-- @function myTimer:IsActive
|
||||
-- @return true if the timer is active, false if otherwise
|
||||
IsActive = function(t)
|
||||
return LevelVars.__TEN_timer.timers[t.name].active
|
||||
return LevelVars.Engine.Timer.timers[t.name].active
|
||||
end;
|
||||
|
||||
--- Pause or unpause the timer. If showing the remaining time on-screen, its color will be set to yellow (paused) or white (unpaused).
|
||||
-- @function myTimer:SetPaused
|
||||
-- @bool p if true, the timer will be paused; if false, it would be unpaused
|
||||
SetPaused = function(t, p)
|
||||
local thisTimer = LevelVars.__TEN_timer.timers[t.name]
|
||||
local thisTimer = LevelVars.Engine.Timer.timers[t.name]
|
||||
thisTimer.paused = p
|
||||
if thisTimer.timerFormat then
|
||||
if p then
|
||||
|
@ -256,21 +258,21 @@ Timer = {
|
|||
-- @function myTimer:IsPaused
|
||||
-- @return true if the timer is paused, false if otherwise
|
||||
IsPaused = function(t)
|
||||
return LevelVars.__TEN_timer.timers[t.name].paused
|
||||
return LevelVars.Engine.Timer.timers[t.name].paused
|
||||
end;
|
||||
|
||||
--- Get the remaining time for a timer.
|
||||
-- @function myTimer:GetRemainingTime
|
||||
-- @return the time in seconds remaining on the clock
|
||||
GetRemainingTime = function(t)
|
||||
return LevelVars.__TEN_timer.timers[t.name].remainingTime
|
||||
return LevelVars.Engine.Timer.timers[t.name].remainingTime
|
||||
end;
|
||||
|
||||
--- Set the remaining time for a timer
|
||||
-- @function myTimer:SetRemainingTime
|
||||
-- @number remainingTime the new time remaining for the timer
|
||||
SetRemainingTime = function(t, remainingTime)
|
||||
LevelVars.__TEN_timer.timers[t.name].remainingTime = remainingTime
|
||||
LevelVars.Engine.Timer.timers[t.name].remainingTime = remainingTime
|
||||
end;
|
||||
|
||||
--- Get the total time for a timer.
|
||||
|
@ -278,23 +280,31 @@ Timer = {
|
|||
-- @function myTimer:GetRemainingTime
|
||||
-- @return the timer's total time
|
||||
GetTotalTime = function(t)
|
||||
return LevelVars.__TEN_timer.timers[t.name].totalTime
|
||||
return LevelVars.Engine.Timer.timers[t.name].totalTime
|
||||
end;
|
||||
|
||||
--- Set the total time for a timer
|
||||
-- @function myTimer:SetTotalTime
|
||||
-- @number totalTime timer's new total time
|
||||
SetTotalTime = function(t, totalTime)
|
||||
LevelVars.__TEN_timer.timers[t.name].totalTime = totalTime
|
||||
LevelVars.Engine.Timer.timers[t.name].totalTime = totalTime
|
||||
end;
|
||||
|
||||
--- Set whether or not the timer loops
|
||||
-- @function myTimer:SetLooping
|
||||
-- @bool looping whether or not the timer loops
|
||||
SetLooping = function(t, looping)
|
||||
LevelVars.__TEN_timer.timers[t.name].loop = looping
|
||||
LevelVars.Engine.Timer.timers[t.name].loop = looping
|
||||
end;
|
||||
}
|
||||
|
||||
LevelFuncs.Engine.Timer.UpdateAll = function(dt)
|
||||
for _, t in pairs(LevelVars.Engine.Timer.timers) do
|
||||
Timer.Update(t, dt)
|
||||
end
|
||||
end
|
||||
|
||||
TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, LevelFuncs.Engine.Timer.UpdateAll)
|
||||
|
||||
return Timer
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
-- New level script file.
|
||||
-- To include other script files, you can use require("filename") command.
|
||||
|
||||
local Util = require("Util")
|
||||
local Util = require("Engine.Util")
|
||||
Util.ShortenTENCalls()
|
||||
|
||||
-- Called when entering a level, either after leveljump, new game or loading game
|
||||
|
@ -27,4 +27,4 @@ LevelFuncs.OnEnd = function() end
|
|||
LevelFuncs.PrintText = function(Triggerer, Argument)
|
||||
local TestText = DisplayString(Argument, 100, 100, Color.new(250,250,250))
|
||||
ShowString(TestText, 1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
-- Title script file
|
||||
|
||||
local Util = require("Util")
|
||||
local Util = require("Engine.Util")
|
||||
Util.ShortenTENCalls()
|
||||
|
||||
LevelFuncs.OnLoad = function() end
|
||||
LevelFuncs.OnSave = function() end
|
||||
LevelFuncs.OnEnd = function() end
|
||||
|
||||
LevelFuncs.OnControlPhase = function() end
|
||||
LevelFuncs.OnStart = function() end
|
||||
LevelFuncs.OnControlPhase = function(dt) end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue