Docs - kiwidotzip/sin GitHub Wiki

Installation

Add sin to the "requires" array in your metadata.json

Importing the Base.js file

import Base from "<the file path to the sin/main/base.js file here>

Creating the sin const

const sin = new Base("moduleName", "colorScheme path", "moduleName - for the gui title", "config path - optional")

Adding elements to the GUI

const sin = /*...*/
    .addButton({
        /*...*/
    })
    .addSwitch({
        /*...*/
    })

Element types

  • Button
.addButton({
    category: "string",
    configName: "string",
    title: "string", // optional
    description: "string", // optional
    subcategory: "string",
    onClick: () => print("string"),
    shouldShow: data => data.confName // optional
})
  • Switch/Toggle
.addSwitch({
    category: "string",
    configName: "string",
    title: "string", // optional
    description: "string", // optional
    subcategory: "string",
    value: Num|String|Bool, // optional
    shouldShow: data => data.confName, // optional
    registerListener: (oldV, newV) => print(oldV + " -> " + newV) // optional
})
  • Text input
.addTextInput({
    category: "string",
    configName: "string",
    title: "string", // optional
    description: "string", // optional
    value: Num|String|Bool, // optional
    placeHolder: "string", // optional
    subcategory: "string",
    shouldShow: data => data.confName, // optional
    registerListener: (oldV, newV) => print(oldV + " -> " + newV) // optional
})
  • Slider
.addSlider({
    category: "string",
    configName: "string",
    title: "string", // optional
    description: "string", // optional
    options: [Num, Num],
    value: Num|String|Bool, // optional
    subcategory: "string",
    shouldShow: data => data.confName, // optional
    registerListener: (oldV, newV) => print(oldV + " -> " + newV) // optional
})
  • ColorPicker
.addColorPicker({
    category: "string",
    configName: "string",
    title: "string", // optional
    subcategory: "string",
    value: Array, // optional
    shouldShow: data => data.confName, // optional
    registerListener: (oldV, newV) => print(oldV + " -> " + newV) // optional
})
  • Dropdown
.addDropDown({
    category: "string",
    configName: "string",
    title: "string", // optional
    description: "string", // optional
    subcategory: "string",
    options: Array,
    value: Num, // optional
    shouldShow: data => data.confName, // optional
    registerListener: (oldV, newV) => print(oldV + " -> " + newV) // optional
})
  • Text paragraph
.addTextParagraph({
    category: "string",
    configName: "string",
    title: "string", // optional
    description: "string",
    subcategory: "string", 
    centered: Boolean, // optional
    shouldShow: data => data.confName, // optional
})
  • Keybind
.addKeybind({
    category: "string",
    configName: "string",
    title: "string", // optional
    description: "string", // optional
    subcategory: "string",
    value: Num|String, // optional
    shouldShow: data => data.confName, // optional
    registerListener: (oldV, newV) => print(oldV + " -> " + newV) // optional
})

Additonal methods

  • getGui - Returns the custom GUI instance
  • getHandler - Returns the handler instance
  • openGui - Opens the GUI
  • closeGui - Closes the GUI
  • onOpenGui - Runs the given func on GUI open
  • onCloseGui - Runs the given func on GUI close
  • setSize - Sets the GUI size
  • setRatio - Sets the GUI ratio
  • setValue - Sets a SinGUI setting value
  • setConfigValue - Sets a config value

Exporting the config

.addXYZ({
    /* ... */
})
.setSize(width, height) // optional
/* ... Other methods ... */

export default () => sin.settings
// OR
export default sin.settings

Importing the config in other file

import Config from "config.js file path"

// Use Config() if you did `export default () => sin.settings`, or Config if you did `export default sin.settings`
// We'll continue to use Config() in this example code

register("command", () => {
    Config().getConfig().openGui() // Opens the Config GUI
}).setName("openGui")

register("worldLoad", () => {
    ChatLib.chat(Config().exampleValue) // Sends the exampleValue's value in chat
})

Config().getConfig()
    .onOpenGui(() => ChatLib.chat("GUI opened.")) // Sends a message on GUI open
    .onCloseGui(() => ChatLib.chat("GUI closed.")) // Sends a message on GUI close
    .registerListener("exampleValue", (oldV, newV) => ChatLib.chat(`${oldV} -> ${newV}`)) // Sends a message when exampleValue changes

tska's FeatureManager

import Config from "../config"
import { FeatureManager } from "../../tska/event/FeatureManager"

const FeatManager = new FeatureManager(Config().getConfig())
const example = FeatManager.createFeature("exampleConfigVal")

example
    .onRegister(() => ChatLib.chat(`registered`))
    .register("stepFps", () => ChatLib.chat(`meow`), 1)
    .onUnregister(() => ChatLib.chat(`unregistered`))