Class: FFXI::TimeManager

Inherits:
Object
  • Object
show all
Defined in:
lib/Vana/time_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TimeManager

Returns a new instance of TimeManager.



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
# File 'lib/Vana/time_manager.rb', line 5

def initialize(opts={})
 @callbacks = {}
 @cascading_updates = false

 @vana_time = opts[:vana_time] || VanaTime.new
 @vana_day = opts[:vana_day] || VanaDay.new
 @vana_moon = opts[:vana_moon] || VanaMoon.new

 @vana_moon_countdown = opts[:vana_moon_countdown] || VanaMoonCountdown.new
 @skillup_calculator = opts[:skillup_calculator] || SkillupCalculator.new

 [@vana_time, @vana_day, @vana_moon, @vana_moon_countdown,
  @skillup_calculator].each do |obj|
  obj.add_listener(self)
 end

 if opts[:logger]
  level = opts[:log_level] || Logger::INFO
  @log_listener = Util::LogListener.new(:logger => opts[:logger],
   :log_level => level)

  [@vana_time, @vana_day, @vana_moon, @vana_moon_countdown,
   @skillup_calculator].each do |obj|
   obj.add_listener(@log_listener)
  end
 end

 if opts[:cascading_updates]
  enable_cascading_updates(opts[:earth_time] || Time.now)
 end
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



37
38
39
# File 'lib/Vana/time_manager.rb', line 37

def callbacks
  @callbacks
end

#cascading_updatesObject (readonly)

Returns the value of attribute cascading_updates.



37
38
39
# File 'lib/Vana/time_manager.rb', line 37

def cascading_updates
  @cascading_updates
end

#log_listenerObject (readonly)

Returns the value of attribute log_listener.



37
38
39
# File 'lib/Vana/time_manager.rb', line 37

def log_listener
  @log_listener
end

#skillup_calculatorObject (readonly)

Returns the value of attribute skillup_calculator.



40
41
42
# File 'lib/Vana/time_manager.rb', line 40

def skillup_calculator
  @skillup_calculator
end

#vana_dayObject (readonly) Also known as: day

Returns the value of attribute vana_day.



38
39
40
# File 'lib/Vana/time_manager.rb', line 38

def vana_day
  @vana_day
end

#vana_moonObject (readonly) Also known as: moon

Returns the value of attribute vana_moon.



38
39
40
# File 'lib/Vana/time_manager.rb', line 38

def vana_moon
  @vana_moon
end

#vana_moon_countdownObject (readonly) Also known as: moon_countdown

Returns the value of attribute vana_moon_countdown.



39
40
41
# File 'lib/Vana/time_manager.rb', line 39

def vana_moon_countdown
  @vana_moon_countdown
end

#vana_timeObject (readonly) Also known as: time

Returns the value of attribute vana_time.



38
39
40
# File 'lib/Vana/time_manager.rb', line 38

def vana_time
  @vana_time
end

Instance Method Details

#callback(property, proc = nil, &block) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/Vana/time_manager.rb', line 95

def callback(property, proc=nil, &block)
 if block_given?
  cb = block
 elsif ! proc.nil?
  cb = proc
 end

 raise "callback needs to be a Proc/lambda" if ! cb.is_a? Proc

 @callbacks[property] = [] if @callbacks[property].nil?
 @callbacks[property] << cb
end

#disable_cascading_updatesObject



57
58
59
# File 'lib/Vana/time_manager.rb', line 57

def disable_cascading_updates
 @cascading_updates = false
end

#enable_cascading_updates(earth_time = Time.now) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/Vana/time_manager.rb', line 47

def enable_cascading_updates(earth_time = Time.now)
 @vana_time.update_earth_time(earth_time)
 @vana_day.update_vana_time(@vana_time)
 @vana_moon.update_earth_time(@vana_time.earth_time)
 @vana_moon_countdown.update_moon(@vana_moon)
 @skillup_calculator.update_day_and_moon(@vana_day, @vana_moon)

 @cascading_updates = true
end

#property_changed(property, old_value, new_value) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/Vana/time_manager.rb', line 74

def property_changed(property, old_value, new_value)
 if @cascading_updates
  case property
  when :second
   @vana_moon_countdown.update_earth_time(@vana_time.earth_time)
  when :date
   @vana_day.update_vana_time(@vana_time.to_f)
   @vana_moon.update_earth_time(@vana_time.earth_time)
  when :moon_days
   @vana_moon_countdown.update_moon(@vana_moon)
   @skillup_calculator.update_day_and_moon(@vana_day, @vana_moon)
  when :day
   @skillup_calculator.update_day_and_moon(@vana_day, @vana_moon)
  end
 end

 @callbacks[property].each do |c|
  c.call(self, old_value, new_value)
 end if ! @callbacks[property].nil?
end

#update_earth_time(earth_time) ⇒ Object



61
62
63
64
# File 'lib/Vana/time_manager.rb', line 61

def update_earth_time(earth_time)
 raise "Input needs to be a Time object" if ! earth_time.is_a? Time
 @vana_time.update_earth_time(earth_time)
end

#update_vana_time(vt) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/Vana/time_manager.rb', line 66

def update_vana_time(vt)
 if vt.is_a? VanaTime
  update_earth_time(vt.earth_time)
 else
  update_earth_time(FFXI::Common.vana_to_earth(vt))
 end
end