vn.lua --- Provides core functions for scripting visual novels. -- @module vn require("builtin/stdlib") require("builtin/callbacks") -- ---------------------------------------------------------------------------- -- Functions -- ---------------------------------------------------------------------------- -- Prints a warning when called from a script targetting an engine version more recent than the time of -- deprecation. function deprecated(deprecatedSince) local targetVersion = prefs.engineTargetVersion if deprecatedSince ~= nil and targetVersion ~= nil and System.compareVersion(deprecatedSince, targetVersion) <= 0 then local info = debug.getinfo(2, 'n') Log.warn("Warning: Deprecated function used ({})", info.name) end end local function preJump(filename) if getSkipMode() == SkipMode.SCENE then stopSkipping() end savepoint(filename) end ---Executes the script with the given filename. When the called script -- completes, resumes executing the current script. Use -- jump("some-script.lvn") when you don't want/need to -- come back to the current script. -- @string filename Path to the script, relative to the res/script -- folder. function call(filename) preJump(filename) return dofile(filename) end ---Jumps execution to the specified script file. If you want to resume from the -- current position after the new script ends, use call instead. -- @string filename Path to the script, relative to the res/script -- folder. function jump(filename) preJump(filename) return Thread.jump(filename) end ---Include submodules -------------------------------------------------------------------------------------------------------------- @section submodules module("vn", package.seeall) --Require submodules local submodules = { "anim", "choice", "context", "gui", "image", "imagefx", "save", "savescreen", "settingsscreen", "sound", "system", "text", "textbox", "textlog", "tween", "video" } for _,module in ipairs(submodules) do require("builtin/vn/" .. module) end -- ---------------------------------------------------------------------------- -- Flatten functions -- ---------------------------------------------------------------------------- local function flattenSingle(env, pkg) if pkg == nil then return end for k,v in pairs(pkg) do if k[0] ~= '_' then env[k] = v end end end -- Flattens this module and its submodules into env -- @param env The table (often _G) to flatten the module into. local function flattenModule(env) flattenSingle(env, package.loaded.vn) for _,module in ipairs(submodules) do flattenSingle(env, package.loaded.vn[module]) end _G.vn = nil --Delete the now flattened table end -- Flatten submodules into main namespace flattenModule(_G) ---Initialization -------------------------------------------------------------------------------------------------------------- @section init -- Register default textboxes registerTextBox(TextMode.NVL, NvlTextBox.new) registerTextBox(TextMode.ADV, AdvTextBox.new) ← Previous Index Next →