feat: add lifetime total tracking (step 8)

Accumulate lifetimeTotal on every positive PLAYER_MONEY delta and
persist to SavedVariables so it survives /reload and Reset. Display
a 'Lifetime: Xg Ys Zc' label on the HUD frame. Also fix missing
closing 'end' in SlashCmdList closure.
This commit is contained in:
bepis
2026-10-19 21:28:51 +11:00
parent 9a30efa170
commit f7e32111f1
3 changed files with 128 additions and 12 deletions
Regular → Executable
+2 -2
View File
@@ -42,7 +42,7 @@ Each step should be independently testable in game before moving on.
4. **Frame:** Movable frame with labels for earned gold and per-hour rate. No drag yet. ✅ DONE 4. **Frame:** Movable frame with labels for earned gold and per-hour rate. No drag yet. ✅ DONE
5. **Drag and save position:** Drag support + save point on `OnDragStop` + restore on login. 5. **Drag and save position:** Drag support + save point on `OnDragStop` + restore on login.
6. **Reset button:** On-frame button that zeroes session counters and resets `sessionStart`. 6. **Reset button:** On-frame button that zeroes session counters and resets `sessionStart`.
7. **Slash command:** `/gt` toggle, `/gt reset` wired to the same reset logic. 7. **Slash command:** `/gt` toggle, `/gt reset` wired to the same reset logic. ✅ DONE
8. **Lifetime total:** Add `sessionEarned` to `lifetimeTotal` on `PLAYER_LOGOUT`. 8. **Lifetime total:** Accumulate `lifetimeTotal` on every positive `PLAYER_MONEY` delta (robust against Reset), persist to SavedVariables. ✅ DONE
9. **Polish:** Format display cleanly, add a tooltip, test across a /reload. 9. **Polish:** Format display cleanly, add a tooltip, test across a /reload.
Regular → Executable
+69 -7
View File
@@ -7,15 +7,14 @@
- [x] 2. DB init - [x] 2. DB init
- [x] 3. Money tracking - [x] 3. Money tracking
- [x] 4. Frame - [x] 4. Frame
- [x] 5. Drag and save position
- [x] 6. Reset button
- [x] 7. Slash command
- [x] 8. Lifetime total
## In Progress ## In Progress
- [ ] 5. Drag and save position
## Pending ## Pending
- [ ] 6. Reset button
- [ ] 7. Slash command
- [ ] 8. Lifetime total - [ ] 8. Lifetime total
- [ ] 9. Polish - [ ] 9. Polish
@@ -25,9 +24,8 @@
|---|---|---| |---|---|---|
| `GetMoney()` | PlayerScriptDocumentation.lua | ✅ VERIFIED | | `GetMoney()` | PlayerScriptDocumentation.lua | ✅ VERIFIED |
| `GetTime()` | SystemTimeDocumentation.lua | ✅ VERIFIED | | `GetTime()` | SystemTimeDocumentation.lua | ✅ VERIFIED |
| `MONEY_DISPLAY_UPDATING` | — | ❌ NOT FOUND (unverified) |
| `PLAYER_LOGIN` | SystemDocumentation.lua | ✅ VERIFIED |
| `PLAYER_MONEY` | CurrencyInfoDocumentation.lua | ✅ VERIFIED | | `PLAYER_MONEY` | CurrencyInfoDocumentation.lua | ✅ VERIFIED |
| `PLAYER_LOGIN` | SystemDocumentation.lua | ✅ VERIFIED |
| `PLAYER_LOGOUT` | SystemDocumentation.lua | ✅ VERIFIED | | `PLAYER_LOGOUT` | SystemDocumentation.lua | ✅ VERIFIED |
| `CreateFrame` | FrameAPI docs | ✅ VERIFIED | | `CreateFrame` | FrameAPI docs | ✅ VERIFIED |
| `frame:SetMovable(true)` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED | | `frame:SetMovable(true)` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
@@ -38,9 +36,13 @@
| `frame:GetPoint()` | SimpleScriptRegionResizingAPIDocumentation.lua | ✅ VERIFIED | | `frame:GetPoint()` | SimpleScriptRegionResizingAPIDocumentation.lua | ✅ VERIFIED |
| `frame:SetPoint()` | SimpleScriptRegionResizingAPIDocumentation.lua | ✅ VERIFIED | | `frame:SetPoint()` | SimpleScriptRegionResizingAPIDocumentation.lua | ✅ VERIFIED |
| `frame:SetClampedToScreen(true)` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED | | `frame:SetClampedToScreen(true)` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `frame:IsShown()` | SimpleScriptRegionAPIDocumentation.lua | ✅ VERIFIED |
| `frame:Show()` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `frame:Hide()` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `SlashCmdList` / `SLASH_GT1` | SlashCommandsRegistry.lua.annotated.lua | ✅ VERIFIED | | `SlashCmdList` / `SLASH_GT1` | SlashCommandsRegistry.lua.annotated.lua | ✅ VERIFIED |
| `GetMoneyString()` | QuestInfo.lua, MerchantFrame.lua, etc. | ✅ VERIFIED | | `GetMoneyString()` | QuestInfo.lua, MerchantFrame.lua, etc. | ✅ VERIFIED |
| `SecondsToTime()` | SharedBasicControls.lua, Blizzard_TimeManager.lua | ✅ VERIFIED | | `SecondsToTime()` | SharedBasicControls.lua, Blizzard_TimeManager.lua | ✅ VERIFIED |
| `UIPanelButtonTemplate` | Blizzard_UIPanelTemplates.lua | ✅ VERIFIED (standard template) |
## Design Decisions ## Design Decisions
@@ -52,3 +54,63 @@
## Known Issues ## Known Issues
(None yet) (None yet)
# SessionGoldTracker — STATUS.md
## Completed Steps
- [x] 1. Skeleton
- [x] 2. DB init
- [x] 3. Money tracking
- [x] 4. Frame
- [x] 5. Drag and save position
- [x] 6. Reset button
- [x] 7. Slash command
## In Progress
## Pending
- [ ] 8. Lifetime total
- [ ] 9. Polish
## API Verification Status
| API | Source | Verified? |
|---|---|---|
| `GetMoney()` | PlayerScriptDocumentation.lua | ✅ VERIFIED |
| `GetTime()` | SystemTimeDocumentation.lua | ✅ VERIFIED |
| `PLAYER_MONEY` | CurrencyInfoDocumentation.lua | ✅ VERIFIED |
| `PLAYER_LOGIN` | SystemDocumentation.lua | ✅ VERIFIED |
| `PLAYER_LOGOUT` | SystemDocumentation.lua | ✅ VERIFIED |
| `CreateFrame` | FrameAPI docs | ✅ VERIFIED |
| `frame:SetMovable(true)` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `frame:EnableMouse(true)` | SimpleScriptRegionAPIDocumentation.lua | ✅ VERIFIED |
| `frame:RegisterForDrag("LeftButton")` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `frame:SetScript("OnDragStart", ...)` | Frame scripts | ✅ VERIFIED |
| `frame:SetScript("OnDragStop", ...)` | Frame scripts | ✅ VERIFIED |
| `frame:GetPoint()` | SimpleScriptRegionResizingAPIDocumentation.lua | ✅ VERIFIED |
| `frame:SetPoint()` | SimpleScriptRegionResizingAPIDocumentation.lua | ✅ VERIFIED |
| `frame:SetClampedToScreen(true)` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `frame:IsShown()` | SimpleScriptRegionAPIDocumentation.lua | ✅ VERIFIED |
| `frame:Show()` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `frame:Hide()` | SimpleFrameAPIDocumentation.lua | ✅ VERIFIED |
| `SlashCmdList` / `SLASH_GT1` | SlashCommandsRegistry.lua.annotated.lua | ✅ VERIFIED |
| `GetMoneyString()` | QuestInfo.lua, MerchantFrame.lua, etc. | ✅ VERIFIED |
| `SecondsToTime()` | SharedBasicControls.lua, Blizzard_TimeManager.lua | ✅ VERIFIED |
| `UIPanelButtonTemplate` | Blizzard_UIPanelTemplates.lua | ✅ VERIFIED (standard template) |
## Design Decisions
- **Gold per hour**: Shows "---" until 60 seconds have elapsed
- **Frame visible on login**: No — hidden by default, toggled with `/gt`
- **Session survives /reload**: Yes — restored from `lastSession` in SavedVariables
- **Lifetime total**: Accumulated on every positive money change (not only at logout), so Reset doesn't lose gold earned before reset
## Known Issues
(None yet)
Regular → Executable
+57 -3
View File
@@ -100,14 +100,19 @@ local timeLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
timeLabel:SetPoint("TOPLEFT", gphLabel, "BOTTOMLEFT", 0, -4) timeLabel:SetPoint("TOPLEFT", gphLabel, "BOTTOMLEFT", 0, -4)
timeLabel:SetText("Time: 0s") timeLabel:SetText("Time: 0s")
-- Lifetime total label
local lifetimeLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
lifetimeLabel:SetPoint("TOPLEFT", timeLabel, "BOTTOMLEFT", 0, -4)
lifetimeLabel:SetText("Lifetime: 0g 0s 0c")
-- Update display function -- Update display function
local function UpdateDisplay() local function UpdateDisplay()
local elapsed = GetTime() - sessionStart local elapsed = GetTime() - sessionStart
local hours = elapsed / 3600 local hours = elapsed / 3600
-- Earned (gross) -- Earned (gross)
earnedLabel:SetText("Earned: " .. FormatCopper(sessionGross)) earnedLabel:SetText("Earned: " .. FormatCopper(sessionGross))
-- Gold per hour (show "---" until threshold) -- Gold per hour (show "---" until threshold)
if elapsed >= GOLD_PER_HOUR_SHOW_AFTER and hours > 0 then if elapsed >= GOLD_PER_HOUR_SHOW_AFTER and hours > 0 then
local gph = sessionGross / hours local gph = sessionGross / hours
@@ -115,10 +120,13 @@ local function UpdateDisplay()
else else
gphLabel:SetText("Rate: ---") gphLabel:SetText("Rate: ---")
end end
-- Time elapsed -- Time elapsed
local timeStr = SecondsToTime(elapsed, false, false, 1) local timeStr = SecondsToTime(elapsed, false, false, 1)
timeLabel:SetText("Time: " .. timeStr) timeLabel:SetText("Time: " .. timeStr)
-- Lifetime total
lifetimeLabel:SetText("Lifetime: " .. FormatCopper(lifetimeTotal))
end end
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
@@ -171,6 +179,12 @@ loginFrame:SetScript("OnEvent", function(self, event)
end) end)
end) end)
-- ---------------------------------------------------------------------------
-- Lifetime total (Step 8)
-- ---------------------------------------------------------------------------
local lifetimeTotal = SessionGoldTrackerDB.lifetimeTotal or 0
SessionGoldTrackerDB.lifetimeTotal = lifetimeTotal
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- Money tracking (PLAYER_MONEY event) -- Money tracking (PLAYER_MONEY event)
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
@@ -183,6 +197,8 @@ moneyFrame:SetScript("OnEvent", function(self, event)
if delta > 0 then if delta > 0 then
sessionGross = sessionGross + delta sessionGross = sessionGross + delta
lifetimeTotal = lifetimeTotal + delta
SessionGoldTrackerDB.lifetimeTotal = lifetimeTotal
end end
sessionNet = sessionNet + delta sessionNet = sessionNet + delta
@@ -195,3 +211,41 @@ moneyFrame:SetScript("OnEvent", function(self, event)
)) ))
end end
end) end)
-- ---------------------------------------------------------------------------
-- Reset Button (Step 6)
-- ---------------------------------------------------------------------------
local resetButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
resetButton:SetSize(60, 22)
resetButton:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -8, 8)
resetButton:SetText("Reset")
local function DoReset()
sessionGross = 0
sessionNet = 0
sessionStart = GetTime()
sessionGoldStart = GetMoney()
lastMoney = GetMoney()
UpdateDisplay()
print("[SessionGoldTracker] Session reset.")
end
resetButton:SetScript("OnClick", DoReset)
-- ---------------------------------------------------------------------------
-- Slash Command (Step 7)
-- ---------------------------------------------------------------------------
SlashCmdList["SESSIONGOLDTRACKER"] = function(msg)
msg = msg and msg:lower() or ""
if msg == "reset" then
DoReset()
else
if frame:IsShown() then
frame:Hide()
else
frame:Show()
end
end
end
SLASH_SESSIONGOLDTRACKER1 = "/gt"