Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Notepad settings by Miki_Tellurium
- -- Version: 1.0.0
- local buttonLibrary = require("button")
- local expect = require("cc.expect")
- expect = expect.expect
- local settingsFile = "notepad.settings" --Settings file
- --- Settings API for the notepad app.
- ---@class notepadsettings
- notepadsettings = {}
- --- Define the settings for the program.
- function notepadsettings.defineSettings()
- settings.define("ItalyFlag", {
- description = "If the Italy flag should be displayed",
- default = false,
- type = "boolean"
- })
- settings.define("HeaderText", {
- description = "The app header",
- default = "Notepad",
- type = "string"
- })
- settings.define("HeaderColor", {
- description = "The color of the app header",
- default = colors.white,
- type = "number"
- })
- settings.define("IngameInfoTitleColor", {
- description = "The color of the ingame info title",
- default = colors.blue,
- type = "number"
- })
- settings.define("IngameInfoColor", {
- description = "The color of the ingame info",
- default = colors.lightBlue,
- type = "number"
- })
- settings.define("IrlInfoTitleColor", {
- description = "The color of the real time info title",
- default = colors.orange,
- type = "number"
- })
- settings.define("IrlInfoColor", {
- description = "The color of the real time info",
- default = colors.yellow,
- type = "number"
- })
- end
- --- Set default values for the settings and write them in notepad.settings.
- local function setDefaultValues()
- settings.set("ItalyFlag", false)
- settings.set("HeaderText", "Notepad")
- settings.set("HeaderColor", colors.white)
- settings.set("IngameInfoTitleColor", colors.blue)
- settings.set("IngameInfoColor", colors.lightBlue)
- settings.set("IrlInfoTitleColor", colors.orange)
- settings.set("IrlInfoColor", colors.yellow)
- end
- --- Check if the setting file exist and if it doesn't create it.
- function notepadsettings.createSettings()
- if fs.open(settingsFile, "r") then
- return
- else
- term.clear()
- term.setCursorPos(1, 1)
- write("Configuring settings")
- textutils.slowPrint("...", 2)
- setDefaultValues()
- settings.save(settingsFile)
- sleep(1)
- print("Done!")
- sleep(1)
- end
- end
- --- Update the value of a setting.
- ---@param setting string The name of the setting
- ---@param value any The new value of the setting
- function notepadsettings.update(setting, value)
- expect(1, setting, "string")
- expect(2, value, "string", "number", "boolean")
- settings.set(setting,value)
- settings.save(settingsFile)
- end
- settings.load(settingsFile)
Advertisement
Add Comment
Please, Sign In to add comment