mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 17:19:31 +00:00
Custom dofile, take 2
This commit is contained in:
parent
5961b217c5
commit
389ebcba8d
1 changed files with 13 additions and 14 deletions
27
scene.lua
27
scene.lua
|
|
@ -2,17 +2,6 @@
|
||||||
local uqt = require((...):match("^(.-ubiquitousse)%."))
|
local uqt = require((...):match("^(.-ubiquitousse)%."))
|
||||||
local m = uqt.module
|
local m = uqt.module
|
||||||
|
|
||||||
--- Returns the file path of the given module name.
|
|
||||||
local function getPath(modname)
|
|
||||||
local filepath = ""
|
|
||||||
for path in package.path:gmatch("[^;]+") do
|
|
||||||
path = path:gsub("%?", (modname:gsub("%.", "/")))
|
|
||||||
local f = io.open(path)
|
|
||||||
if f then f:close() filepath = path break end
|
|
||||||
end
|
|
||||||
return filepath
|
|
||||||
end
|
|
||||||
|
|
||||||
--- 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 Ubiquitousse and is mostly a "recommended way" of organising an Ubiquitousse-based game.
|
-- This module is fully implemented in Ubiquitousse and is mostly a "recommended way" of organising an Ubiquitousse-based game.
|
||||||
|
|
@ -47,7 +36,17 @@ scene = {
|
||||||
|
|
||||||
--- Function which load a scene file
|
--- Function which load a scene file
|
||||||
-- @impl ubiquitousse
|
-- @impl ubiquitousse
|
||||||
dofile = dofile,
|
load = function(scenePath)
|
||||||
|
for path in package.path:gmatch("[^;]+") do
|
||||||
|
path = path:gsub("%?", (scenePath:gsub("%.", "/")))
|
||||||
|
local f = io.open(path)
|
||||||
|
if f then
|
||||||
|
f:close()
|
||||||
|
return dofile(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
error("can't find scene "..tostring(scenePath))
|
||||||
|
end,
|
||||||
|
|
||||||
--- Creates and returns a new Scene object.
|
--- Creates and returns a new Scene object.
|
||||||
-- @tparam[opt="unamed"] string name the new scene name
|
-- @tparam[opt="unamed"] string name the new scene name
|
||||||
|
|
@ -78,7 +77,7 @@ scene = {
|
||||||
-- @impl ubiquitousse
|
-- @impl ubiquitousse
|
||||||
switch = function(scenePath, ...)
|
switch = function(scenePath, ...)
|
||||||
local previous = scene.current
|
local previous = scene.current
|
||||||
scene.current = scene.dofile(getPath(scene.prefix..scenePath))
|
scene.current = scene.load(scene.prefix..scenePath)
|
||||||
scene.current.name = scenePath
|
scene.current.name = scenePath
|
||||||
if previous then previous:exit() end
|
if previous then previous:exit() end
|
||||||
scene.current:enter(...)
|
scene.current:enter(...)
|
||||||
|
|
@ -94,7 +93,7 @@ scene = {
|
||||||
-- @impl ubiquitousse
|
-- @impl ubiquitousse
|
||||||
push = function(scenePath, ...)
|
push = function(scenePath, ...)
|
||||||
local previous = scene.current
|
local previous = scene.current
|
||||||
scene.current = scene.dofile(getPath(scene.prefix..scenePath))
|
scene.current = scene.load(scene.prefix..scenePath)
|
||||||
scene.current.name = scenePath
|
scene.current.name = scenePath
|
||||||
if previous then previous:suspend() end
|
if previous then previous:suspend() end
|
||||||
scene.current:enter(...)
|
scene.current:enter(...)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue