OSDN Git Service

2009-01-25:コアタイム(21時~24時)中の最小参加人数を変更
[wolvez/wolvez.git] / trunk / lib / ms / page.rb
1 module Page
2         
3         class Base
4                 def initialize
5                         klass = self.class.to_s.gsub(/.*::/ , '').downcase
6                         @suffix = '.rhtml'
7                         @fp = 'skel/' + klass + @suffix
8
9                         @header, @footer = true, true
10                 end
11
12                 def header
13                         _ = HEAD1
14
15                         if @title
16                                 _ << "<title>#{GAME_TITLE} #{@title}</title>\n"
17                         else
18                                 _ << "<title>#{GAME_TITLE}</title>\n"
19                         end
20
21                         _ << HEAD2.sub(/<body.*/, '<body>')
22                         _ << HEAD3
23                         _ << @login if @login
24                         _
25                 end
26
27                 def footer
28                         FOOT + "</div></body></html>"
29                 end
30
31                 def result
32                         erb = Erubis::Eruby.load_file(@fp)
33                         # erb = ERB.new(File.read(@fp))
34                         erb.filename = @fp
35                         _ = ''
36                         _ << header() if @header
37                         _ << erb.result(binding)
38                         _ << footer() if @footer
39                         _
40                 end
41         end
42
43         class Index < Base
44                 def initialize(login, changes, villages)
45                         super()
46                         @footer = false
47
48                         @login = login
49                         changes = changes.sort {|x, y| y[0] <=> x[0]}
50                         @changes = changes[0, S[:index_info]]
51                         @villages = villages.reverse.each {|v|
52                                 np = (v['state'] == 0) ? DB::Village.players(v['vid']).size : ''
53                                 v['state_str'] = STATES[v['state']]
54                                 if v['state'] < Vil::State::Ready
55                                         v['state_str'] += "<br>(#{np.to_s}/#{S[:max_entries]})"
56                                 end
57                                 v['start_str'] = v['start'].strftime("%H時%M分")
58                         }
59                 end
60         end
61
62         class LogIndex < Base
63                 def initialize(login)
64                         require 'cache'
65                         super()
66
67                         ckey = File.mtime(S[:vilsdb_path]).to_i.to_s
68                         cache = Cache::FileCache.new(:root_dir => S[:cache_dir] + 'log/')
69
70                         begin
71                                 @villages = cache.get_object(ckey)
72                         rescue Cache::CacheMiss
73                                 cache.clear()
74                                 @villages = DB::Villages.select {|v| v['state'] == 4 }
75                                 cache.set_object(ckey, @villages)
76                         end
77
78                         @login = login
79                         @title = '終了した村の記録'
80                 end
81         end
82
83         class History < Base
84                 def initialize(login, history)
85                         super()
86
87                         @login = login
88                         @title = '開発履歴'
89                         @history = history
90                 end
91         end
92
93         class Info < Base
94                 def initialize(login, changes)
95                         super()
96
97                         @login = login
98                         @title = 'お知らせ'
99                         @changes = changes
100                 end
101         end
102
103         class MakeVillage < Base
104                 def initialize(login)
105                         super()
106
107                         @login = login
108                         @title = '村を作成する'
109                 end
110         end
111
112         class CharList < Base
113                 def initialize(login, chars)
114                         super()
115
116                         @login = login
117                         @title = 'キャラクター一覧'
118                         @chars = chars
119                 end
120         end
121
122         class Document < Base
123                 def initialize(login)
124                         super()
125
126                         @login = login
127                         @title = 'しおり'
128                 end
129         end
130
131         class Regulation < Base
132                 def initialize(login)
133                         require 'cache'
134                         super()
135
136                         ckey = File.mtime(S[:reg_file]).to_i.to_s
137                         cache = Cache::FileCache.new(:root_dir => S[:cache_dir] + 'reg/')
138
139                         begin
140                                 @table = cache.get_object(ckey)
141                         rescue Cache::CacheMiss
142                                 cache.clear()
143                                 @table = {}
144                                 Vil::Regulation::Table.keys().sort.each {|num|
145                                         @table[num] = Vil::Regulation.to_str(num)
146                                 }
147                                 cache.set_object(ckey, @table)
148                         end
149
150                         @login = login
151                         @title = '役職配分一覧'
152                 end
153         end
154
155         class Day < Base
156                 def initialize(login, village, date, player)
157                         super()
158                         @footer = false
159
160                         @login = login
161                         @vil = village
162                         @date = date
163                         @player = player
164                         @title = "#{@vil.vid} #{@vil.name}"
165                 end
166         end
167
168         class ActionBalloon < Base
169                 def initialize(player, login, village)
170                         super()
171
172                         @header, @footer = false, false
173                         @player = player
174                         @login = login
175                         @vil = village
176                         @lockid = LockID.new
177
178                         klass = 'entry'
179
180                         @fp = 'skel/' + klass + @suffix
181                 end
182         end
183
184         class Order < Base
185                 def initialize(login, vil)
186                         super()
187                         @header, @footer = false, false
188
189                         @login = login
190                         @vil = vil
191                         @up = @vil.update_time
192                         @orders = (vil.state == 3) ? show_winner() : show_update()
193                         @orders << PLEASE_LOGIN unless @login.login
194                 end
195
196
197                 private
198
199                 def show_winner
200                         [c(SHOW_WINNER_STATIC, @vil.winner, @up.hour, @up.min)]
201                 end
202
203                 def show_update
204                         _ = []
205
206                         if @vil.state == Vil::State::Welcome
207                                 #2009/01/25 mod tkt for min_entries by coretime|| min_entries = (@vil.first_restart) ? S[:min_entries] : S[:apply_advance_num]
208                                 min_entries = (@vil.first_restart) ? min_entries_num(@up, true) : S[:apply_advance_num]
209                                 _ << c(SHOW_UPDATE_PR_STATIC, @up.hour, @up.min, @up.sec, min_entries)
210                         else
211                                 _ << c(SHOW_UPDATE_STATIC, @up.hour, @up.min, @up.sec)
212                         end
213                         _
214                 end
215         end
216
217 end