Refactor delete note and copy paste to print note
This commit is contained in:
@@ -42,6 +42,100 @@ function shared.Noter.Init()
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function DeleteNotes(name, args)
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Delete note command received for: %s", ModuleName, name))
|
||||||
|
end
|
||||||
|
local range = args[4]
|
||||||
|
if range then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Range received for delete note: %s", ModuleName, range))
|
||||||
|
end
|
||||||
|
local indices = shared.Split(range, "..")
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Indices for range deletion: %s", ModuleName,
|
||||||
|
table.concat(indices, ", ")))
|
||||||
|
shared.dumpTable(indices)
|
||||||
|
end
|
||||||
|
local start = tonumber(indices[1])
|
||||||
|
local finish = tonumber(indices[2])
|
||||||
|
|
||||||
|
if not start then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Invalid start range for delete note: %s", ModuleName,
|
||||||
|
tostring(start)))
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not finish then finish = start end
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Deleting note range %s to %s for: %s", ModuleName, start, finish, name))
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = start, finish do
|
||||||
|
if not Heimdall_Data.config.notes[name] then Heimdall_Data.config.notes[name] = {} end
|
||||||
|
if not Heimdall_Data.config.notes[name][i] then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Note at index %s does not exist", ModuleName, i))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Deleting note %s at index %s", ModuleName, name, i))
|
||||||
|
shared.dumpTable(Heimdall_Data.config.notes[name][i])
|
||||||
|
end
|
||||||
|
Heimdall_Data.config.notes[name][i] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function PrintNotes(name, args)
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Print note command received for: %s", ModuleName, name))
|
||||||
|
end
|
||||||
|
local range = args[3]
|
||||||
|
if range then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Range received for print note: %s", ModuleName, range))
|
||||||
|
end
|
||||||
|
local indices = shared.Split(range, "..")
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Indices for range printing: %s", ModuleName,
|
||||||
|
table.concat(indices, ", ")))
|
||||||
|
shared.dumpTable(indices)
|
||||||
|
end
|
||||||
|
local start = tonumber(indices[1])
|
||||||
|
local finish = tonumber(indices[2])
|
||||||
|
|
||||||
|
if not start then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Invalid start range for print note: %s", ModuleName,
|
||||||
|
tostring(start)))
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not finish then finish = start end
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Printing note range %s to %s for: %s", ModuleName, start, finish, name))
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = start, finish do
|
||||||
|
if not Heimdall_Data.config.notes[name] then Heimdall_Data.config.notes[name] = {} end
|
||||||
|
if not Heimdall_Data.config.notes[name][i] then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Note at index %s does not exist", ModuleName, i))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Printing note %s at index %s", ModuleName, name, i))
|
||||||
|
shared.dumpTable(Heimdall_Data.config.notes[name][i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Here's the plan:
|
-- Here's the plan:
|
||||||
-- Implement a "note" command, that will do everything
|
-- Implement a "note" command, that will do everything
|
||||||
-- Saying "note <name> <note>" will add a note to the list for the character
|
-- Saying "note <name> <note>" will add a note to the list for the character
|
||||||
@@ -101,51 +195,9 @@ function shared.Noter.Init()
|
|||||||
end
|
end
|
||||||
local note = strtrim(args[3])
|
local note = strtrim(args[3])
|
||||||
if note == "delete" then
|
if note == "delete" then
|
||||||
if Heimdall_Data.config.noter.debug then
|
DeleteNotes(name, args)
|
||||||
print(string.format("[%s] Delete note command received for: %s", ModuleName, name))
|
elseif string.find(note, "%d") then
|
||||||
end
|
PrintNotes(name, args)
|
||||||
local range = args[4]
|
|
||||||
if range then
|
|
||||||
if Heimdall_Data.config.noter.debug then
|
|
||||||
print(string.format("[%s] Range received for delete note: %s", ModuleName, range))
|
|
||||||
end
|
|
||||||
local indices = shared.Split(range, "..")
|
|
||||||
if Heimdall_Data.config.noter.debug then
|
|
||||||
print(string.format("[%s] Indices for range deletion: %s", ModuleName,
|
|
||||||
table.concat(indices, ", ")))
|
|
||||||
shared.dumpTable(indices)
|
|
||||||
end
|
|
||||||
local start = tonumber(indices[1])
|
|
||||||
local finish = tonumber(indices[2])
|
|
||||||
|
|
||||||
if not start then
|
|
||||||
if Heimdall_Data.config.noter.debug then
|
|
||||||
print(string.format("[%s] Invalid start range for delete note: %s", ModuleName,
|
|
||||||
tostring(start)))
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if not finish then finish = start end
|
|
||||||
if Heimdall_Data.config.noter.debug then
|
|
||||||
print(string.format("[%s] Deleting note range %s to %s for: %s", ModuleName, start, finish, name))
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = start, finish do
|
|
||||||
if not Heimdall_Data.config.notes[name] then Heimdall_Data.config.notes[name] = {} end
|
|
||||||
if not Heimdall_Data.config.notes[name][i] then
|
|
||||||
if Heimdall_Data.config.noter.debug then
|
|
||||||
print(string.format("[%s] Note at index %s does not exist", ModuleName, i))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if Heimdall_Data.config.noter.debug then
|
|
||||||
print(string.format("[%s] Deleting note %s at index %s", ModuleName, name, i))
|
|
||||||
shared.dumpTable(Heimdall_Data.config.notes[name][i])
|
|
||||||
end
|
|
||||||
Heimdall_Data.config.notes[name][i] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user