Skip to content

Commit

Permalink
add option to strip advanced copy paste info out
Browse files Browse the repository at this point in the history
  • Loading branch information
Regisle committed Oct 23, 2024
1 parent 78b52c9 commit 8130f33
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Classes/ItemsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1170,13 +1170,27 @@ function ItemsTabClass:Draw(viewPort, inputEvents)
if event.type == "KeyDown" then
if event.key == "v" and IsKeyDown("CTRL") then
local newItem = Paste()
if newItem:find("{ ", 0, true) then
main:OpenConfirmPopup("Warning", "\"Advanced Item Descriptions\" (Ctrl+Alt+c) are unsupported.\n\nAbort paste?", "OK", function()
self:SetDisplayItem()
end)
end
if newItem then
self:CreateDisplayItemFromRaw(newItem, true)
if newItem:find("{ ", 0, true) then
local controls = { }
controls.label = new("LabelControl", nil, {0, 30, 0, 16}, "^7\"Advanced Item Descriptions\" (Ctrl+Alt+c) are unsupported.\n\nIf this is not an advanced item copy paste or if you wish to procced anyway click proceed.\n\nOr you can removed the advanced info from the item and paste as a normal item.")

Check warning on line 1176 in src/Classes/ItemsTab.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (procced)
controls.close = new("ButtonControl", nil, {-175, 140, 150, 20}, "^7Proceed Anyway", function()
self:CreateDisplayItemFromRaw(newItem, true)
main:ClosePopup()
end)
controls.strip = new("ButtonControl", nil, {0, 140, 150, 20}, "^7Remove Advanced Info", function()
newItem = itemLib.stripAdvancedCopyPaste(newItem)
self:CreateDisplayItemFromRaw(newItem, true)
main:ClosePopup()
end)
controls.abort = new("ButtonControl", nil, {175, 140, 150, 20}, "^7Abort", function()
self:SetDisplayItem()
main:ClosePopup()
end)
main:OpenPopup(570, 170, "Warning", controls)
else
self:CreateDisplayItemFromRaw(newItem, true)
end
end
elseif event.key == "e" then
local mOverControl = self:GetMouseOverControl()
Expand Down
31 changes: 31 additions & 0 deletions src/Modules/ItemTools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,37 @@ function itemLib.formatModLine(modLine, dbMode)
return colorCode..line
end

function itemLib.stripAdvancedCopyPaste(rawItem)
local rawLines = {}
for line in rawItem:gmatch("%s*([^\n]*%S)") do
t_insert(rawLines, line)
end
local line = 1
local newItem = ""
while rawLines[line] do
if rawLines[line]:match("^{ .*}") and rawLines[line+1] then
local line2 = line + 1
while rawLines[line2] and not rawLines[line2]:match("^{ .*}") and not (rawLines[line2] == "--------") do
if rawLines[line2]:match("^%(.*%)") then
rawLines[line2] = ""
else
rawLines[line2] = rawLines[line2]:gsub(" — Unscalable Value", ""):gsub(" %- Unscalable Value", "")
local val, range = rawLines[line2]:gsub("%-","%%%-"):match("(.*)%((.*)%)[ %%]")
while range do
rawLines[line2] = rawLines[line2]:gsub("%("..range.."%)","")
val, range = rawLines[line2]:gsub("%-","%%%-"):match("(.*)%((.*)%)[ %%]")
end
end
line2 = line2 + 1
end
else
newItem = newItem..rawLines[line]..(rawLines[line+1] and "\n" or "")
end
line = line + 1
end
return newItem
end

itemLib.wiki = {
key = "F1",
openGem = function(gemData)
Expand Down

0 comments on commit 8130f33

Please sign in to comment.