Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon: [1.7.49] - Feature: ChatReader: Allows @ character to be extracted with less processing on both ends #543

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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