From b34c18da8a0aa811ba2a8abd5ec858930518cbe2 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Thu, 4 May 2023 21:33:58 +0300 Subject: [PATCH] config library --- uranium/config.lua | 36 ++++++++++++++++++++++++++++++++++++ uranium/main.lua | 31 +++++++++---------------------- 2 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 uranium/config.lua diff --git a/uranium/config.lua b/uranium/config.lua new file mode 100644 index 0000000..03e9083 --- /dev/null +++ b/uranium/config.lua @@ -0,0 +1,36 @@ +-- Internal module for Uranium's configuration system, meant to be used +-- for other systems to access the values. +local M = {} + +-- Uranium's configuration system, providing methods to configure parts +-- of the template. +uranium.config = {} + +M.resetOnFrameStart = false + +-- Toggle actor resetting on frame start behavior by default. +---@param bool boolean +function uranium.config.resetOnFrameStart(bool) + M.resetOnFrameStart = bool +end + +---@type table +M.resetActorOnFrameStart = {} + +-- Toggle actor resetting on frame start for individual actors. `bool` defaults to the opposite of your `resetOnFrameStart` config +---@param actor Actor +---@param bool boolean | nil +function uranium.config.resetActorOnFrameStart(actor, bool) + if bool == nil then bool = not M.resetOnFrameStart end + M.resetActorOnFrameStart[actor.__raw or actor] = bool +end + +M.hideThemeActors = true + +-- Toggle if theme actors (lifebars, scores, song names, etc.) are hidden. Must be toggled **before** `init`. +---@param bool boolean +function uranium.config.hideThemeActors(bool) + M.hideThemeActors = bool +end + +return M \ No newline at end of file diff --git a/uranium/main.lua b/uranium/main.lua index 58c85c9..b8c71f3 100644 --- a/uranium/main.lua +++ b/uranium/main.lua @@ -1,9 +1,7 @@ require 'uranium.constants' require 'uranium.events' local actors = require 'uranium.actors' - -local resetOnFrameStartCfg = false -local resetOnFrameStartActors = {} +local config = require 'uranium.config' local hasExited = false local function exit() @@ -34,10 +32,10 @@ local function onCommand(self) actors._actorsInitialized = true actors._actorsInitializing = false local resetOnFrameStartActors_ = {} - for k,v in pairs(resetOnFrameStartActors) do + for k,v in pairs(config.resetActorOnFrameStart) do resetOnFrameStartActors_[k.__raw] = v end - resetOnFrameStartActors = resetOnFrameStartActors_ + config.resetActorOnFrameStart = resetOnFrameStartActors_ uranium.call('init') end @@ -61,25 +59,14 @@ end GAMESTATE:ApplyModifiers('clearall') --- Toggle actor resetting on frame start behavior by default. ----@param bool boolean -function resetOnFrameStart(bool) - resetOnFrameStartCfg = bool -end - --- Toggle actor resetting on frame start for individual actors. `bool` defaults to the opposite of your `resetOnFrameStart` config ----@param actor Actor ----@param bool boolean | nil -function resetActorOnFrameStart(actor, bool) - if bool == nil then bool = not resetOnFrameStartCfg end - resetOnFrameStartActors[actor.__raw or actor] = bool -end - local lastt = GAMESTATE:GetSongTime() local function screenReadyCommand(self) actors.finalize() - hideThemeActors() + if config.hideThemeActors then + hideThemeActors() + end + self:hidden(0) collectgarbage() @@ -116,12 +103,12 @@ local function screenReadyCommand(self) drawfunctionArguments = {} for _, q in ipairs(actors._globalQueue) do - local enabled = resetOnFrameStartCfg + local enabled = config.resetOnFrameStart local actor = q[1] local v = q[2] - local pref = resetOnFrameStartActors[actor] + local pref = config.resetActorOnFrameStart[actor] if pref ~= nil then enabled = pref end if enabled then