Skip to content

Commit

Permalink
Merge pull request #543 from Xian55/feature/chat-extract-v2
Browse files Browse the repository at this point in the history
Addon: [1.7.49] - Feature: `ChatReader`: Allows `@` character to be extracted with less processing on both ends
  • Loading branch information
Xian55 authored Sep 23, 2023
2 parents d076472 + 504b3ac commit 20d977f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
35 changes: 22 additions & 13 deletions Addons/DataToColor/DataToColor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,17 @@ function DataToColor:CreateFrames()
Pixel(int, DataToColor.globalTime, GLOBAL_TIME_CELL)
end

local function IdxToRadix(input)
if input == 1 then
return 10000
elseif input == 2 then
return 100
elseif input == 3 then
return 1
end
return 0
end

local function updateFrames()
if not SETUP_SEQUENCE and globalCounter >= initPhase then
Pixel(int, 0, 0)
Expand Down Expand Up @@ -873,22 +884,20 @@ function DataToColor:CreateFrames()
DataToColor.ChatQueue:shift()
chatMsgHead = -2
else
local s = sub(e.msg, chatMsgHead, chatMsgHead + 2)
local ASCII = ''
for i = 1, len(s) do
local c = upper(sub(s, i))
local b = byte(c) or 32

if b == 32 or b > 100 then -- space has no upper
b = byte('@')
local part = sub(e.msg, chatMsgHead, chatMsgHead + 2)
local number = 0
local length = len(part)
for i = 1, length do
local c = upper(sub(part, i))
local b = byte(c) or 32 -- SPACE character fallback
if b > 100 then
b = 32
end

ASCII = ASCII .. b
number = number + (b * IdxToRadix(i + (3 - length)))
end

--print(e.length, chatMsgHead, "'" .. s .. "'", ASCII)

Pixel(int, tonumber(ASCII), 98)
--print(e.length, chatMsgHead, "'" .. part .. "'", number)
Pixel(int, number, 98)
Pixel(int, e.type * 1000000 + 1000 * e.length + chatMsgHead, 99)
end
end
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor.toc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors
## Version: 1.7.48
## Version: 1.7.49
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
2 changes: 1 addition & 1 deletion Core/Addon/AddonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void Update()
TargetName =
creatureDb.Entries.TryGetValue(playerReader.TargetId, out string? name)
? name
: reader.GetString(16) + reader.GetString(17);
: reader.GetString(16).Trim() + reader.GetString(17).Trim();
}

if (lastMouseOverId != playerReader.MouseOverId)
Expand Down
2 changes: 1 addition & 1 deletion Core/AddonDataProvider/IAddonDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ string GetString(int index)
n = color % 100;
if (n > 0) TextBuilder.Append((char)n);

return TextBuilder.ToString().Trim();
return TextBuilder.ToString();
}
}
6 changes: 3 additions & 3 deletions Core/Chat/ChatReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Update(IAddonDataProvider reader)
else if (_head == head)
return;

string part = reader.GetString(cMsg).Replace('@', ' ');
string part = reader.GetString(cMsg);

sb.Append(part);

Expand All @@ -68,9 +68,9 @@ public void Update(IAddonDataProvider reader)

int firstSpaceIdx = text.AsSpan().IndexOf(' ');
string author = text.AsSpan(0, firstSpaceIdx).ToString();
text = text.AsSpan(firstSpaceIdx + 1).ToString();
string msg = text.AsSpan(firstSpaceIdx + 1).ToString();

ChatMessageEntry entry = new(DateTime.Now, type, author, text);
ChatMessageEntry entry = new(DateTime.Now, type, author, msg);
Messages.Add(entry);
logger.LogInformation(entry.ToString());
}
Expand Down

0 comments on commit 20d977f

Please sign in to comment.