mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 17:19:31 +00:00
Update
This commit is contained in:
parent
52b3389e13
commit
8ccf3534bc
3 changed files with 24 additions and 11 deletions
|
|
@ -53,7 +53,7 @@ abstract.backend = "ctrulua"
|
||||||
-- abstract.time
|
-- abstract.time
|
||||||
if abstract.time then
|
if abstract.time then
|
||||||
add(abstract.time, {
|
add(abstract.time, {
|
||||||
get = ctr.time()
|
get = ctr.time
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
27
scene.lua
27
scene.lua
|
|
@ -5,13 +5,16 @@ local time = require((...):match("^(.-abstract)%.")..".time")
|
||||||
local function getPath(modname)
|
local function getPath(modname)
|
||||||
local filepath = ""
|
local filepath = ""
|
||||||
for path in package.path:gmatch("[^;]+") do
|
for path in package.path:gmatch("[^;]+") do
|
||||||
local path = path:gsub("%?", (modname:gsub("%.", "/")))
|
path = path:gsub("%?", (modname:gsub("%.", "/")))
|
||||||
local f = io.open(path)
|
local f = io.open(path)
|
||||||
if f then f:close() filepath = path break end
|
if f then f:close() filepath = path break end
|
||||||
end
|
end
|
||||||
return filepath
|
return filepath
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- FIXME: http://hump.readthedocs.io/en/latest/gamestate.html
|
||||||
|
-- FIXME: call order
|
||||||
|
|
||||||
--- Scene management.
|
--- Scene management.
|
||||||
-- You can use use scenes to seperate the different states of your game: for example, a menu scene and a game scene.
|
-- You can use use scenes to seperate the different states of your game: for example, a menu scene and a game scene.
|
||||||
-- This module is fully implemented in abstract and is mostly a "recommended way" of organising an abstract-based game.
|
-- This module is fully implemented in abstract and is mostly a "recommended way" of organising an abstract-based game.
|
||||||
|
|
@ -19,6 +22,11 @@ end
|
||||||
-- make them scene-independent, for example by creating a scene-specific TimerRegistry (TimedFunctions that are keept accross
|
-- make them scene-independent, for example by creating a scene-specific TimerRegistry (TimedFunctions that are keept accross
|
||||||
-- states are generally a bad idea). Theses scene-specific states should be created and available in the table returned by
|
-- states are generally a bad idea). Theses scene-specific states should be created and available in the table returned by
|
||||||
-- abstract.scene.new.
|
-- abstract.scene.new.
|
||||||
|
-- Currently, the implementation always execute a scene's file before setting it as current, but this may change in the future or
|
||||||
|
-- for some implementations (e.g., on a computer where memory isn't a problem, the scene may be put in a cache). The result of this
|
||||||
|
-- is that you can load assets, libraries, etc. outside of the enter callback, so they can be cached and not reloaded each time
|
||||||
|
-- the scene is entered, but all the other scene initialization should be done in the enter callback, since it won't be executed on
|
||||||
|
-- each enter otherwise.
|
||||||
-- The expected code-organisation is:
|
-- The expected code-organisation is:
|
||||||
-- * each scene is in a file, identified by its module name (same identifier used by Lua's require)
|
-- * each scene is in a file, identified by its module name (same identifier used by Lua's require)
|
||||||
-- * each scene file create a new scene table using abstract.scene.new and returns it at the end of the file
|
-- * each scene file create a new scene table using abstract.scene.new and returns it at the end of the file
|
||||||
|
|
@ -47,7 +55,8 @@ scene = {
|
||||||
return {
|
return {
|
||||||
time = time.new(), -- Scene-specific TimerRegistry.
|
time = time.new(), -- Scene-specific TimerRegistry.
|
||||||
|
|
||||||
exit = function() end, -- Called when exiting a scene, and not expecting to come back (scene will be unloaded).
|
enter = function(...) end, -- Called when entering a scene.
|
||||||
|
exit = function() end, -- Called when exiting a scene, and not expecting to come back (scene may be unloaded).
|
||||||
|
|
||||||
suspend = function() end, -- Called when suspending a scene, and expecting to come back (scene won't be unloaded).
|
suspend = function() end, -- Called when suspending a scene, and expecting to come back (scene won't be unloaded).
|
||||||
resume = function() end, -- Called when resuming a suspended scene (after calling suspend).
|
resume = function() end, -- Called when resuming a suspended scene (after calling suspend).
|
||||||
|
|
@ -58,15 +67,17 @@ scene = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Switch to a new scene.
|
--- Switch to a new scene.
|
||||||
-- The current scene exit function will be called, the new scene will be loaded, and then
|
-- The current scene exit function will be called, the new scene will be loaded,
|
||||||
-- the current scene will then be replaced by the new one.
|
-- the current scene will then be replaced by the new one, and then the enter callback is called.
|
||||||
-- @tparam string scenePath the new scene module name
|
-- @tparam string scenePath the new scene module name
|
||||||
|
-- @param ... arguments to pass to the scene's enter function
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
switch = function(scenePath)
|
switch = function(scenePath, ...)
|
||||||
if scene.current then scene.current.exit() end
|
if scene.current then scene.current.exit() end
|
||||||
scene.current = dofile(getPath(scene.prefix..scenePath))
|
scene.current = dofile(getPath(scene.prefix..scenePath))
|
||||||
local i = #scene.stack
|
local i = #scene.stack
|
||||||
scene.stack[math.max(i, 1)] = scene.current
|
scene.stack[math.max(i, 1)] = scene.current
|
||||||
|
scene.current.enter(...)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Push a new scene to the scene stack.
|
--- Push a new scene to the scene stack.
|
||||||
|
|
@ -74,11 +85,13 @@ scene = {
|
||||||
-- and the current scene is not replaced: when the new scene call abstract.scene.pop, the old scene
|
-- and the current scene is not replaced: when the new scene call abstract.scene.pop, the old scene
|
||||||
-- will be reused.
|
-- will be reused.
|
||||||
-- @tparam string scenePath the new scene module name
|
-- @tparam string scenePath the new scene module name
|
||||||
|
-- @param ... arguments to pass to the scene's enter function
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
push = function(scenePath)
|
push = function(scenePath, ...)
|
||||||
if scene.current then scene.current.suspend() end
|
if scene.current then scene.current.suspend() end
|
||||||
scene.current = dofile(getPath(scene.prefix..scenePath))
|
scene.current = dofile(getPath(scene.prefix..scenePath))
|
||||||
table.insert(scene.stack, scene.current)
|
table.insert(scene.stack, scene.current)
|
||||||
|
scene.current.enter(...)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Pop the current scene from the scene stack.
|
--- Pop the current scene from the scene stack.
|
||||||
|
|
@ -88,9 +101,9 @@ scene = {
|
||||||
pop = function()
|
pop = function()
|
||||||
if scene.current then scene.current.exit() end
|
if scene.current then scene.current.exit() end
|
||||||
local previous = scene.stack[#scene.stack-1]
|
local previous = scene.stack[#scene.stack-1]
|
||||||
|
scene.current = previous
|
||||||
if previous then previous.resume() end
|
if previous then previous.resume() end
|
||||||
table.remove(scene.stack)
|
table.remove(scene.stack)
|
||||||
scene.current = previous
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Update the current scene.
|
--- Update the current scene.
|
||||||
|
|
|
||||||
6
time.lua
6
time.lua
|
|
@ -98,7 +98,7 @@ local function newTimerRegistry()
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
run = function(func)
|
run = function(func)
|
||||||
-- Creates empty function (the TimedFunction may be used for time measure or stuff like that which doesn't need a specific function)
|
-- Creates empty function (the TimedFunction may be used for time measure or stuff like that which doesn't need a specific function)
|
||||||
local func = func or function() end
|
func = func or function() end
|
||||||
|
|
||||||
-- Since delayed functions can end in any order, it doesn't really make sense to use a integer-keyed list.
|
-- Since delayed functions can end in any order, it doesn't really make sense to use a integer-keyed list.
|
||||||
-- Using the function as the key works and it's unique.
|
-- Using the function as the key works and it's unique.
|
||||||
|
|
@ -161,7 +161,7 @@ local function newTimerRegistry()
|
||||||
-- @treturn TimedFunction the object
|
-- @treturn TimedFunction the object
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
tween = function(duration, tbl, to, method)
|
tween = function(duration, tbl, to, method)
|
||||||
local method = method or "linear"
|
method = method or "linear"
|
||||||
method = type(method) == "string" and ease[method] or method
|
method = type(method) == "string" and ease[method] or method
|
||||||
|
|
||||||
local time = 0
|
local time = 0
|
||||||
|
|
@ -170,7 +170,7 @@ local function newTimerRegistry()
|
||||||
|
|
||||||
return registry.run(function(wait, dt)
|
return registry.run(function(wait, dt)
|
||||||
time = time + dt
|
time = time + dt
|
||||||
for k, v in pairs(to) do
|
for k in pairs(to) do
|
||||||
tbl[k] = method(time, from[k], to[k] - from[k], duration)
|
tbl[k] = method(time, from[k], to[k] - from[k], duration)
|
||||||
end
|
end
|
||||||
end):during(duration)
|
end):during(duration)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue