Skip to content

Commit b3f18af

Browse files
committed
refactor(Color): add weak caching
- Add weak instance caching. - Annotate `r`, `g`, `b`, and `a` class members as private. Although instances are still mutable, this change will trigger language server warnings when indexing these fields; assuming LuaLS is present. - Translations: Get boss types and register/retire labels from the game instead of our own translations.
1 parent 07434bf commit b3f18af

20 files changed

Lines changed: 249 additions & 141 deletions

File tree

SSV2/includes/features/online/yim_resupplier/YimResupplierV3.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ function YRV3:init()
9999
self.m_sell_script_disp_name = "None"
100100
self.m_last_error = ""
101101
self.m_businesses = { safes = {} }
102-
self.m_boss_types_avail = { { name = "GB_BOSS" --[[VIP]], id = 0 } }
102+
self.m_boss_types_avail = { { name = "PIM_MAGB" --[[SecuroServ VIP]], id = 0 } }
103103
self.m_cooldown_controller = IManagedValueController.new(RawData.Cooldowns)
104104

105-
-- this is stupid but works. we're just caching the label so that we can later use it anywhere with the _T macro
105+
-- this is stupid but works. we're just caching the labels so that we can later use them anywhere with the _T macro
106106
-- we should probably decouble game labels from our own, something like a global table where we can do `label = GLabels.GB_BOSS`
107107
-- while still keeping Translator compatibility.
108-
Translator:TranslateGXT("GB_BOSS")
108+
for _, v in ipairs({ "PIM_MAGB", "PIM_MAGBC", "PI_BIK_MCP", "PIM_REGBOSS", "PIM_MAGM0B" }) do
109+
Translator:TranslateGXT(v)
110+
end
109111

110112
self.m_thread = ThreadManager:RegisterLooped("SS_YRV3", function()
111113
self:OnTick()
@@ -130,7 +132,7 @@ function YRV3:Reset(disable, reason)
130132
self.m_last_autosell_check_time = 0
131133
self.m_last_income_check_time = 0
132134
self.m_last_business_update_time = 0
133-
self.m_boss_types_avail = { { name = "GB_BOSS" --[[VIP]], id = 0 } }
135+
self.m_boss_types_avail = { { name = "PIM_MAGB" --[[SecuroServ VIP]], id = 0 } }
134136
self.m_sell_script_running = false
135137
self.m_initial_data_done = false
136138
self.m_data_initialized = false
@@ -356,7 +358,7 @@ function YRV3:PopulateOffice()
356358
name = Game.GetLabelText(ref.gxt),
357359
coords = ref.coords,
358360
}
359-
self.m_boss_types_avail[1].name = "GB_BOSSC"
361+
self.m_boss_types_avail[1].name = "PIM_MAGBC"
360362
end
361363

362364
function YRV3:PopulateClubhouse()
@@ -377,7 +379,7 @@ function YRV3:PopulateClubhouse()
377379
coords = club_ref.coords,
378380
safe_data = safe_data
379381
}
380-
table.insert(self.m_boss_types_avail, { name = "GB_REST_ACCM", id = 1 })
382+
self.m_boss_types_avail[2] = { name = "PI_BIK_MCP", id = 1 }
381383
end
382384

383385
function YRV3:PopulateBikerBusinesses()

SSV2/includes/frontend/helpers/TableRenderer.lua

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,22 @@ end
5959
---@param value anyval
6060
---@param isKey boolean
6161
function TableRenderer:DrawObject(value, isKey)
62-
local token = TableRendererToken.new(value)
63-
local color = token.m_color
64-
local v = type(value) == "string" and _F('"%s"', value) or tostring(value)
62+
local token = TableRendererToken.new(value)
63+
local color = token.m_color
64+
local r, g, b, a = color:AsFloat()
65+
local v = type(value) == "string" and _F('"%s"', value) or tostring(value)
6566
if (not isKey) then
66-
ImGui.TextColored(color.r, color.g, color.b, color.a, v)
67+
ImGui.TextColored(r, g, b, a, v)
6768
return
6869
end
6970

71+
local r2, g2, b2, a2 = PURPLE:AsFloat()
7072
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, 0, 0)
71-
ImGui.TextColored(PURPLE.r, PURPLE.g, PURPLE.b, PURPLE.a, "[")
73+
ImGui.TextColored(r2, g2, b2, a2, "[")
7274
ImGui.SameLine()
73-
ImGui.TextColored(color.r, color.g, color.b, color.a, v)
75+
ImGui.TextColored(r, g, b, a, v)
7476
ImGui.SameLine()
75-
ImGui.TextColored(PURPLE.r, PURPLE.g, PURPLE.b, PURPLE.a, "]")
77+
ImGui.TextColored(r2, g2, b2, a2, "]")
7678
ImGui.PopStyleVar()
7779
end
7880

@@ -89,7 +91,8 @@ function TableRenderer:DrawValue(value, depth, seen)
8991
end
9092

9193
if (seen[value]) then
92-
ImGui.TextColored(RED.r, RED.g, RED.b, RED.a, "<circular_reference>")
94+
local r, g, b, a = RED:AsFloat()
95+
ImGui.TextColored(r, g, b, a, "<circular_reference>")
9396
return
9497
end
9598

SSV2/includes/frontend/yim_resupplier/helpers/boss_register_combo.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local selectedBossType = -1
1313
return function()
1414
local currentBossType = LocalPlayer:GetBossType()
1515
if (currentBossType > -1) then
16-
if (GUI:Button(_T("YRV3_DASHBOARD_BOSS_RETIRE"))) then
16+
if (GUI:Button(_T("PIM_MAGM0B"))) then
1717
LocalPlayer:Retire()
1818
end
1919
return
@@ -24,7 +24,7 @@ return function()
2424
return
2525
end
2626

27-
if (GUI:Button(_T("YRV3_DASHBOARD_BOSS_REGISTER"))) then
27+
if (GUI:Button(_T("PIM_REGBOSS"))) then
2828
ImGui.OpenPopup("##bossRegister")
2929
end
3030

SSV2/includes/frontend/yim_resupplier/nameplate_ui.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ return function(business, args)
5252
local bg = args.bgColor
5353
ImGui.SetCursorPosX((ImGui.GetContentRegionAvail() - custom_name_width) * 0.5)
5454
if (bg) then
55-
ImGui.TextColored(bg.r, bg.g, bg.b, bg.a, custom_name)
55+
local r, g, b, a = bg:AsFloat()
56+
ImGui.TextColored(r, g, b, a, custom_name)
5657
else
5758
ImGui.Text(custom_name)
5859
end

SSV2/includes/lib/extensions/__init__.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
math.randomseed(os.time())
1111

1212
---@type table<table, table<integer, string>>
13-
local EnumNamesCache <const> = {}
13+
local EnumNamesCache <const> = setmetatable({}, { __mode = "v" })
1414
local Chrono <const> = require("includes.modules.Chrono")
1515
Bit = require("includes.modules.Bit") -- exposed globally sicne it's used all over the project.
1616

SSV2/includes/lib/extensions/api_imgui.lua

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -895,20 +895,22 @@ end
895895
---@param boxStyle? ImGuiDialogBoxStyle
896896
---@return boolean
897897
function ImGui.DialogBox(label, message, boxStyle)
898-
boxStyle = boxStyle or ImGuiDialogBoxStyle.INFO
899-
message = message or _T("GENERIC_CONFIRM_WARN")
900-
local col = DialogBoxColors[boxStyle] or ImGui.GetStyleColor(ImGuiCol.PopupBg)
901-
local textCol = ImGui.GetAutoTextColor(col)
902-
local v = false
898+
boxStyle = boxStyle or ImGuiDialogBoxStyle.INFO
899+
message = message or _T("GENERIC_CONFIRM_WARN")
900+
local col = DialogBoxColors[boxStyle] or ImGui.GetStyleColor(ImGuiCol.PopupBg)
901+
local r, g, b, a = col:AsFloat()
902+
local textCol = ImGui.GetAutoTextColor(col)
903+
local v = false
903904

904905
DialogBoxAnimation:OnFrame()
905906
if (not DialogBoxAnimation:IsActive()) then
906907
ImGui.SetNextWindowSizeConstraints(440, 200, 440, 600)
907908
end
908-
ImGui.PushStyleColor(ImGuiCol.TitleBg, col.r, col.g, col.b, col.a)
909-
ImGui.PushStyleColor(ImGuiCol.TitleBgActive, col.r, col.g, col.b, col.a)
910-
ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, col.r, col.g, col.b, col.a) -- is this even necessary?
911-
ImGui.PushStyleColor(ImGuiCol.Text, textCol.r, textCol.g, textCol.b, textCol.a)
909+
910+
ImGui.PushStyleColor(ImGuiCol.TitleBg, r, g, b, a)
911+
ImGui.PushStyleColor(ImGuiCol.TitleBgActive, r, g, b, a)
912+
ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, r, g, b, a) -- is this even necessary?
913+
ImGui.PushStyleColor(ImGuiCol.Text, textCol:AsFloat())
912914
local open = ImGui.BeginPopupModal(
913915
label,
914916
true,
@@ -933,10 +935,10 @@ function ImGui.DialogBox(label, message, boxStyle)
933935

934936
ImGui.Dummy(0, 40)
935937
if (boxStyle > ImGuiDialogBoxStyle.INFO) then
936-
ImGui.PushStyleColor(ImGuiCol.Button, col.r, col.g, col.b, math.max(col.a * 0.8, 0.8))
937-
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, col.r, col.g, col.b, col.a)
938-
ImGui.PushStyleColor(ImGuiCol.ButtonActive, col.r, col.g, col.b, math.max(col.a * 0.7, 0.7))
939-
ImGui.PushStyleColor(ImGuiCol.Text, textCol.r, textCol.g, textCol.b, textCol.a)
938+
ImGui.PushStyleColor(ImGuiCol.Button, r, g, b, math.max(a * 0.8, 0.8))
939+
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, r, g, b, a)
940+
ImGui.PushStyleColor(ImGuiCol.ButtonActive, r, g, b, math.max(a * 0.7, 0.7))
941+
ImGui.PushStyleColor(ImGuiCol.Text, textCol:AsFloat())
940942
end
941943

