VanaTime 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 2.1.0 / 2007-09-17
2
+
3
+ * ok, the previous callback system was retarded. rewritten again to not suck
4
+ moved from ruby observer to RubyBean
5
+ added skillup calculator support
6
+
1
7
  == 2.0.0 / 2007-09-08
2
8
 
3
9
  * rewritten to support a callback based arch, added element information,
data/Manifest CHANGED
@@ -4,10 +4,13 @@ LICENSE
4
4
  lib/vana_time.rb
5
5
  lib/Vana/time_manager.rb
6
6
  lib/Vana/time.rb
7
+ lib/Vana/skillup_calculator.rb
7
8
  lib/Vana/moon_countdown.rb
8
9
  lib/Vana/moon.rb
9
10
  lib/Vana/element.rb
10
11
  lib/Vana/day.rb
11
12
  lib/Vana/constants.rb
12
13
  lib/Vana/common.rb
14
+ lib/util/ruby_bean.rb
15
+ lib/util/log_listener.rb
13
16
  CHANGELOG
data/README CHANGED
@@ -1,7 +1,7 @@
1
- VanaTime 2.0.0 README
1
+ VanaTime 2.1.0 README
2
2
  =====================
3
3
 
4
- This document was last updated on Sat Sep 8 13:41:50 EDT 2007.
4
+ This document was last updated on Mon Sep 17 23:09:51 EDT 2007.
5
5
 
6
6
 
7
7
  Introduction to VanaTime
@@ -19,103 +19,98 @@ you may want to use explicit versioning in any code depending on it.
19
19
  FFXI::TimeManager
20
20
  =================
21
21
 
