Skip to content

Commit

Permalink
adds api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
2jammers committed Sep 13, 2024
1 parent 7ec79e3 commit 64b55f9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added API documentation to every function within the code

## [0.3.0] - 2024-09-12

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/Library/Action.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local plugin: Plugin = script:FindFirstAncestorWhichIsA("Plugin")

-- Functions

--[=[
Creates a new plugin action that can be bound to a keycode or placed in studio's topbar.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/action#new)
]=]
local function New(
name: string,
description: string,
Expand Down
26 changes: 26 additions & 0 deletions src/Library/Data.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local Cache = {}

-- Functions

--[=[
Gets the value of a key in the current session's cache or directly from the last save.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/data#set)
]=]
local function Get(key: string, useCache: boolean?): any
if useCache == false then
return plugin:GetSetting(key)
Expand All @@ -14,15 +19,30 @@ local function Get(key: string, useCache: boolean?): any
return Result
end

--[=[
Sets a key within the current session's cache to be saved on shutdown.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/data#set)
]=]
local function Set(key: string, value: any, ignoreCacheIndex: boolean?)
assert(ignoreCacheIndex == false and Cache[key], "No such key found in cache")
Cache[key] = value
end

--[=[
Saves a key to the user's local data directly without interacting with cache.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/data#save)
]=]
local function Save(key: string, value: any)
plugin:SetSetting(key, value)
end

--[=[
Removes a key from the user's local data.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/data#remove)
]=]
local function Remove(key: string, useCache: boolean?)
if useCache == false then
Save(key, nil)
Expand All @@ -31,6 +51,12 @@ local function Remove(key: string, useCache: boolean?)
Set(key, nil)
end

--[=[
Updates the value of a key using the current session's cache, uses a callback function
to calculate a new returned value.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/data#update)
]=]
local function Update(key: string, callback: (value: any) -> any, useCache: boolean?)
local Result = callback(Get(key))
assert(Result, "Must resolve a value in the update callback")
Expand Down
21 changes: 21 additions & 0 deletions src/Library/Interface/Menu.luau
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,42 @@ local function PluginMenu(name: string, children: Types.MenuChildren, icon: stri
return Menu
end

--[=[
Creates a new plugin menu that is visually similar to a context menu.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/menu#new)
]=]
local function New(name: string, children: Types.MenuChildren, icon: string?)
local self = setmetatable({
Menu = PluginMenu(name, children, icon or ""),
}, Index)
return self
end

--[=[
Appends a new menu to the parent menu.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/menu#append)
]=]
function Index.Append(self: any, children: Types.MenuChildren)
self.Menu:AddMenu()
end

--[=[
Clears the menu, removing any items left inside.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/menu#clear)
]=]
function Index.Clear(self: any)
self.Menu:Clear()
end

--[=[
Shows the menu, and runs the provided callback giving the chosen `PluginAction` as an
argument. The callback will not run if the user does not choose an option.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/menu#show)
]=]
function Index.Show(self: any, callback: (id: PluginAction) -> ())
local Identifier = self.Menu:ShowAsync()
if Identifier then
Expand Down
12 changes: 11 additions & 1 deletion src/Library/Interface/Toolbar.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Index.__index = Index

-- Functions

--[=[
Creates a new plugin toolbar with a specified name.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/toolbar#new)
]=]
local function New(name: string)
local self = setmetatable({
Toolbar = plugin:CreateToolbar(name),
Expand All @@ -15,7 +20,12 @@ local function New(name: string)
return self
end

function Index.Button(self: any, name: string, tooltip: string, image: string, onClick: () -> ())
--[=[
Creates a new toolbar button using the toolbar it was created on.
[Learn More](https://luminlabsdev.github.io/plugin-framework/api/toolbar#append)
]=]
function Index.Append(self: any, name: string, tooltip: string, image: string, onClick: () -> ())
local Button = self.Toolbar:CreateButton(name, tooltip, image)
Button.Click:Connect(onClick)
table.insert(self.Buttons, Button)
Expand Down
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lumin/plugin-framework"
version = "0.3.0"
version = "0.4.0"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"

Expand Down

0 comments on commit 64b55f9

Please sign in to comment.