942944
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + firstCursorPos)

SSV2/includes/lib/translations/__hashmap.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,6 @@
961961
"YRV3_DASHBOARD_BOSS_RETIRED": 3795613883,
962962
"YRV3_DASHBOARD_BOSS_CEO_FMT": 2595999048,
963963
"YRV3_DASHBOARD_BOSS_PRES_FMT": 3301945000,
964-
"YRV3_DASHBOARD_BOSS_RETIRE": 1508124669,
965-
"YRV3_DASHBOARD_BOSS_REGISTER": 248929079,
966964
"MPSTAT_CONTROLLDER_DESC": 1596639631,
967965
"MPSTAT_LOCK_VAL_TT": 48368387,
968966
"YRV3_DASHBOARD_MANAGE_FUNDS": 926196671,

SSV2/includes/lib/translations/de-DE.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,6 @@ return {
961961
["YRV3_DASHBOARD_BOSS_RETIRED"] = "Im Ruhestand",
962962
["YRV3_DASHBOARD_BOSS_TYPE"] = "Boss-Typ",
963963
["YRV3_DASHBOARD_BOSS_PRES_FMT"] = "Präsident von %s",
964-
["YRV3_DASHBOARD_BOSS_REGISTER"] = "Registrieren Sie sich als Chef",
965964
["YRV3_DASHBOARD_BOSS_CEO_FMT"] = "CEO von %s",
966965
["MPSTAT_CONTROLLDER_DESC"] = "Verwalten, bearbeiten und sperren Sie Multiplayer-Statistiken dauerhaft.",
967966
["MPSTAT_LOCK_VAL_TT"] = "Sperrt die Statistik auf den aktuellen Wert.\n\nHinweis: Sie müssen Ihren gewünschten Wert festlegen, bevor Sie diese Option aktivieren, da durch die Aktivierung des Schalters der aktuelle Statistikwert erfasst und gespeichert wird, damit er im Hintergrund geschrieben wird.",

SSV2/includes/lib/translations/en-US.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,6 @@ return {
460460
["YRV3_DASHBOARD_BOSS_RETIRED"] = "Retired",
461461
["YRV3_DASHBOARD_BOSS_CEO_FMT"] = "CEO of %s",
462462
["YRV3_DASHBOARD_BOSS_PRES_FMT"] = "President of %s",
463-
["YRV3_DASHBOARD_BOSS_RETIRE"] = "Retire",
464-
["YRV3_DASHBOARD_BOSS_REGISTER"] = "Register As a Boss",
465463
["YRV3_DASHBOARD_MANAGE_FUNDS"] = "Manage Funds",
466464
["YRV3_CASH_SAFES_LABEL"] = "Cash Safes",
467465
["YRV3_CASH_LOOP"] = "[ ! ] Cash Loop",

SSV2/includes/lib/translations/es-ES.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,6 @@ return {
962962
["MPSTAT_CONTROLLDER_DESC"] = "Administre, edite y bloquee estadísticas multijugador con persistencia.",
963963
["YRV3_DASHBOARD_BOSS_CEO_FMT"] = "CEO de %s",
964964
["YRV3_DASHBOARD_BOSS_TYPE"] = "Tipo de jefe",
965-
["YRV3_DASHBOARD_BOSS_RETIRE"] = "Retirarse",
966-
["YRV3_DASHBOARD_BOSS_REGISTER"] = "Regístrate como jefe",
967965
["MPSTAT_LOCK_VAL_TT"] = "Bloquea la estadística al valor actual.\n\nNota: Debe establecer el valor deseado antes de activar esta opción, ya que al activar la opción se captura y guarda el valor de la estadística actual para escribirlo en segundo plano.",
968966
["YRV3_DASHBOARD_MANAGE_FUNDS"] = "Administrar fondos",
969967
["VEH_STANCE_LOCKED_FMT"] = "'Stancer' actualmente es propiedad de '%s'. Deshabilite la función de propietario para desbloquear la interfaz de usuario.",

0 commit comments

Comments
 (0)