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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2025-02-01 13:29:49 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2025-02-01 13:29:49 +1100
commit574c62bc32a99891295ecdcf671c7e3145c7aab2 (patch)
tree1e2bc58b3bf34b649529c5330c60483bbd033fcf
parent690d47995f6733eef9b28bd2ebef2c237b61b159 (diff)
allow item pasting to stack
-rw-r--r--assets/opensb/scripts/opensb/player/copy_paste.lua18
-rw-r--r--source/core/scripting/StarUtilityLuaBindings.cpp1
-rw-r--r--source/frontend/StarInventory.cpp7
3 files changed, 20 insertions, 6 deletions
diff --git a/assets/opensb/scripts/opensb/player/copy_paste.lua b/assets/opensb/scripts/opensb/player/copy_paste.lua
index 2a15af4..f301427 100644
--- a/assets/opensb/scripts/opensb/player/copy_paste.lua
+++ b/assets/opensb/scripts/opensb/player/copy_paste.lua
@@ -24,13 +24,18 @@ local function copyItem()
local item = player.swapSlotItem() or player.primaryHandItem() or player.altHandItem()
if not item then return end
- clipboard.setText(sb.printJson(item, 2))
- local message = string.format("Copied ^cyan;%s^reset; to clipboard", getItemName(item))
+ local message = "^#f00;Failed to write to clipboard^reset;"
+ if clipboard.setText(sb.printJson(item, 2)) then
+ message = string.format("Copied ^cyan;%s^reset; to clipboard", getItemName(item))
+ end
interface.queueMessage(message, 4, 0.5)
end
local function pasteItem()
- if player.swapSlotItem() then return end
+ if not clipboard.available() then
+ return interface.queueMessage("^#f00;Clipboard unavailable^reset;", 4, 0.5)
+ end
+ local swap = player.swapSlotItem()
local data = getClipboardText()
if not data then return end
@@ -38,6 +43,13 @@ local function pasteItem()
if not success then
popupError("Error parsing clipboard item", result)
else
+ if swap then
+ if swap.name == result.name and sb.jsonEqual(swap.parameters, result.parameters) then
+ result.count = (tonumber(result.count) or 1) + (tonumber(swap.count) or 1)
+ else
+ return interface.queueMessage("^#f00;Cursor is occupied^reset;", 4, 0.5)
+ end
+ end
local success, err = pcall(player.setSwapSlotItem, result)
if not success then popupError("Error loading clipboard item", err)
else
diff --git a/source/core/scripting/StarUtilityLuaBindings.cpp b/source/core/scripting/StarUtilityLuaBindings.cpp
index 98ad239..8fb65cc 100644
--- a/source/core/scripting/StarUtilityLuaBindings.cpp
+++ b/source/core/scripting/StarUtilityLuaBindings.cpp
@@ -120,6 +120,7 @@ LuaCallbacks LuaBindings::makeUtilityCallbacks() {
callbacks.registerCallback("replaceTags", UtilityCallbacks::replaceTags);
callbacks.registerCallback("parseJsonSequence", [](String const& json) { return Json::parseSequence(json); });
callbacks.registerCallback("jsonMerge", [](Json const& a, Json const& b) { return jsonMerge(a, b); });
+ callbacks.registerCallback("jsonEqual", [](Json const& a, Json const& b) { return a == b; });
callbacks.registerCallback("jsonQuery", [](Json const& json, String const& path, Json const& def) { return json.query(path, def); });
callbacks.registerCallback("makeRandomSource", [](Maybe<uint64_t> seed) { return seed ? RandomSource(*seed) : RandomSource(); });
callbacks.registerCallback("makePerlinSource", [](Json const& config) { return PerlinF(config); });
diff --git a/source/frontend/StarInventory.cpp b/source/frontend/StarInventory.cpp
index 3730c9b..1c42a0d 100644
--- a/source/frontend/StarInventory.cpp
+++ b/source/frontend/StarInventory.cpp
@@ -450,12 +450,13 @@ void InventoryPane::update(float dt) {
}
if (auto item = inventory->swapSlotItem()) {
+ float pitch = 1.f - ((float)item->count() / (float)item->maxStack()) * .2f;
if (!m_currentSwapSlotItem || !item->matches(*m_currentSwapSlotItem, true))
- context->playAudio(RandomSource().randFrom(m_pickUpSounds));
+ context->playAudio(RandomSource().randFrom(m_pickUpSounds), 0, 1.f, pitch);
else if (item->count() > m_currentSwapSlotItem->count())
- context->playAudio(RandomSource().randFrom(m_someUpSounds));
+ context->playAudio(RandomSource().randFrom(m_someUpSounds), 0, 1.f, pitch);
else if (item->count() < m_currentSwapSlotItem->count())
- context->playAudio(RandomSource().randFrom(m_someDownSounds));
+ context->playAudio(RandomSource().randFrom(m_someDownSounds), 0, 1.f, pitch);
m_currentSwapSlotItem = item->descriptor();
} else {