Skip to content

Commit 12e866e

Browse files
committed
text length proxy functions + text event
required to make a basic but proper typing system that plays a sound when letters appear using the truncate mode or with the chat typing input, for example
1 parent a65435e commit 12e866e

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

lua/pac3/core/client/parts/event.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,25 @@ PART.OldEvents = {
30373037
return string.format("steamid: [%s %s]", self.Operator, idSumm)
30383038
end
30393039
},
3040+
3041+
text = {
3042+
operator_type = "string",
3043+
tutorial = "compares a text part's text\nthis can be useful with the changed operator",
3044+
arguments = {{uid = "string"}, {compare = "string"}, {truncated = "boolean"}},
3045+
callback = function(self, ent, uid, compare, truncated)
3046+
local part = self:GetOrFindCachedPart(uid)
3047+
if part and part:IsValid() and part.ClassName == "text" then
3048+
if not truncated then
3049+
return self:StringOperator(part.DisplayTextPreTruncate, compare)
3050+
else
3051+
return self:StringOperator(part.DisplayTextPostTruncate, compare)
3052+
end
3053+
end
3054+
return false
3055+
end,
3056+
},
3057+
3058+
30403059
}
30413060

30423061

lua/pac3/core/client/parts/proxy.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,33 @@ end
16031603

16041604
PART.Inputs.healthmod_bar_remaining_bars = PART.Inputs.pac_healthbar_remaining_bars
16051605

1606+
PART.Inputs.text_length_raw = function(self, uid)
1607+
local part = self:GetOrFindCachedPart(uid)
1608+
if not IsValid(part) then return 0 end
1609+
if part.ClassName ~= "text" then return 0 end
1610+
return part.DisplayTextLengthPreTruncate or 0
1611+
end
1612+
PART.Inputs.text_length_raw_nospaces = function(self, uid)
1613+
local part = self:GetOrFindCachedPart(uid)
1614+
if not IsValid(part) then return 0 end
1615+
if part.ClassName ~= "text" then return 0 end
1616+
if not part.DisplayTextPreTruncate then return 0 end
1617+
local chars = 0
1618+
for c=1,#part.DisplayTextPreTruncate do
1619+
if part.DisplayTextPreTruncate[c] ~= " " then
1620+
chars = chars + 1
1621+
end
1622+
end
1623+
return chars
1624+
end
1625+
PART.Inputs.text_length_truncated = function(self, uid)
1626+
local part = self:GetOrFindCachedPart(uid)
1627+
if not IsValid(part) then return 0 end
1628+
if part.ClassName ~= "text" then return 0 end
1629+
return part.DisplayTextLengthPostTruncate or 0
1630+
end
1631+
1632+
16061633

16071634
local proxy_verbosity = CreateConVar("pac_proxy_verbosity", 1, FCVAR_ARCHIVE, "whether to print info when running pac_proxy")
16081635
net.Receive("pac_proxy", function()

lua/pac3/core/client/parts/text.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,10 @@ function PART:OnDraw()
626626
end
627627
end
628628

629+
DisplayText = tostring(DisplayText)
629630
::DRAW::
631+
self.DisplayTextLengthPreTruncate = #DisplayText
632+
self.DisplayTextPreTruncate = DisplayText
630633
if self.Truncate then
631634

632635
if self.TruncateSkipCharacters_tbl then
@@ -665,7 +668,9 @@ function PART:OnDraw()
665668
DisplayText = string.Replace(DisplayText,"! ","!\n")
666669
DisplayText = string.Replace(DisplayText,"? ","?\n")
667670
end
668-
671+
self.DisplayTextPostTruncate = DisplayText
672+
self.DisplayTextLengthPostTruncate = #DisplayText
673+
669674
if self.Wrap or self.ForceNewline then
670675
if (self.lines == nil) or (self.previous_str ~= DisplayText) or self.request_line_recalculation then
671676
self.lines = self:WrapString(DisplayText, self.WrapWidth)

0 commit comments

Comments
 (0)