Giter Site home page Giter Site logo

config-library's Introduction

⚙️ Config Library

Library Install Documentation Examples Contact Information

This library allows you to save the settings of your script in the easiest way possible. This library handles converting of datatypes like Color3 into strings in the way so the table can be encoded into JSON format without any null values.

Color3.fromRGB(255, 255, 255) (Raw) > "Color3_(255, 255, 255)" (Config Library Archive)

For loading configs, the library decodes the JSON table (turns it into a Lua table) and later restores all the values by checking the signature types.

"Vector3_(10, 50, 20)" (Config Library Archive) > Vector3.new(10, 50, 20) (Raw)

Your script executor must support the following filesystem functions in order for the library to function:

  • readfile
  • isfile
  • writefile
  • isfolder
  • makefolder

Signatures

  • Color3.fromRGB(...) -> "Color3_(...)"
  • Vector3.new(...) -> "Vector3_(...)"
  • Vector2.new(...) -> "Vector2_(...)"
  • CFrame.new(...) -> "CFrame_(...)"
  • Enum[...] -> "EnumItem_(...)"

💻Install

You can load this library into your script's environment by copying the code below.

local Library = loadstring(game:HttpGet("https://raw.githubusercontent.com/Aegians/Config-Library/main/Main.lua"))()

📑Documentation

ConfigLibrary.Encode(<table> Table) --> JSON-Encoded Lua Table <string>

  • Encodes Table to JSON format.
print(ConfigLibrary.Encode({Bool = true})) -- {"Bool":true}

ConfigLibrary.Decode(<string> Content) --> Decoded JSON Table <table>

  • Decodes JSON Table (Content) & converts it to a Lua table.
print(ConfigLibrary.Decode([[{"Bool":true}]])[1]) -- true

ConfigLibrary:Recursive(<table> Table, <function> Callback)

  • Iterates through nested / inner tables. Will pass through every value and call Callback with the parameters i (index of value) & v (value).
local TestTable = {
	Bool = true,
	Number = 123,
	String = "Hello",
	Color = Color3.fromRGB(255, 255, 255),
	InnerTable = {
		Color2 = Color3.fromRGB(150, 150, 150),
		InnerInnerTable = {
			Color3_ = Color3.fromRGB(100, 100, 100),
			Vector3_ = Vector3.new(50, 200, 100),
			Vector2_ = Vector2.new(10, 20),
			InnerInnerInnerTable = {
				Key = Enum.KeyCode.X
			}
		}
	}
}

ConfigLibrary:Recursive(TestTable, warn)

Output:

image

ConfigLibrary.EditValue(<any> Value) --> Edited Value <any>

  • Edits the parsed value's type to the library's signature type.
print(ConfigLibrary.EditValue(Color3.fromRGB(50, 100, 200))) -- Color3_(50, 100, 200)

ConfigLibrary.RestoreValue(<any> Value) --> Restored Value <any>

  • Edits the parsed value (if the value's type is the library's signature type) to a default Luau value.
print(ConfigLibrary.RestoreValue("Color3_(50, 100, 200)")) -- 50, 100, 200 <Color3>

ConfigLibrary:CloneTable(<table> Table) --> Clone <table>

  • Clones the parsed Table and returns the Clone.
local TestTable = {
	Bool = true,
	Number = 123,
	String = "Hello",
	Color = Color3.fromRGB(255, 255, 255),
	InnerTable = {
		Color2 = Color3.fromRGB(150, 150, 150),
		InnerInnerTable = {
			Color3_ = Color3.fromRGB(100, 100, 100),
			Vector3_ = Vector3.new(50, 200, 100),
			Vector2_ = Vector2.new(10, 20),
			InnerInnerInnerTable = {
				Key = Enum.KeyCode.X
			}
		}
	}
}

local Clone = ConfigLibrary:CloneTable(TestTable)

print(TestTable)
print(Clone)
print(TestTable == Clone)

print(string.rep("=", 25))

ConfigLibrary:Recursive(TestTable, warn)
print(string.rep("=", 10).."Clone"..string.rep("=", 10))
ConfigLibrary:Recursive(Clone, warn)

Output:

image

ConfigLibrary:ConvertValues(<table> Data, <string> Method) --> Result (Converted Data) <table>

  • Edits all the values of parsed table (Data) depending on the Method.
  • "Edit" method calls ConfigLibrary.EditValue function.
  • "Restore" method calls ConfigLibrary.RestoreValue function.
local TestTable = {
	Bool = true,
	Number = 123,
	String = "Hello",
	Color = Color3.fromRGB(255, 255, 255),
	InnerTable = {
		Color2 = Color3.fromRGB(150, 150, 150),
		InnerInnerTable = {
			Color3_ = Color3.fromRGB(100, 100, 100),
			Vector3_ = Vector3.new(50, 200, 100),
			Vector2_ = Vector2.new(10, 20),
			InnerInnerInnerTable = {
				Key = Enum.KeyCode.X
			}
		}
	}
}

ConfigLibrary:Recursive(ConfigLibrary:ConvertValues(TestTable, "Edit"), warn)

Output:

image

ConfigLibrary:SaveConfig(<string> Path, <table> Data)

  • Converts the parsed Data's values to the library's signature values and later encodes the result to a JSON table. The JSON-Encoded table later gets saved at the parsed Path. If Path doesn't exist, the library creates the path and the file with the given extension (with folders and everything).
local TestTable = {
	Bool = true,
	Number = 123,
	String = "Hello",
	Color = Color3.fromRGB(255, 255, 255),
	InnerTable = {
		Color2 = Color3.fromRGB(150, 150, 150),
		InnerInnerTable = {
			Color3_ = Color3.fromRGB(100, 100, 100),
			Vector3_ = Vector3.new(50, 200, 100),
			Vector2_ = Vector2.new(10, 20),
			InnerInnerInnerTable = {
				Key = Enum.KeyCode.X
			}
		}
	}
}

ConfigLibrary:SaveConfig("a/b/c/d/test.json", TestTable)

image image

ConfigLibrary:LoadConfig(<string> Path) --> Config <table>

  • Opens the file located at Path and decodes the JSON table and restores its values to Luau format.
local TestTable = {}

TestTable = ConfigLibrary:LoadConfig("a/b/c/d/test.json")

ConfigLibrary:Recursive(TestTable, warn)

Output:

image

📝Examples

Saving a configuration:

local Library = loadstring(game:HttpGet("https://raw.githubusercontent.com/Aegians/Config-Library/main/Main.lua"))()

local ESP_Settings = {
  TextColor = Color3.fromRGB(255, 0, 0),
  Outline = true,
  OutlineColor = Color3.fromRGB(0, 0, 0),
  Transparency = 0.7
}

Library:SaveConfig("My Cool Hub/Config.json", ESP_Settings)

image image

Loading a configuration:

local Library = loadstring(game:HttpGet("https://raw.githubusercontent.com/Aegians/Config-Library/main/Main.lua"))()

local ESP_Settings = {}

ESP_Settings = Library:LoadConfig("My Cool Hub/Config.json")

loadstring(game:HttpGet("https://raw.githubusercontent.com/Aegians/Config-Library/main/Main.lua"))():SaveConfig("test.json", {b = "c", d = {e = "f", g = {h = "i", j = {"k"}}}})

->

{"b":"c","d":{"e":"f","g":{"h":"i","j":["k"]}}}

📧Contact Information

config-library's People

Contributors

aegians avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.