diff options
| author | Jomar Milan <jomarm@jomarm.com> | 2025-08-23 13:02:19 -0700 |
|---|---|---|
| committer | Jomar Milan <jomarm@jomarm.com> | 2025-08-23 13:02:19 -0700 |
| commit | 98c89b9c66394281c5c7bf1f6ec38398e6bbd46b (patch) | |
| tree | 3ee108059af3f578387beeb67b79b0365b2f9422 | |
| download | UserScripts-master.tar.gz UserScripts-master.zip | |
| -rw-r--r-- | .stylua.toml | 1 | ||||
| -rw-r--r-- | UserScripts.lua | 55 | ||||
| -rw-r--r-- | UserScriptsBanner.png | bin | 0 -> 1925 bytes | |||
| -rw-r--r-- | UserScriptsIcon.png | bin | 0 -> 573 bytes | |||
| -rw-r--r-- | mod.json | 20 |
5 files changed, 76 insertions, 0 deletions
diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..eb6f5ec --- /dev/null +++ b/.stylua.toml @@ -0,0 +1 @@ +call_parentheses = "NoSingleString" diff --git a/UserScripts.lua b/UserScripts.lua new file mode 100644 index 0000000..a43c472 --- /dev/null +++ b/UserScripts.lua @@ -0,0 +1,55 @@ +-- Press Shift+F1 to display debug output in-game +local Menu = require "necro.menu.Menu" + +local UserScripts = {} + +UserScripts.callbacks = {} + +-- Other scripts can't directly modify a module member, so provide a function +-- to do it with +function UserScripts.add(label, callback) + UserScripts.callbacks[label] = callback +end + +-- The menu event is an EnumSelector event, so use the key field. +event.menu.add("pauseOptions", { key = "pause", sequence = 1 }, function(ev) + if not ev.menu or not ev.menu.entries then + return + end + + -- 8th index: without any other mods, this is after "Customize" + table.insert(ev.menu.entries, 8, { + label = "User Scripts", + action = function() + Menu.open "scriptsList" + end, + }) +end) + +-- key corresponds to what is passed to Menu.open +event.menu.add("scriptsList", { key = "scriptsList", sequence = 0 }, function(ev) + local entries = {} + + for index, callback in pairs(UserScripts.callbacks) do + table.insert(entries, { + label = index, + action = callback, + }) + end + + table.insert(entries, { + id = "_done", + sound = "UIBack", + label = L "Done", + action = function() + Menu.close() + end, + }) + + ev.menu = { + label = "Script List", + entries = entries, + } +end) + +return UserScripts diff --git a/UserScriptsBanner.png b/UserScriptsBanner.png Binary files differnew file mode 100644 index 0000000..2299875 --- /dev/null +++ b/UserScriptsBanner.png diff --git a/UserScriptsIcon.png b/UserScriptsIcon.png Binary files differnew file mode 100644 index 0000000..e8c60df --- /dev/null +++ b/UserScriptsIcon.png diff --git a/mod.json b/mod.json new file mode 100644 index 0000000..665dee3 --- /dev/null +++ b/mod.json @@ -0,0 +1,20 @@ +{ + "namespace": "UserScripts", + "displayName": "User Scripts", + "version": "1.0.0", + "synchronyVersion": "4.1.1", + "description": "A simple mod which adds a menu option to make it convenient to run callbacks for quick scriptable actions and debug mod scripts.\n\nRequire the mod without making a hard dependency like this:\n\nlocal hasUserScripts, UserScripts = pcall(require, \"UserScripts.UserScripts\")\n\nThen, the success value (hasUserScripts) can be checked before using UserScripts.add(label, callback).", + "author": "TheLegendaryOrb", + "dependencies": {}, + "api": {"scriptPath":""}, + "icon": "UserScriptsIcon.png", + "banner": "UserScriptsBanner.png", + "tags": [], + "name": "UserScripts_io_5105664", + "changelog": "", + "homepageURL": "https://mod.io/g/crypt/m/userscripts", + "modioID": "5105664", + "modioUserID": 24922981, + "pendingVersion": "1.0.0", + "visibility": 0 +}
\ No newline at end of file |