22
- This will probably be the only class you end up using. It wraps everything
23
- else up in a convenient callback system that keeps things in sync, only
24
- does updates when necessary, and fires off your code on events. Huzzah! Here's
25
- a quick example text clock:
26
-
27
- include FFXI::Constants
28
- tm = FFXI::TimeManager.now
29
- tm.callback(MS_SECOND) {|time| puts "Vana'diel Time: #{time}" }
30
- loop {tm.earth_time=(Time.now) ; sleep 0.04}
31
-
32
- If you want to manage existing VanaTime, VanaDay, and VanaMoon objects you
33
- can create a blank TimeManager and call manage on them:
34
-
35
- tm = FFXI::TimeManager.new
36
- tm.manage(time, day, moon)
37
-
38
- The following are the supported events for adding callbacks:
39
-
40
- MS_SECOND
41
- MS_MINUTE
42
- MS_HOUR
43
- MS_DAY
44
- MS_MONTH
45
- MS_YEAR
46
- day (of the week, fires off seperately from MS_DAY)
47
- moon_days
48
- moon_percent
49
- moon_phase
50
- next_optimal_phase
51
- next_phase_countdown
52
- optimal_phase_countdown
53
-
54
- FFXI::VanaTime API
55
- ==================
56
-
57
- * new(Time)
58
- accepts a Time object to initialize a new VanaTime
59
- * now
60
- calls new with Time.now
61
- * at(VanaTime)
62
- accepts a VanaTime object, int, or float representing vana time to
63
- initialize a new VanaTime object
64
- * earth_time=(Time)
65
- allows re-initializing a VanaTime object with a new earth time
66
- * vana_time=(VanaTime)
67
- allows re-initializing a VanaTime object with a new vana time, given
68
- as a VanaTime object (why not >_>), or (more useful) an int or float
69
- * to_i
70
- returns an integer with the internal representation of vana time
71
- * to_f
72
- returns a float with the internal representation of vana time without
73
- losing any accuracy
74
- * year
75
- * year_start
76
- * month
77
- * month_start
78
- * date
79
- * date_start
80
- * tomorrow
81
- * hour
82
- * hour_start
83
- * minute
84
- * minute_start
85
- * second
86
- * second_start
87
- these methods return various times, what we're interested in
88
- * to_s
89
- returns a string in the format:
90
- YYYY-MM-DD hh:mm:ss
91
- * time_string
92
- returns just the time portion of to_s
93
- * date_string
94
- returns just the date portion of to_s
95
-
96
- FFXI::VanaDay API
97
- =================
22
+ This will probably be the only class you end up using directly. It wraps
23
+ everything else up in a convenient cascading update system that keeps things
24
+ in sync, only does updates when necessary, and provides callbacks for firing
25
+ off your code on events. Huzzah! Callbacks have access to the instance of
26
+ TimeManager that fired the callback (in case you need access to values other
27
+ than the property you're installing the callback for), the old value for the
28
+ property, and the new value for the property. Cascading updates are enabled by
29
+ enable_cascading_updates and disabled by disable_cascading_updates.
30
+
31
+ Here's a quick example text clock:
32
+
33
+ tm = FFXI::TimeManager.new
34
+ tm.callback(:time_string) {|m,old,new| puts "Time: #{new}"}
35
+ tm.callback(:next_phase_countdown_string) do |manager, old, new|
36
+ puts "Countdown until #{manager.moon.next_phase}: #{new}"
37
+ end
38
+ tm.enable_cascading_updates
39
+ loop {tm.update_earth_time(Time.now) ; sleep 0.5}
40
+
41
+ If you want to manage existing VanaTime, VanaDay, and etc you can pass these as
42
+ options on init, and any objects not passed in will be created for you. The
43
+ name for the option will be similar to the class name:
44
+
45
+ tm = FFXI::TimeManager.new(:vana_time => FFXI::VanaTime.now)
46
+
47
+ Note that you can have as many TimeManager objects as you want or need for the
48
+ same set of vanatime objects, as long as only one of them has cascading
49
+ updates enabled.
50
+
51
+ The following are the supported properties for adding callbacks, along with the
52
+ classes that define them (with the more interesting properties first):
53
+
54
+ =====> VanaTime
55
+ :time_string
56
+ :date_string
57
+ :earth_time
58
+ :vana_time
59
+ :tomorrow
60
+ :year
61
+ :month
62
+ :date
63
+ :hour
64
+ :minute
65
+ :second
66
+ :year_start
67
+ :month_start
68
+ :date_start
69
+ :hour_start
70
+ :minute_start
71
+ :second_start
72
+
73
+ =====> VanaDay
74
+ :day_html
75
+ :day_string
76
+ :day
77
+ :day_element
78
+ :day_weakness
79
+ :day_strength
80
+
81
+ =====> VanaMoon
82
+ :moon_string
83
+ :moon_percent_string
84
+ :moon_phase_name
85
+ :moon_phase_short_name
86
+ :next_phase_name
87
+ :next_phase_short_name
88
+ :optimal_phase_name
89
+ :optimal_phase_short_name
90
+ :next_phase_target
91
+ :optimal_phase_target
92
+ :moon_phase
93
+ :moon_percent
94
+ :moon_days
95
+
96
+ =====> VanaMoonCountdown
97
+ :next_phase_countdown_string
98
+ :optimal_phase_countdown_string
99
+ :next_phase_countdown
100
+ :optimal_phase_countdown
101
+
102
+ =====> SkillupCalculator
103
+ :skillup_difficulty
104
+ :base_difficulty
105
+ :moon_phase_factor
106
+ :day_crystal_factor
98
107
 
99
- * new(VanaTime)
100
- accepts a VanaTime object used to initialize the vana day, using a new
101
- VanaTime initialized to the current time if one isn't passed
102
- * vana_time=(VanaTime)
103
- used to reinitialize the vana day object with a new time
104
- * to_i
105
- returns a base zero number representing the day of the week
106
- * to_s
107
- returns the name of the day of the week
108
- * to_html
109
- returns the day's name in a font tag with the day's color
110
- * element
111
- returns an Element object with the current day's element
112
- * weakness
113
- returns an Element object with the current day's elemental weakness
114
108
 
115
109
  FFXI::ElementFactory::Element
116
110
  =============================
117
111
 
118
112
  * name
113
+ * direction
119
114
  * strength
120
115
  * weakness
121
116
  * color
@@ -124,37 +119,12 @@ FFXI::ElementFactory::Element
124
119
  * ninjutsu
125
120
  * avatar
126
121
 
127
- FFXI::VanaMoon API
128
- ==================
129
-
130
- * new(Time)
131
- Unlike VanaDay, VanaMoon is initialized with earth time
132
- * now
133
- calls new with the current time
134
- * to_i
135
- returns a number representing the exact position along the progression
136
- of moon phases
137
- * percent
138
- returns the absolute value of the percentage formatted
139
- * phase
140
- returns the name of the current moon phase
141
- * to_s
142
- returns a string in the format: moon_percent.abs phase_name
143
- * next_phase
144
- returns the name of the next moon phase
145
- * optimal_phase
146
- returns the name of the next optimal moon phase
147
-
148
- FFXI::VanaMoonCountdown API
122
+
123
+ FFXI::SkillupCalculator API
149
124
  ===========================
150
125
 
151
- * to_next_array
152
- returns an array containing the days, hours, minutes, and seconds until
153
- the next moon phase
154
- * to_next
155
- returns a formatted countdown until the next moon phase
156
- * to_optimal_array
157
- returns an array containing the days, hours, minutes, and seconds until
158
- the next optimal moon phase
159
- * to_optimal
160
- returns a formatted countdown until the next optimal moon phase
126
+ * crystal_element=(element)
127
+ * recipe_cap=(cap)
128
+ * skill=(skill)
129
+
130
+ All other details are handled by cascading updates via TimeManager.
@@ -1,11 +1,11 @@
1
1
 
2
- # Gem::Specification for Vanatime-2.0.0
2
+ # Gem::Specification for Vanatime-2.1.0
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{VanaTime}
7
- s.version = "2.0.0"
8
- s.date = %q{2007-09-08}
7
+ s.version = "2.1.0"
8
+ s.date = %q{2007-09-18}
9
9
  s.summary = %q{A library for converting realtime to vanadiel time}
10
10
  s.email = %q{ttilley@gmail.com}
11
11
  s.homepage = %q{http://vanatime.rubyforge.org/}
@@ -13,30 +13,30 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{A library for converting realtime to vanadiel time}
14
14
  s.has_rdoc = true
15
15
  s.authors = ["Travis Tilley"]
16
- s.files = ["README", "Manifest", "LICENSE", "lib/vana_time.rb", "lib/Vana/time_manager.rb", "lib/Vana/time.rb", "lib/Vana/moon_countdown.rb", "lib/Vana/moon.rb", "lib/Vana/element.rb", "lib/Vana/day.rb", "lib/Vana/constants.rb", "lib/Vana/common.rb", "CHANGELOG", "VanaTime.gemspec"]
16
+ s.files = ["README", "Manifest", "LICENSE", "lib/vana_time.rb", "lib/Vana/time_manager.rb", "lib/Vana/time.rb", "lib/Vana/skillup_calculator.rb", "lib/Vana/moon_countdown.rb", "lib/Vana/moon.rb", "lib/Vana/element.rb", "lib/Vana/day.rb", "lib/Vana/constants.rb", "lib/Vana/common.rb", "lib/util/ruby_bean.rb", "lib/util/log_listener.rb", "CHANGELOG", "VanaTime.gemspec"]
17
17
  end
18
18
 
19
19
 
20
20
  # # Original Rakefile source (requires the Echoe gem):
21
21
  #
22
- # version = "2.0.0"
22
+ # version = "2.1.0"
23
23
  #
24
24
  # ENV['RUBY_FLAGS'] = ""
25
25
  #
26
26
  # begin
27
- # require 'rubygems'
28
- # gem 'echoe', '=2.3'
29
- # require 'echoe'
27
+ # require 'rubygems'
28
+ # gem 'echoe', '=2.4'
29
+ # require 'echoe'
30
30
  #
31
- # Echoe.new('VanaTime', version) do |p|
32
- # p.rubyforge_name = 'vanatime'
33
- # p.summary = "A library for converting realtime to vanadiel time"
34
- # p.url = "http://vanatime.rubyforge.org/"
35
- # p.author = 'Travis Tilley'
36
- # p.email = "ttilley@gmail.com"
37
- # end
31
+ # Echoe.new('VanaTime', version) do |p|
32
+ # p.rubyforge_name = 'vanatime'
33
+ # p.summary = "A library for converting realtime to vanadiel time"
34
+ # p.url = "http://vanatime.rubyforge.org/"
35
+ # p.author = 'Travis Tilley'
36
+ # p.email = "ttilley@gmail.com"
37
+ # end
38
38
  #
39
39
  # rescue LoadError => boom
40
- # puts "You are missing a dependency required for meta-operations on this gem."
41
- # puts "#{boom.to_s.capitalize}."
40
+ # puts "You are missing a dependency required for meta-operations on this gem."
41
+ # puts "#{boom.to_s.capitalize}."
42
42
  # end
@@ -1,86 +1,86 @@
1
1
  module FFXI
2
- module Common
3
- include FFXI::Constants
2
+ module Common
3
+ include FFXI::Constants
4
4
 
5
- def self.vana_to_earth(vana_time)
6
- (((vana_time.to_f - ((898 * 360 + 30) * MS_DAY.to_f)) / 25) +
7
- MS_BASIS_DATE.to_f) / MS_SECOND
8
- end
9
-
10
- def self.earth_to_vana(earth_time)
11
- ((898 * 360 + 30) * MS_DAY) + ((earth_time.to_f * MS_SECOND) -
12
- MS_BASIS_DATE) * 25
13
- end
5
+ def self.vana_to_earth(vana_time)
6
+ (((vana_time.to_f - ((898 * 360 + 30) * MS_DAY.to_f)) / 25) +
7
+ MS_BASIS_DATE.to_f) / MS_SECOND
8
+ end
14
9
 
15
- private
10
+ def self.earth_to_vana(earth_time)
11
+ ((898 * 360 + 30) * MS_DAY) + ((earth_time.to_f * MS_SECOND) -
12
+ MS_BASIS_DATE) * 25
13
+ end
16
14
 
17
- def start_of_period(vana_time, period)
18
- vana_time.to_f - (vana_time.to_f % period )
19
- end
15
+ private
20
16
 
21
- def end_of_period(vana_time, period)
22
- start_of_period(vana_time, period) + period
23
- end
17
+ def start_of_period(vana_time, period)
18
+ vana_time.to_f - (vana_time.to_f % period )
19
+ end
24
20
 
25
- def period_has_passed_since(period, since, vana_time)
26
- if since.nil?
27
- true
28
- else
29
- elapsed = vana_time.to_f - since.to_f
21
+ def end_of_period(vana_time, period)
22
+ start_of_period(vana_time, period) + period
23
+ end
30
24
 
31
- if elapsed < 0
32
- # if we're going -back- in time, we need to measure from the END of
33
- # the period instead of the start.
34
- elapsed = (since.to_f + period) - vana_time.to_f
35
- end
25
+ def period_has_passed_since(period, since, vana_time)
26
+ if since.nil?
27
+ true
28
+ else
29
+ elapsed = vana_time.to_f - since.to_f
36
30
 
37
- elapsed >= period
38
- end
31
+ if elapsed < 0
32
+ # if we're going -back- in time, we need to measure from the END of
33
+ # the period instead of the start.
34
+ elapsed = (since.to_f + period) - vana_time.to_f
39
35
  end
40
36
 
41
- def second_has_passed_since(since, vana_time)
42
- period_has_passed_since(MS_SECOND, since, vana_time)
43
- end
37
+ elapsed >= period
38
+ end
39
+ end
44
40
 
45
- def minute_has_passed_since(since, vana_time)
46
- period_has_passed_since(MS_MINUTE, since, vana_time)
47
- end
41
+ def second_has_passed_since(since, vana_time)
42
+ period_has_passed_since(MS_SECOND, since, vana_time)
43
+ end
48
44
 
49
- def hour_has_passed_since(since, vana_time)
50
- period_has_passed_since(MS_HOUR, since, vana_time)
51
- end
45
+ def minute_has_passed_since(since, vana_time)
46
+ period_has_passed_since(MS_MINUTE, since, vana_time)
47
+ end
52
48
 
53
- def day_has_passed_since(since, vana_time)
54
- period_has_passed_since(MS_DAY, since, vana_time)
55
- end
49
+ def hour_has_passed_since(since, vana_time)
50
+ period_has_passed_since(MS_HOUR, since, vana_time)
51
+ end
56
52
 
57
- def month_has_passed_since(since, vana_time)
58
- period_has_passed_since(MS_MONTH, since, vana_time)
59
- end
53
+ def day_has_passed_since(since, vana_time)
54
+ period_has_passed_since(MS_DAY, since, vana_time)
55
+ end
60
56
 
61
- def year_has_passed_since(since, vana_time)
62
- period_has_passed_since(MS_YEAR, since, vana_time)
63
- end
57
+ def month_has_passed_since(since, vana_time)
58
+ period_has_passed_since(MS_MONTH, since, vana_time)
59
+ end
60
+
61
+ def year_has_passed_since(since, vana_time)
62
+ period_has_passed_since(MS_YEAR, since, vana_time)
63
+ end
64
64
 
65
- def countdown(time)
66
- day_left = time.to_f / MS_DAY
67
- hour_left = (day_left.to_f - day_left.floor) * 24
68
- min_left = (hour_left.to_f - hour_left.floor) * 60
69
- sec_left = (min_left.to_f - min_left.floor) * 60
65
+ def countdown(time)
66
+ day_left = time.to_f / MS_DAY
67
+ hour_left = (day_left.to_f - day_left.floor) * 24
68
+ min_left = (hour_left.to_f - hour_left.floor) * 60
69
+ sec_left = (min_left.to_f - min_left.floor) * 60
70
70
 
71
- [day_left.floor, hour_left.floor, min_left.floor, sec_left.floor]
72
- end
71
+ [day_left.floor, hour_left.floor, min_left.floor, sec_left.floor]
72
+ end
73
73
 
74
- def format_countdown(countdown)
75
- formatted = String.new
76
- countdown[0..2].each do |part|
77
- if (part > 0)
78
- formatted += "%02d" % part
79
- formatted += ":"
80
- end
81
- end
82
- formatted += "%02d" % countdown[3]
83
- formatted
74
+ def format_countdown(countdown)
75
+ formatted = String.new
76
+ countdown[0..2].each do |part|
77
+ if (part > 0)
78
+ formatted += "%02d" % part
79
+ formatted += ":"
84
80
  end
81
+ end
82
+ formatted += "%02d" % countdown[3]
83
+ formatted
85
84
  end
85
+ end
86
86
  end