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:
@@ -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
|
||||
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`.
|
||||
7. **Slash command:** `/gt` toggle, `/gt reset` wired to the same reset logic.
|
||||
8. **Lifetime total:** Add `sessionEarned` to `lifetimeTotal` on `PLAYER_LOGOUT`.
|
||||
7. **Slash command:** `/gt` toggle, `/gt reset` wired to the same reset logic. ✅ DONE
|
||||
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.
|
||||
|
||||
|
||||
@@ -7,15 +7,14 @@
|
||||
- [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
|
||||
- [x] 8. Lifetime total
|
||||
## In Progress
|
||||
|
||||
- [ ] 5. Drag and save position
|
||||
|
||||
## Pending
|
||||
|
||||
- [ ] 6. Reset button
|
||||
- [ ] 7. Slash command
|
||||
- [ ] 8. Lifetime total
|
||||
- [ ] 9. Polish
|
||||
|
||||
@@ -25,9 +24,8 @@
|
||||
|---|---|---|
|
||||
| `GetMoney()` | PlayerScriptDocumentation.lua | ✅ VERIFIED |
|
||||
| `GetTime()` | SystemTimeDocumentation.lua | ✅ VERIFIED |
|
||||
| `MONEY_DISPLAY_UPDATING` | — | ❌ NOT FOUND (unverified) |
|
||||
| `PLAYER_LOGIN` | SystemDocumentation.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 |
|
||||
@@ -38,9 +36,13 @@
|
||||
| `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
|
||||
|
||||
@@ -52,3 +54,63 @@
|
||||
## Known Issues
|
||||
|
||||
(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
@@ -100,14 +100,19 @@ local timeLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
||||
timeLabel:SetPoint("TOPLEFT", gphLabel, "BOTTOMLEFT", 0, -4)
|
||||
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
|
||||
local function UpdateDisplay()
|
||||
local elapsed = GetTime() - sessionStart
|
||||
local hours = elapsed / 3600
|
||||
|
||||
|
||||
-- Earned (gross)
|
||||
earnedLabel:SetText("Earned: " .. FormatCopper(sessionGross))
|
||||
|
||||
|
||||
-- Gold per hour (show "---" until threshold)
|
||||
if elapsed >= GOLD_PER_HOUR_SHOW_AFTER and hours > 0 then
|
||||
local gph = sessionGross / hours
|
||||
@@ -115,10 +120,13 @@ local function UpdateDisplay()
|
||||
else
|
||||
gphLabel:SetText("Rate: ---")
|
||||
end
|
||||
|
||||
|
||||
-- Time elapsed
|
||||
local timeStr = SecondsToTime(elapsed, false, false, 1)
|
||||
timeLabel:SetText("Time: " .. timeStr)
|
||||
|
||||
-- Lifetime total
|
||||
lifetimeLabel:SetText("Lifetime: " .. FormatCopper(lifetimeTotal))
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -171,6 +179,12 @@ loginFrame:SetScript("OnEvent", function(self, event)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Lifetime total (Step 8)
|
||||
-- ---------------------------------------------------------------------------
|
||||
local lifetimeTotal = SessionGoldTrackerDB.lifetimeTotal or 0
|
||||
SessionGoldTrackerDB.lifetimeTotal = lifetimeTotal
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Money tracking (PLAYER_MONEY event)
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -183,6 +197,8 @@ moneyFrame:SetScript("OnEvent", function(self, event)
|
||||
|
||||
if delta > 0 then
|
||||
sessionGross = sessionGross + delta
|
||||
lifetimeTotal = lifetimeTotal + delta
|
||||
SessionGoldTrackerDB.lifetimeTotal = lifetimeTotal
|
||||
end
|
||||
sessionNet = sessionNet + delta
|
||||
|
||||
@@ -195,3 +211,41 @@ moneyFrame:SetScript("OnEvent", function(self, event)
|
||||
))
|
||||
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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user