VanaTime 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/Manifest +3 -0
- data/README +95 -125
- data/VanaTime.gemspec +17 -17
- data/lib/Vana/common.rb +65 -65
- data/lib/Vana/constants.rb +20 -21
- data/lib/Vana/day.rb +47 -44
- data/lib/Vana/element.rb +45 -40
- data/lib/Vana/moon.rb +131 -139
- data/lib/Vana/moon_countdown.rb +48 -51
- data/lib/Vana/skillup_calculator.rb +142 -0
- data/lib/Vana/time.rb +98 -110
- data/lib/Vana/time_manager.rb +91 -64
- data/lib/util/log_listener.rb +15 -0
- data/lib/util/ruby_bean.rb +39 -0
- data/lib/vana_time.rb +7 -2
- metadata +35 -39
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.
|
1
|
+
VanaTime 2.1.0 README
|
2
2
|
=====================
|
3
3
|
|
4
|
-
This document was last updated on
|
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
|
23
|
-
else up in a convenient
|
24
|
-
does updates when necessary, and
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
tm
|
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
|
-
|
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
|
-
|
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
|
-
*
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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.
|
data/VanaTime.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Vanatime-2.
|
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.
|
8
|
-
s.date = %q{2007-09-
|
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.
|
22
|
+
# version = "2.1.0"
|
23
23
|
#
|
24
24
|
# ENV['RUBY_FLAGS'] = ""
|
25
25
|
#
|
26
26
|
# begin
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
27
|
+
# require 'rubygems'
|
28
|
+
# gem 'echoe', '=2.4'
|
29
|
+
# require 'echoe'
|
30
30
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
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
|
-
#
|
41
|
-
#
|
40
|
+
# puts "You are missing a dependency required for meta-operations on this gem."
|
41
|
+
# puts "#{boom.to_s.capitalize}."
|
42
42
|
# end
|
data/lib/Vana/common.rb
CHANGED
@@ -1,86 +1,86 @@
|
|
1
1
|
module FFXI
|
2
|
-
|
3
|
-
|
2
|
+
module Common
|
3
|
+
include FFXI::Constants
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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
|
-
|
18
|
-
vana_time.to_f - (vana_time.to_f % period )
|
19
|
-
end
|
15
|
+
private
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def start_of_period(vana_time, period)
|
18
|
+
vana_time.to_f - (vana_time.to_f % period )
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
37
|
+
elapsed >= period
|
38
|
+
end
|
39
|
+
end
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def second_has_passed_since(since, vana_time)
|
42
|
+
period_has_passed_since(MS_SECOND, since, vana_time)
|
43
|
+
end
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
def minute_has_passed_since(since, vana_time)
|
46
|
+
period_has_passed_since(MS_MINUTE, since, vana_time)
|
47
|
+
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
def hour_has_passed_since(since, vana_time)
|
50
|
+
period_has_passed_since(MS_HOUR, since, vana_time)
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
def day_has_passed_since(since, vana_time)
|
54
|
+
period_has_passed_since(MS_DAY, since, vana_time)
|
55
|
+
end
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
72
|
-
|
71
|
+
[day_left.floor, hour_left.floor, min_left.floor, sec_left.floor]
|
72
|
+
end
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|