Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/assets/opensb/scripts
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-19 01:16:22 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-19 01:16:22 +1000
commite1645f37fc72e7733b64c51ffbee0370e13cbe29 (patch)
treebdd219080958016e68589476004427cbb50616f5 /assets/opensb/scripts
parent770314fd7e86c0be355f19bd4273ebd12d5bcdc6 (diff)
Support for player entity message commands
Diffstat (limited to 'assets/opensb/scripts')
-rw-r--r--assets/opensb/scripts/opensb/player/commands.lua30
-rw-r--r--assets/opensb/scripts/opensb/player/player.lua2
-rw-r--r--assets/opensb/scripts/opensb/universeclient/universeclient.lua2
-rw-r--r--assets/opensb/scripts/opensb/universeclient/voicemanager.lua (renamed from assets/opensb/scripts/universeClient/opensb/voice_manager.lua)51
-rw-r--r--assets/opensb/scripts/opensb/util/modules.lua31
-rw-r--r--assets/opensb/scripts/universeClient/opensb.lua29
6 files changed, 81 insertions, 64 deletions
diff --git a/assets/opensb/scripts/opensb/player/commands.lua b/assets/opensb/scripts/opensb/player/commands.lua
new file mode 100644
index 0000000..f62e2b8
--- /dev/null
+++ b/assets/opensb/scripts/opensb/player/commands.lua
@@ -0,0 +1,30 @@
+local module = {}
+modules.commands = module
+
+local commands = {}
+local function command(name, func)
+ commands[name] = func
+end
+
+function module.init()
+ for name, func in pairs(commands) do
+ message.setHandler("/" .. name, function(isLocal, _, ...)
+ if not isLocal then
+ return
+ else
+ return func(...)
+ end
+ end)
+ end
+end
+
+
+command("run", function(src)
+ local success, result = pcall(loadstring, src, "/run")
+ if not success then
+ return "^#f00;compile error: " .. result
+ else
+ local success, result = pcall(result)
+ return not success and "^#f00;error: " .. result or sb.printJson(result)
+ end
+end) \ No newline at end of file
diff --git a/assets/opensb/scripts/opensb/player/player.lua b/assets/opensb/scripts/opensb/player/player.lua
new file mode 100644
index 0000000..05cbfb9
--- /dev/null
+++ b/assets/opensb/scripts/opensb/player/player.lua
@@ -0,0 +1,2 @@
+require "/scripts/opensb/util/modules.lua"
+modules("/scripts/opensb/player/", {"commands"}) \ No newline at end of file
diff --git a/assets/opensb/scripts/opensb/universeclient/universeclient.lua b/assets/opensb/scripts/opensb/universeclient/universeclient.lua
new file mode 100644
index 0000000..cad342b
--- /dev/null
+++ b/assets/opensb/scripts/opensb/universeclient/universeclient.lua
@@ -0,0 +1,2 @@
+require "/scripts/opensb/util/modules.lua"
+modules("/scripts/opensb/universeclient/", {"voicemanager"}) \ No newline at end of file
diff --git a/assets/opensb/scripts/universeClient/opensb/voice_manager.lua b/assets/opensb/scripts/opensb/universeclient/voicemanager.lua
index d1c540f..c0aa309 100644
--- a/assets/opensb/scripts/universeClient/opensb/voice_manager.lua
+++ b/assets/opensb/scripts/opensb/universeclient/voicemanager.lua
@@ -4,7 +4,7 @@ local fmt = string.format
local sqrt = math.sqrt
local module = {}
-submodules.voice_manager = module
+modules.voice_manager = module
--constants
local INDICATOR_PATH = "/interface/voicechat/indicator/"
@@ -19,52 +19,35 @@ local LINE_COLOR = {50, 210, 255, 255}
local FONT_DIRECTIVES = "?border=1;333;3337?border=1;333;3330"
local NAME_PREFIX = "^noshadow,white,set;"
-local canvas
-
-local linePaddingDrawable = {
- image = BACK_INDICATOR_IMAGE,
- position = {0, 0},
- color = LINE_COLOR,
- centered = false
-}
-
-local function getLinePadding(a, b)
- linePaddingDrawable.image = BACK_INDICATOR_IMAGE .. fmt("?crop=%i;%i;%i;%i?fade=fff;1", a, 0, b, INDICATOR_SIZE[2])
- linePaddingDrawable.position[1] = a
- return linePaddingDrawable;
+local linePaddingDrawable
+do
+ local drawable = { image = BACK_INDICATOR_IMAGE, position = {0, 0}, color = LINE_COLOR, centered = false }
+ function linePaddingDrawable(a, b)
+ drawable.image = BACK_INDICATOR_IMAGE .. fmt("?crop=%i;%i;%i;%i?fade=fff;1", a, 0, b, INDICATOR_SIZE[2])
+ drawable.position[1] = a
+ return drawable;
+ end
end
-local lineDrawable = {
- line = {{LINE_PADDING, 24}, {10, 24}},
- width = 48,
- color = LINE_COLOR
-}
-
-local function drawTheLine(pos, value)
+local function line(pos, value)
local width = math.floor((LINE_WIDTH * value) + 0.5)
LINE_COLOR[4] = 255 * math.min(1, sqrt(width / 350))
if width > 0 then
- canvas:drawDrawable(getLinePadding(0, math.min(12, width)), pos)
+ canvas:drawDrawable(linePaddingDrawable(0, math.min(12, width)), pos)
if width > 12 then
lineDrawable.line[2][1] = math.min(width, LINE_WIDTH_PADDED)
canvas:drawDrawable(lineDrawable, pos)
if width > LINE_WIDTH_PADDED then
- canvas:drawDrawable(getLinePadding(LINE_WIDTH_PADDED, width), pos)
+ canvas:drawDrawable(linePaddingDrawable(LINE_WIDTH_PADDED, width), pos)
end
end
end
end
-local drawable = {
- image = BACK_INDICATOR_IMAGE,
- centered = false
-}
+local canvas
-local textPositioning = {
- position = {0, 0},
- horizontalAnchor = "left",
- verticalAnchor = "mid"
-}
+local drawable = { image = BACK_INDICATOR_IMAGE, centered = false }
+local textPositioning = { position = {0, 0}, horizontalAnchor = "left", verticalAnchor = "mid" }
local hoveredSpeaker = nil
local hoveredSpeakerIndex = 1
@@ -78,7 +61,7 @@ end
local function drawSpeakerBar(mouse, pos, speaker, i)
drawable.image = BACK_INDICATOR_IMAGE
canvas:drawDrawable(drawable, pos)
- drawTheLine(pos, 1 - math.sqrt(math.min(1, math.max(0, speaker.loudness / -50))))
+ line(pos, 1 - sqrt(math.min(1, math.max(0, speaker.loudness / -50))))
local hovering = not speaker.isLocal and mouseOverSpeaker(mouse, pos)
textPositioning.position = {pos[1] + 49, pos[2] + 24}
@@ -128,7 +111,6 @@ local function drawIndicators()
local mousePosition = canvas:mousePosition()
local basePos = {screenSize[1] - 350, 50}
- -- sort it ourselves for now
local speakersRemaining, speakers = {}, {}
local hoveredSpeakerId = nil
if hoveredSpeaker then
@@ -140,7 +122,6 @@ local function drawIndicators()
end
local speakerCount = 0
- local now = os.clock()
for i, speaker in pairs(voice.speakers()) do
local speakerId = speaker.speakerId
speakersRemaining[speakerId] = true
diff --git a/assets/opensb/scripts/opensb/util/modules.lua b/assets/opensb/scripts/opensb/util/modules.lua
new file mode 100644
index 0000000..2ce7086
--- /dev/null
+++ b/assets/opensb/scripts/opensb/util/modules.lua
@@ -0,0 +1,31 @@
+modules = setmetatable({}, {__call = function(this, path, names)
+ for i, name in pairs(names) do
+ require(path .. name .. ".lua")
+ end
+end})
+
+local modules, type = modules, type
+local function call(func, ...)
+ if type(func) == "function" then
+ return func(...)
+ end
+end
+
+function init(...)
+ script.setUpdateDelta(1)
+ for i, module in pairs(modules) do
+ call(module.init, ...)
+ end
+end
+
+function update(...)
+ for i, module in pairs(modules) do
+ call(module.update, ...)
+ end
+end
+
+function uninit(...)
+ for i, module in pairs(modules) do
+ call(module.uninit, ...)
+ end
+end \ No newline at end of file
diff --git a/assets/opensb/scripts/universeClient/opensb.lua b/assets/opensb/scripts/universeClient/opensb.lua
deleted file mode 100644
index c1b4dea..0000000
--- a/assets/opensb/scripts/universeClient/opensb.lua
+++ /dev/null
@@ -1,29 +0,0 @@
-submodules = {}
-
-require "/scripts/universeClient/opensb/voice_manager.lua"
-
-local submodules, type = submodules, type
-local function call(func, ...)
- if type(func) == "function" then
- return func(...)
- end
-end
-
-function init(...)
- script.setUpdateDelta(1)
- for i, module in pairs(submodules) do
- call(module.init, ...)
- end
-end
-
-function update(...)
- for i, module in pairs(submodules) do
- call(module.update, ...)
- end
-end
-
-function uninit(...)
- for i, module in pairs(submodules) do
- call(module.uninit, ...)
- end
-end \ No newline at end of file