Miki_Tellurium

notepad-settings API

Jan 2nd, 2023 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | Gaming | 0 0
  1. -- Notepad settings by Miki_Tellurium
  2. -- Version: 1.0.0
  3. local buttonLibrary = require("button")
  4. local expect = require("cc.expect")
  5. expect = expect.expect
  6.  
  7. local settingsFile = "notepad.settings" --Settings file
  8.  
  9. --- Settings API for the notepad app.
  10. ---@class notepadsettings
  11. notepadsettings = {}
  12.  
  13. --- Define the settings for the program.
  14. function notepadsettings.defineSettings()
  15.     settings.define("ItalyFlag", {
  16.         description = "If the Italy flag should be displayed",
  17.         default = false,
  18.         type = "boolean"
  19.     })
  20.     settings.define("HeaderText", {
  21.         description = "The app header",
  22.         default = "Notepad",
  23.         type = "string"
  24.     })
  25.     settings.define("HeaderColor", {
  26.         description = "The color of the app header",
  27.         default = colors.white,
  28.         type = "number"
  29.     })
  30.     settings.define("IngameInfoTitleColor", {
  31.         description = "The color of the ingame info title",
  32.         default = colors.blue,
  33.         type = "number"
  34.     })
  35.     settings.define("IngameInfoColor", {
  36.         description = "The color of the ingame info",
  37.         default = colors.lightBlue,
  38.         type = "number"
  39.     })
  40.     settings.define("IrlInfoTitleColor", {
  41.         description = "The color of the real time info title",
  42.         default = colors.orange,
  43.         type = "number"
  44.     })
  45.     settings.define("IrlInfoColor", {
  46.         description = "The color of the real time info",
  47.         default = colors.yellow,
  48.         type = "number"
  49.     })
  50. end
  51.  
  52. --- Set default values for the settings and write them in notepad.settings.
  53. local function setDefaultValues()
  54.     settings.set("ItalyFlag", false)
  55.     settings.set("HeaderText", "Notepad")
  56.     settings.set("HeaderColor", colors.white)
  57.     settings.set("IngameInfoTitleColor", colors.blue)
  58.     settings.set("IngameInfoColor", colors.lightBlue)
  59.     settings.set("IrlInfoTitleColor", colors.orange)
  60.     settings.set("IrlInfoColor", colors.yellow)
  61. end
  62. --- Check if the setting file exist and if it doesn't create it.
  63. function notepadsettings.createSettings()
  64.     if fs.open(settingsFile, "r") then
  65.         return
  66.     else
  67.         term.clear()
  68.         term.setCursorPos(1, 1)
  69.         write("Configuring settings")
  70.         textutils.slowPrint("...", 2)
  71.         setDefaultValues()
  72.         settings.save(settingsFile)
  73.         sleep(1)
  74.         print("Done!")
  75.         sleep(1)
  76.     end
  77. end
  78. --- Update the value of a setting.
  79. ---@param setting string The name of the setting
  80. ---@param value any The new value of the setting
  81. function notepadsettings.update(setting, value)
  82.     expect(1, setting, "string")
  83.     expect(2, value, "string", "number", "boolean")
  84.     settings.set(setting,value)
  85.     settings.save(settingsFile)
  86. end
  87.  
  88. settings.load(settingsFile)
Advertisement
Add Comment
Please, Sign In to add comment