vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --<< ================================================= >>-- |
2 | -- Section I: Chronos Support. -- |
||
3 | --<< ================================================= >>-- |
||
4 | |||
5 | local EMPTY_TABLE = {}; |
||
6 | local DEFAULT_TASK_LIMIT = 100; |
||
7 | local RUN_COUNT = 1; |
||
8 | local TIMER_PREFIX = "ChronosTimer_"; |
||
9 | |||
10 | local getTime = GetTime; |
||
11 | |||
12 | local function doTask(task, name) |
||
13 | if (not task[RUN_COUNT]) then |
||
14 | if (task.before) then |
||
15 | task.before(unpack(task.beforeArgs)); |
||
16 | end |
||
17 | task[RUN_COUNT] = 0; |
||
18 | end |
||
19 | task.step(unpack(task.stepArgs)); |
||
20 | task[RUN_COUNT] = task[RUN_COUNT] + 1; |
||
21 | if (task.isDone(unpack(task.doneArgs))) then |
||
22 | Timex:DeleteSchedule(name); |
||
23 | task[RUN_COUNT] = nil; |
||
24 | if task.after then |
||
25 | task.after(unpack(task.afterArgs)); |
||
26 | end |
||
27 | elseif (task[RUN_COUNT] > task.limit) then |
||
28 | Timex:DeleteSchedule(name); |
||
29 | task[RUN_COUNT] = nil; |
||
30 | end |
||
31 | end |
||
32 | |||
33 | if not Chronos then |
||
34 | Chronos = AceAddon:new({ |
||
35 | initTime = getTime(), |
||
36 | isScheduledByName = function(n) |
||
37 | local e = Timex:RemainingScheduleTime(n); |
||
38 | return e; |
||
39 | end, |
||
40 | scheduleByName = function(n, t, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
41 | Timex:AddSchedule(n, t, nil, nil, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||
42 | end, |
||
43 | schedule = function(t, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
44 | Chronos.scheduleByName(nil, t, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||
45 | end, |
||
46 | unscheduleByName = function(n) |
||
47 | Timex:DeleteSchedule(n); |
||
48 | end, |
||
49 | flushByName = function(n, w) |
||
50 | Timex:ChangeScheduleDue(n, w); |
||
51 | end, |
||
52 | |||
53 | scheduleRepeating = function(n, t, f) |
||
54 | Timex:AddSchedule(n, t, true, nil, f); |
||
55 | end, |
||
56 | |||
57 | getTimer = function(id) |
||
58 | return Timex:GetTimer(id); |
||
59 | end, |
||
60 | startTimer = function(id) |
||
61 | Timex:AddTimer(id); |
||
62 | end, |
||
63 | endTimer = function(id) |
||
64 | return Timex:DeleteTimer(id); |
||
65 | end, |
||
66 | isTimerActive = function(id) |
||
67 | return Timex:TimerCheck(id); |
||
68 | end, |
||
69 | |||
70 | getTime = function() |
||
71 | return getTime() - Chronos.initTime; |
||
72 | end, |
||
73 | |||
74 | everyFrame = function(f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
75 | Timex:AddOnUpdate(nil, nil, true, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||
76 | end, |
||
77 | |||
78 | afterInit = function(f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
79 | Timex:AddStartupFunc(f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||
80 | end, |
||
81 | |||
82 | performTask = function(t, n) |
||
83 | if not n then |
||
84 | n = t; |
||
85 | end |
||
86 | if not t.step then |
||
87 | error("step function is required for Chronos.performTask"); |
||
88 | elseif not t.isDone then |
||
89 | error("isDone function is required for Chronos.performTask"); |
||
90 | end |
||
91 | t.stepArgs = t.stepArgs or EMPTY_TABLE; |
||
92 | t.doneArgs = t.doneArgs or EMPTY_TABLE; |
||
93 | t.beforeArgs = t.beforeArgs or EMPTY_TABLE; |
||
94 | t.afterArgs = t.afterArgs or EMPTY_TABLE; |
||
95 | t.limit = t.limit or DEFAULT_TASK_LIMIT; |
||
96 | Timex:AddSchedule(n, 0, TRUE, nil, doTask, t, n); |
||
97 | end |
||
98 | }); |
||
99 | Chronos.unscheduleRepeating = Chronos.unscheduleByName; |
||
100 | Chronos.isScheduledRepeating = Chronos.isScheduledByName; |
||
101 | |||
102 | |||
103 | ChronosData = { |
||
104 | -- Initialize the VariablesLoaded flag |
||
105 | variablesLoaded = false; |
||
106 | |||
107 | -- Initialize the EnteredWorld flag |
||
108 | enteredWorld = false; |
||
109 | } |
||
110 | |||
111 | function Chronos:Initialize() |
||
112 | Timex:AddStartupFunc(function() |
||
113 | ChronosData.variablesLoaded = true; |
||
114 | end); |
||
115 | end |
||
116 | |||
117 | function Chronos:Enable() |
||
118 | Chronos:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
119 | Chronos:RegisterEvent("PLAYER_LEAVING_WORLD"); |
||
120 | end |
||
121 | |||
122 | function Chronos:PLAYER_ENTERING_WORLD() |
||
123 | ChronosData.enteredWorld = true; |
||
124 | ChronosData.online = true; |
||
125 | end |
||
126 | |||
127 | function Chronos:PLAYER_LEAVING_WORLD() |
||
128 | ChronosData.online = false; |
||
129 | end |
||
130 | end; |
||
131 | |||
132 | --<< ================================================= >>-- |
||
133 | -- Section Omega: Closure. -- |
||
134 | --<< ================================================= >>-- |