-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMoneyMoneyMoney.moon
96 lines (77 loc) · 2.73 KB
/
MoneyMoneyMoney.moon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import GetAddOnMetadata, CreateFrame, GetMoney,
RepairAllItems, InRepairMode,
MoneyMoneyMoneyDB, LibStub from _G
LibDataBroker = LibStub\GetLibrary "LibDataBroker-1.1"
export MoneyMoneyMoney
MoneyMoneyMoneyDB or= {}
class HierarchicalDB
new: (@levels, @queriable) =>
MoneyMoneyMoney =
Name: "MoneyMoneyMoney"
Version: GetAddOnMetadata("MoneyMoneyMoney", "Version")
Frame: CreateFrame "Frame"
Broker: nil
DB: nil
Events:
PLAYER_ENTERING_WORLD: () =>
@CurrentGold = GetMoney()
PLAYER_MONEY: () =>
delta = GetMoney() - @CurrentGold
@CurrentGold = GetMoney()
@UpdateMoney(delta)
OnEvent: (_, evt, ...) =>
if @Events[evt]
@Events[evt](@, ...)
else
print "Unhandled event #{evt}!"
UpdateMoney: (delta) =>
if @Expected[1] and delta == @Expected[1].Amount
print "MMM: Expected: #{delta} from #{@Expected[1].Category}"
table.remove(@Expected, 1)
else
for category, opts in pairs(@Categories)
if flag = opts.HasFlag
if @Flags[flag]
print "MMM: Flag: #{delta} from #{source}"
return
print "MMM: Got #{delta} from unknown source."
Expect: (category, amount) =>
@Expected[#@Expected + 1] = Category: category, Amount: amount
print "MMM: Expecting #{amount} from #{source}"
CurrentGold: 0
Categories: {}
Flags: {}
Expected: {}
Timers: {}
RegisterCategory: (name, opts={}) =>
@Categories[name] = opts
RegisterEvent: (name, actions) =>
@Events[name] = (...) =>
if flag = actions.SetFlag
@Flags[flag] = true
if flag = actions.ClearFlag
@Flags[flag] = nil
if timer = actions.SetTimer
@Timers[timer] = GetTime()
RegisterHook: (name, fun) =>
hooksecurefunc(name, (...) -> fun(@, ...))
MMM = MoneyMoneyMoney
MMM.Broker = with LibDataBroker\NewDataObject("MoneyMoneyMoney_Broker", type: "data source", label: "MoneyMoneyMoney", tocname: "MoneyMoneyMoney")
.OnTooltipShow = () =>
@AddLine("This is a test.")
.text = "MMM: 10|TInterface\\MONEYFRAME\\UI-GoldIcon:0|t"
MMM\RegisterCategory 'Vendor', HasFlag: 'UsingVendor'
MMM\RegisterEvent 'MERCHANT_SHOW', SetFlag: 'UsingVendor'
MMM\RegisterEvent 'MERCHANT_CLOSED', ClearFlag: 'UsingVendor'
MMM\RegisterHook 'BuyMerchantItem', (idx, qty) =>
_, _, price, defaultQty = GetMerchantItemInfo(idx)
@Expect 'Vendor', -price * (qty or defaultQty)
MMM\RegisterCategory 'Flights', :EXPENSES
MMM\RegisterHook 'TakeTaxiNode', (id) =>
@Expect 'Flights', -TaxiNodeCost(id)
MMM\RegisterCategory 'Repair'
MMM\RegisterHook 'RepairAllItems', (guildBankRepair) =>
@Expect 'Repair', -GetRepairAllCost() unless guildBankRepair
for k, _ in pairs(MMM.Events)
MMM.Frame\RegisterEvent(k)
MMM.Frame\SetScript "OnEvent", MMM\OnEvent