feat(scripting): module exports

- add currentSide global
- add script name rule
- add displayName
This commit is contained in:
rhunk
2023-12-25 02:02:27 +01:00
parent 4a4aa28ccf
commit 3edd6ed723
7 changed files with 40 additions and 13 deletions

View File

@@ -64,6 +64,7 @@ class ModDatabase(
"scripts" to listOf(
"name VARCHAR PRIMARY KEY",
"version VARCHAR NOT NULL",
"displayName VARCHAR",
"description VARCHAR",
"author VARCHAR NOT NULL",
"enabled BOOLEAN"
@@ -266,6 +267,7 @@ class ModDatabase(
ModuleInfo(
name = cursor.getStringOrNull("name")!!,
version = cursor.getStringOrNull("version")!!,
displayName = cursor.getStringOrNull("displayName"),
description = cursor.getStringOrNull("description"),
author = cursor.getStringOrNull("author"),
grantedPermissions = emptyList()
@@ -305,14 +307,18 @@ class ModDatabase(
}
availableScripts.forEach { script ->
if (!enabledScriptPaths.contains(script.name)) {
database.execSQL("INSERT OR REPLACE INTO scripts (name, version, description, author, enabled) VALUES (?, ?, ?, ?, ?)", arrayOf(
script.name,
script.version,
script.description,
script.author,
0
))
if (!enabledScriptPaths.contains(script.name) || script != enabledScripts.find { it.name == script.name }) {
database.execSQL(
"INSERT OR REPLACE INTO scripts (name, version, displayName, description, author, enabled) VALUES (?, ?, ?, ?, ?, ?)",
arrayOf(
script.name,
script.version,
script.displayName,
script.description,
script.author,
0
)
)
}
}
}

View File

@@ -7,6 +7,7 @@ import me.rhunk.snapenhance.bridge.scripting.AutoReloadListener
import me.rhunk.snapenhance.bridge.scripting.IPCListener
import me.rhunk.snapenhance.bridge.scripting.IScripting
import me.rhunk.snapenhance.common.scripting.ScriptRuntime
import me.rhunk.snapenhance.common.scripting.bindings.BindingSide
import me.rhunk.snapenhance.common.scripting.impl.ConfigInterface
import me.rhunk.snapenhance.common.scripting.impl.ConfigTransactionType
import me.rhunk.snapenhance.common.scripting.type.ModuleInfo
@@ -63,6 +64,7 @@ class RemoteScriptManager(
fun init() {
runtime.buildModuleObject = { module ->
putConst("currentSide", this, BindingSide.MANAGER.key)
module.registerBindings(
ManagerIPC(ipcListeners),
InterfaceManager(),

View File

@@ -64,7 +64,7 @@ class ScriptsSection : Section() {
.weight(1f)
.padding(end = 8.dp)
) {
Text(text = script.name, fontSize = 20.sp,)
Text(text = script.displayName ?: script.name, fontSize = 20.sp,)
Text(text = script.description ?: "No description", fontSize = 14.sp,)
}
IconButton(onClick = { openSettings = !openSettings }) {