Ruby GTK3移行後のメインリポジトリ
Revision | 94d2429314c5cac73dae076b2665a3e4bd1801ed (tree) |
---|---|
Time | 2014-04-30 00:02:47 |
Author | Shyouzou Sugitani <shy@user...> |
Commiter | Shyouzou Sugitani |
add seriko.rb
@@ -19,8 +19,7 @@ require "ninix/dll" | ||
19 | 19 | |
20 | 20 | module Home |
21 | 21 | |
22 | -# PLUGIN_STANDARD = [3.0, 3.1] | |
23 | - PLUGIN_STANDARD = [0.0, 10.0] # FIXME: TEST | |
22 | + PLUGIN_STANDARD = [3.0, 3.1] | |
24 | 23 | |
25 | 24 | def self.get_ninix_home() |
26 | 25 | return File.join(File.expand_path('~'), '.ninix') |
@@ -0,0 +1,945 @@ | ||
1 | +# -*- coding: utf-8 -*- | |
2 | +# | |
3 | +# Copyright (C) 2002 by Tamito KAJIYAMA | |
4 | +# Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net> | |
5 | +# Copyright (C) 2002-2014 by Shyouzou Sugitani <shy@users.sourceforge.jp> | |
6 | +# | |
7 | +# This program is free software; you can redistribute it and/or modify it | |
8 | +# under the terms of the GNU General Public License (version 2) as | |
9 | +# published by the Free Software Foundation. It is distributed in the | |
10 | +# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | |
11 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
12 | +# PURPOSE. See the GNU General Public License for more details. | |
13 | +# | |
14 | + | |
15 | +require "gtk3" | |
16 | + | |
17 | +module Seriko | |
18 | + | |
19 | + class Controler | |
20 | + | |
21 | + DEFAULT_FPS = 30.0 # current default | |
22 | + | |
23 | + def initialize(seriko) | |
24 | + @seriko = seriko | |
25 | + self.request_parent = lambda {|a| return nil} # dummy | |
26 | + @exclusive_actor = nil | |
27 | + @base_id = nil | |
28 | + @timeout_id = nil | |
29 | + reset_overlays() | |
30 | + @queue = [] | |
31 | + @fps = Controler.DEFAULT_FPS | |
32 | + @next_tick = 0 | |
33 | + @prev_tick = 0 # XXX | |
34 | + @active = [] | |
35 | + @move = nil | |
36 | + @dirty = true | |
37 | + end | |
38 | + | |
39 | + def set_responsible(request_method) | |
40 | + self.request_parent = request_method | |
41 | + end | |
42 | + | |
43 | + def set_base_id(window, surface_id) | |
44 | + if surface_id == '-2' | |
45 | + terminate(window) | |
46 | + @base_id = window.surface_id | |
47 | + elsif surface_id == '-1' | |
48 | + @base_id = window.surface_id | |
49 | + else | |
50 | + @base_id = surface_id | |
51 | + end | |
52 | + @dirty = true | |
53 | + end | |
54 | + | |
55 | + def move_surface(xoffset, yoffset) | |
56 | + @move = [xoffset, yoffset] | |
57 | + end | |
58 | + | |
59 | + def append_actor(frame, actor) | |
60 | + @active << [frame, actor] | |
61 | + end | |
62 | + | |
63 | + def update_frame(window) | |
64 | + frame, actor = get_actor_next(window) | |
65 | + last_actor = actor | |
66 | + while actor != nil | |
67 | + actor.update(window, frame) | |
68 | + last_actor = actor | |
69 | + frame, actor = get_actor_next(window) | |
70 | + end | |
71 | + if last_actor != nil and last_actor.exclusive and \ | |
72 | + last_actor.terminate_flag and @exclusive_actor == nil # XXX | |
73 | + invoke_restart(window) | |
74 | + end | |
75 | + end | |
76 | + | |
77 | + def get_actor_next(window) | |
78 | + if not @active.empty? | |
79 | + @active.sort(key=lambda {|x| return x[0]}) | |
80 | + if @active[0][0] <= @next_tick | |
81 | + return @active.pop(0) | |
82 | + end | |
83 | + end | |
84 | + return nil, nil | |
85 | + end | |
86 | + | |
87 | + def update(window) | |
88 | + current_tick = GLib.get_monotonic_time() # [microsec] | |
89 | + quality = self.request_parent('GET', 'get_preference', 'animation_quality') | |
90 | + @fps = Controler.DEFAULT_FPS * quality | |
91 | + if @prev_tick == 0 ## First time | |
92 | + delta_tick = 1000.0 / @fps # [msec] | |
93 | + else | |
94 | + delta_tick = (current_tick - @prev_tick) / 1000 # [msec] | |
95 | + end | |
96 | + @next_tick += delta_tick | |
97 | + @prev_tick = current_tick | |
98 | + update_frame(window) | |
99 | + if @dirty | |
100 | + window.update_frame_buffer() | |
101 | + @dirty = false | |
102 | + end | |
103 | + if @move != nil | |
104 | + window.move_surface(*@move) | |
105 | + @move = nil | |
106 | + end | |
107 | + @timeout_id = GLib.timeout_add((1000.0 / @fps).to_i, # [msec] | |
108 | + @update, window) | |
109 | + return false | |
110 | + end | |
111 | + | |
112 | + def lock_exclusive(window, actor) | |
113 | + #assert @exclusive_actor is nil | |
114 | + terminate(window) | |
115 | + @exclusive_actor = actor | |
116 | + actor.set_post_proc(unlock_exclusive, [window, actor]) | |
117 | + @dirty = true # XXX | |
118 | + end | |
119 | + | |
120 | + def unlock_exclusive(window, actor) | |
121 | + #assert @exclusive_actor == actor | |
122 | + @exclusive_actor = nil | |
123 | + end | |
124 | + | |
125 | + def reset_overlays() | |
126 | + @overlays = {} | |
127 | + @dirty = true | |
128 | + end | |
129 | + | |
130 | + def remove_overlay(actor) | |
131 | + begin | |
132 | + del @overlays[actor] | |
133 | + rescue # except KeyError: | |
134 | + pass | |
135 | + end | |
136 | + @dirty = true | |
137 | + end | |
138 | + | |
139 | + def add_overlay(window, actor, surface_id, x, y, method) | |
140 | + if surface_id == '-2' | |
141 | + terminate(window) | |
142 | + end | |
143 | + if ['-1', '-2'].include?(surface_id) | |
144 | + remove_overlay(actor) | |
145 | + return | |
146 | + end | |
147 | + @overlays[actor] = [surface_id, x, y, method] | |
148 | + @dirty = true | |
149 | + end | |
150 | + | |
151 | + def invoke_actor(window, actor) | |
152 | + if @exclusive_actor != nil | |
153 | + interval = actor.get_interval() | |
154 | + if interval.start_with?('talk') or interval == 'yen-e' | |
155 | + return | |
156 | + end | |
157 | + @queue << actor | |
158 | + return | |
159 | + end | |
160 | + if actor.exclusive | |
161 | + lock_exclusive(window, actor) | |
162 | + end | |
163 | + actor.invoke(window, @next_tick) | |
164 | + end | |
165 | + | |
166 | + def invoke(window, actor_id, update=0) | |
167 | + if not @seriko.include?(@base_id) | |
168 | + return | |
169 | + end | |
170 | + for actor in @seriko[@base_id] | |
171 | + if actor_id == actor.get_id() | |
172 | + invoke_actor(window, actor) | |
173 | + break | |
174 | + end | |
175 | + end | |
176 | + end | |
177 | + | |
178 | + def invoke_yen_e(window, surface_id) | |
179 | + if not @seriko.include?(surface_id) | |
180 | + return | |
181 | + end | |
182 | + for actor in @seriko[surface_id] | |
183 | + if actor.get_interval() == 'yen-e' | |
184 | + invoke_actor(window, actor) | |
185 | + break | |
186 | + end | |
187 | + end | |
188 | + end | |
189 | + | |
190 | + def invoke_talk(window, surface_id, count) | |
191 | + if not @seriko.include?(surface_id) | |
192 | + return 0 | |
193 | + end | |
194 | + interval_count = nil | |
195 | + for actor in @seriko[surface_id] | |
196 | + interval = actor.get_interval() | |
197 | + if interval.start_with?('talk') | |
198 | + interval_count = interval[5].to_i # XXX | |
199 | + break | |
200 | + end | |
201 | + end | |
202 | + if interval_count != nil and count >= interval_count | |
203 | + invoke_actor(window, actor) | |
204 | + return 1 | |
205 | + else | |
206 | + return 0 | |
207 | + end | |
208 | + end | |
209 | + | |
210 | + def invoke_runonce(window) | |
211 | + if not @seriko.include?(@base_id) | |
212 | + return | |
213 | + end | |
214 | + for actor in @seriko[@base_id] | |
215 | + if actor.get_interval() == 'runonce' | |
216 | + invoke_actor(window, actor) | |
217 | + end | |
218 | + end | |
219 | + end | |
220 | + | |
221 | + def invoke_always(window) | |
222 | + if not @seriko.include?(@base_id) | |
223 | + return | |
224 | + end | |
225 | + for actor in @seriko[@base_id] | |
226 | + interval = actor.get_interval() | |
227 | + if ['always', 'sometimes', 'rarely'].include?(interval) or \ | |
228 | + interval.start_with?('random') or \ | |
229 | + interval.start_with?('periodic') | |
230 | + invoke_actor(window, actor) | |
231 | + end | |
232 | + end | |
233 | + end | |
234 | + | |
235 | + def invoke_restart(window) | |
236 | + if not @seriko.include?(@base_id) | |
237 | + return | |
238 | + end | |
239 | + for actor in @seriko[@base_id] | |
240 | + if @queue.include?(actor) | |
241 | + @queue.remove(actor) | |
242 | + invoke_actor(window, actor) | |
243 | + end | |
244 | + end | |
245 | + end | |
246 | + | |
247 | + def invoke_kinoko(window) # XXX | |
248 | + if not @seriko.include?(@base_id) | |
249 | + return | |
250 | + end | |
251 | + for actor in @seriko[@base_id] | |
252 | + if ['always', 'runonce', | |
253 | + 'sometimes', 'rarely',].include?(actor.get_interval()) | |
254 | + invoke_actor(window, actor) | |
255 | + end | |
256 | + end | |
257 | + end | |
258 | + | |
259 | + def reset(window, surface_id) | |
260 | + @queue = [] | |
261 | + terminate(window) | |
262 | + @next_tick = 0 | |
263 | + @prev_tick = 0 # XXX | |
264 | + set_base_id(window, window.surface_id) | |
265 | + if @seriko.include?(surface_id) | |
266 | + @base_id = surface_id | |
267 | + else | |
268 | + @base_id = window.surface_id | |
269 | + end | |
270 | + @dirty = true # XXX | |
271 | + end | |
272 | + | |
273 | + def start(window) | |
274 | + invoke_runonce(window) | |
275 | + invoke_always(window) | |
276 | + if @timeout_id != nil | |
277 | + GLib.source_remove(@timeout_id) | |
278 | + end | |
279 | + @timeout_id = GLib.timeout_add((1000.0 / @fps).to_i, # [msec] | |
280 | + @update, window) | |
281 | + end | |
282 | + | |
283 | + def terminate(window) | |
284 | + if @seriko.include?(@base_id) | |
285 | + for actor in @seriko[@base_id] | |
286 | + actor.terminate() | |
287 | + end | |
288 | + end | |
289 | + reset_overlays() | |
290 | + @active = [] | |
291 | + @move = nil | |
292 | + @dirty = true | |
293 | + end | |
294 | + | |
295 | + def stop_actor(actor_id) | |
296 | + if not @seriko.include?(@base_id) | |
297 | + return | |
298 | + end | |
299 | + for actor in @seriko[@base_id] | |
300 | + if actor.get_id() == actor_id | |
301 | + actor.terminate() | |
302 | + end | |
303 | + end | |
304 | + end | |
305 | + | |
306 | + def destroy() | |
307 | + if @timeout_id != nil | |
308 | + GLib.source_remove(!timeout_id) | |
309 | + @timeout_id = nil | |
310 | + end | |
311 | + end | |
312 | + | |
313 | + def iter_overlays() | |
314 | + actors = list(@overlays.keys()) | |
315 | + temp = [] | |
316 | + for actor in actors | |
317 | + temp << [actor.get_id(), actor] | |
318 | + end | |
319 | + actors = temp | |
320 | + actors.sort() | |
321 | + temp = [] | |
322 | + for actor_id, actor in actors | |
323 | + temp << actor | |
324 | + end | |
325 | + actors = temp | |
326 | + for actor in actors | |
327 | + surface_id, x, y, method = @overlays[actor] | |
328 | + ##logging.debug( | |
329 | + ## 'actor={0:d}, id={1}, x={2:d}, y={3:d}'.format( | |
330 | + ## actor.get_id(), surface_id, x, y)) | |
331 | + yield surface_id, x, y, method | |
332 | + end | |
333 | + end | |
334 | + end | |
335 | + | |
336 | + | |
337 | + class Actor | |
338 | + | |
339 | + def initialize(actor_id, interval) | |
340 | + @id = actor_id | |
341 | + @interval = interval | |
342 | + @patterns = [] | |
343 | + @last_method = nil | |
344 | + @exclusive = 0 | |
345 | + @post_proc = nil | |
346 | + @terminate_flag = 1 | |
347 | + end | |
348 | + | |
349 | + def set_post_proc(proc, args) | |
350 | + #assert @post_proc is None | |
351 | + @post_proc = [proc, args] | |
352 | + end | |
353 | + | |
354 | + def set_exclusive() | |
355 | + @exclusive = 1 | |
356 | + end | |
357 | + | |
358 | + def get_id() | |
359 | + return @id | |
360 | + end | |
361 | + | |
362 | + def get_interval() | |
363 | + return @interval | |
364 | + end | |
365 | + | |
366 | + def get_patterns() | |
367 | + return @patterns | |
368 | + end | |
369 | + | |
370 | + def add_pattern(surface, interval, method, args) | |
371 | + @patterns << [surface, interval, method, args] | |
372 | + end | |
373 | + | |
374 | + def invoke(window, base_frame) | |
375 | + @terminate_flag = 0 | |
376 | + end | |
377 | + | |
378 | + def update(window, base_frame) | |
379 | + if @terminate_flag | |
380 | + return False | |
381 | + end | |
382 | + pass | |
383 | + end | |
384 | + | |
385 | + def terminate() | |
386 | + @terminate_flag = 1 | |
387 | + if @post_proc != nil | |
388 | + proc, args = @post_proc | |
389 | + @post_proc = nil | |
390 | + proc(*args) | |
391 | + end | |
392 | + end | |
393 | + | |
394 | + def get_surface_ids() | |
395 | + surface_ids = [] | |
396 | + for surface, interval, method, args in @patterns | |
397 | + if method == 'base' | |
398 | + surface_ids << surface | |
399 | + end | |
400 | + end | |
401 | + return surface_ids | |
402 | + end | |
403 | + | |
404 | + OVERLAY_SET = ['overlay', 'overlayfast', | |
405 | + 'interpolate', 'reduce', 'replace', 'asis'] | |
406 | + | |
407 | + def show_pattern(window, surface, method, args) | |
408 | + if Actor.OVERLAY_SET.include?(@last_method) | |
409 | + window.remove_overlay(self) | |
410 | + end | |
411 | + if method == 'move' | |
412 | + window.seriko.move_surface(args[0], args[1]) ## FIXME | |
413 | + elsif Actor.OVERLAY_SET.include?(method) | |
414 | + window.add_overlay(self, surface, args[0], args[1], method) | |
415 | + elsif method == 'base' | |
416 | + window.seriko.set_base_id(window, surface) ## FIXME | |
417 | + elsif method == 'start' | |
418 | + window.invoke(args[0], update=1) | |
419 | + elsif method == 'alternativestart' | |
420 | + window.invoke(args.sample, update=1) | |
421 | + elsif method == 'stop' | |
422 | + window.seriko.stop_actor(args[0]) ## FIXME | |
423 | + elsif method == 'alternativestop' | |
424 | + window.seriko.stop_actor(args.sample) ## FIXME | |
425 | + else | |
426 | + raise RuntimeError('should not reach here') | |
427 | + end | |
428 | + @last_method = method | |
429 | + end | |
430 | + end | |
431 | + | |
432 | + | |
433 | + class ActiveActor < Actor # always | |
434 | + | |
435 | + def initialize(actor_id, interval) | |
436 | + super(actor_id, interval) | |
437 | + @wait = 0 | |
438 | + @pattern = 0 | |
439 | + end | |
440 | + | |
441 | + def invoke(window, base_frame) | |
442 | + terminate() | |
443 | + @terminate_flag = 0 | |
444 | + @pattern = 0 | |
445 | + update(window, base_frame) | |
446 | + end | |
447 | + | |
448 | + def update(window, base_frame) | |
449 | + if @terminate_flag | |
450 | + return False | |
451 | + end | |
452 | + if @pattern == 0 | |
453 | + @surface_id = window.get_surface() | |
454 | + end | |
455 | + surface, interval, method, args = @patterns[@pattern] | |
456 | + @pattern += 1 | |
457 | + if @pattern == @patterns.length | |
458 | + @pattern = 0 | |
459 | + end | |
460 | + show_pattern(window, surface, method, args) | |
461 | + window.append_actor(base_frame + interval, self) | |
462 | + return False | |
463 | + end | |
464 | + end | |
465 | + | |
466 | + class RandomActor < Actor # sometimes, rarely, random, periodic | |
467 | + | |
468 | + def initialize(actor_id, interval, wait_min, wait_max) | |
469 | + super(actor_id, interval) | |
470 | + @wait_min = wait_min | |
471 | + @wait_max = wait_max | |
472 | + reset() | |
473 | + end | |
474 | + | |
475 | + def reset() | |
476 | + @wait = rand(@wait_min..@wait_max) | |
477 | + @pattern = 0 | |
478 | + end | |
479 | + | |
480 | + def invoke(window, base_frame) | |
481 | + terminate() | |
482 | + @terminate_flag = 0 | |
483 | + reset() | |
484 | + window.append_actor(base_frame + @wait, self) | |
485 | + end | |
486 | + | |
487 | + def update(window, base_frame) | |
488 | + if @terminate_flag | |
489 | + return False | |
490 | + end | |
491 | + if @pattern == 0 | |
492 | + @surface_id = window.get_surface() | |
493 | + end | |
494 | + surface, interval, method, args = @patterns[@pattern] | |
495 | + @pattern += 1 | |
496 | + if @pattern < @patterns.length | |
497 | + @wait = interval | |
498 | + else | |
499 | + reset() | |
500 | + end | |
501 | + show_pattern(window, surface, method, args) | |
502 | + window.append_actor(base_frame + @wait, self) | |
503 | + return False | |
504 | + end | |
505 | + end | |
506 | + | |
507 | + | |
508 | + class OneTimeActor < Actor # runone | |
509 | + | |
510 | + def initialize(actor_id, interval) | |
511 | + super(actor_id, interval) | |
512 | + @wait = -1 | |
513 | + @pattern = 0 | |
514 | + end | |
515 | + | |
516 | + def invoke(window, base_frame) | |
517 | + terminate() | |
518 | + @terminate_flag = 0 | |
519 | + @wait = 0 | |
520 | + @pattern = 0 | |
521 | + update(window, base_frame) | |
522 | + end | |
523 | + | |
524 | + def update(window, base_frame) | |
525 | + if @terminate_flag | |
526 | + return False | |
527 | + end | |
528 | + if @pattern == 0 | |
529 | + @surface_id = window.get_surface() | |
530 | + end | |
531 | + surface, interval, method, args = @patterns[@pattern] | |
532 | + @pattern += 1 | |
533 | + if @pattern < @patterns.length | |
534 | + @wait = interval | |
535 | + else | |
536 | + @wait = -1 # done | |
537 | + terminate() | |
538 | + end | |
539 | + show_pattern(window, surface, method, args) | |
540 | + if @wait >= 0 | |
541 | + window.append_actor(base_frame + @wait, self) | |
542 | + end | |
543 | + return False | |
544 | + end | |
545 | + end | |
546 | + | |
547 | + class PassiveActor < Actor # never, yen-e, talk | |
548 | + | |
549 | + def initialize(actor_id, interval) | |
550 | + super(actor_id, interval) | |
551 | + @wait = -1 | |
552 | + end | |
553 | + | |
554 | + def invoke(window, base_frame) | |
555 | + terminate() | |
556 | + @terminate_flag = 0 | |
557 | + @wait = 0 | |
558 | + @pattern = 0 | |
559 | + update(window, base_frame) | |
560 | + end | |
561 | + | |
562 | + def update(window, base_frame) | |
563 | + if @terminate_flag | |
564 | + return False | |
565 | + end | |
566 | + if @pattern == 0 | |
567 | + @surface_id = window.get_surface() | |
568 | + end | |
569 | + surface, interval, method, args = @patterns[@pattern] | |
570 | + @pattern += 1 | |
571 | + if @pattern < @patterns.length | |
572 | + @wait = interval | |
573 | + else | |
574 | + @wait = -1 # done | |
575 | + terminate() | |
576 | + end | |
577 | + show_pattern(window, surface, method, args) | |
578 | + if @wait >= 0 | |
579 | + window.append_actor(base_frame + @wait, self) | |
580 | + end | |
581 | + return False | |
582 | + end | |
583 | + end | |
584 | + | |
585 | + | |
586 | + class Mayuna < Actor | |
587 | + | |
588 | + def set_exclusive() | |
589 | + pass | |
590 | + end | |
591 | + | |
592 | + def show_pattern(window, surface, method, args) | |
593 | + pass | |
594 | + end | |
595 | + end | |
596 | + | |
597 | + | |
598 | + def self.get_actors(config, version=1) | |
599 | + re_seriko_interval = Regexp.new('^([0-9]+)interval$') | |
600 | + re_seriko_interval_value = Regexp.new('^(sometimes|rarely|random,[0-9]+|always|runonce|yesn-e|talk,[0-9]+|never)$') | |
601 | + re_seriko_pattern = Regexp.new('^([0-9]+|-[12])\s*,\s*([+-]?[0-9]+)\s*,\s*(overlay|overlayfast|base|move|start|alternativestart|)\s*,?\s*([+-]?[0-9]+)?\s*,?\s*([+-]?[0-9]+)?\s*,?\s*(\[[0-9]+(\.[0-9]+)*\])?$') | |
602 | + re_seriko2_interval = Regexp.new('^animation([0-9]+)\.interval$') | |
603 | + re_seriko2_interval_value = Regexp.new('^(sometimes|rarely|random,[0-9]+|periodic,[0-9]+|always|runonce|yesn-e|talk,[0-9]+|never)$') | |
604 | + re_seriko2_pattern = Regexp.new('^(overlay|overlayfast|interpolate|reduce|replace|asis|base|move|start|alternativestart|stop|alternativestop)\s*,\s*([0-9]+|-[12])?\s*,?\s*([+-]?[0-9]+)?\s*,?\s*([+-]?[0-9]+)?\s*,?\s*([+-]?[0-9]+)?\s*,?\s*(\([0-9]+([\.\,][0-9]+)*\))?$') | |
605 | + buf = [] | |
606 | + for key, value in config.each_entry | |
607 | + if version == 1 | |
608 | + match = re_seriko_interval.match(key) | |
609 | + elsif version == 2 | |
610 | + match = re_seriko2_interval.match(key) | |
611 | + else | |
612 | + return [] ## should not reach here | |
613 | + end | |
614 | + if not match | |
615 | + next | |
616 | + end | |
617 | + if version == 1 and not re_seriko_interval_value.match(value) | |
618 | + next | |
619 | + end | |
620 | + if version == 2 and not re_seriko2_interval_value.match(value) | |
621 | + next | |
622 | + end | |
623 | + buf << [match[1].to_i, value] | |
624 | + end | |
625 | + actors = [] | |
626 | + for actor_id, interval in buf | |
627 | + if interval == 'always' | |
628 | + actor = Seriko::ActiveActor.new(actor_id, interval) | |
629 | + elsif interval == 'sometimes' | |
630 | + actor = Seriko::RandomActor.new(actor_id, interval, 0, 10000) # 0 to 10 seconds | |
631 | + elsif interval == 'rarely' | |
632 | + actor = Seriko::RandomActor.new(actor_id, interval, 20000, 60000) | |
633 | + elsif interval.start_with?('random') | |
634 | + actor = Seriko::RandomActor.new(actor_id, interval, | |
635 | + 0, 1000 * interval[7, interval.length - 1].to_i) | |
636 | + elsif interval.start_with?('periodic') | |
637 | + actor = Seriko::RandomActor.new(actor_id, interval, | |
638 | + 1000 * interval[9, interval.length - 1].to_i, | |
639 | + 1000 * interval[9, interval.length - 1].to_i) | |
640 | + elsif interval == 'runonce' | |
641 | + actor = Seriko::OneTimeActor.new(actor_id, interval) | |
642 | + elsif interval == 'yen-e' | |
643 | + actor = Seriko::PassiveActor.new(actor_id, interval) | |
644 | + elsif interval.start_with?('talk') | |
645 | + actor = Seriko::PassiveActor.new(actor_id, interval) | |
646 | + elsif interval == 'never' | |
647 | + actor = Seriko::PassiveActor.new(actor_id, interval) | |
648 | + end | |
649 | + if version == 1 | |
650 | + key = actor_id.to_s + 'option' | |
651 | + else | |
652 | + key = 'animation' + actor_id.to_s + '.option' | |
653 | + end | |
654 | + if config.include?(key) and config[key] == 'exclusive' | |
655 | + actor.set_exclusive() | |
656 | + end | |
657 | + if 1#begin | |
658 | + for n in 0..127 # up to 128 patterns (0 - 127) | |
659 | + if version == 1 | |
660 | + key = actor_id.to_s + 'pattern' + n.to_s | |
661 | + else | |
662 | + key = 'animation' + actor_id.to_s + '.pattern' + n.to_s | |
663 | + end | |
664 | + if not config.include?(key) | |
665 | + key = actor_id.to_s + 'patturn' + n.to_s # only for version 1 | |
666 | + if not config.include?(key) | |
667 | + key = actor_id.to_s + 'putturn' + n.to_s # only for version 1 | |
668 | + if not config.include?(key) | |
669 | + next # XXX | |
670 | + end | |
671 | + end | |
672 | + end | |
673 | + pattern = config[key] | |
674 | + if version == 1 | |
675 | + match = re_seriko_pattern.match(pattern) | |
676 | + else | |
677 | + match = re_seriko2_pattern.match(pattern) | |
678 | + end | |
679 | + if not match | |
680 | +# raise ValueError('unsupported pattern: {0}'.format(pattern)) | |
681 | +# raise ValueError, 'unsupported pattern: ' + pattern + "\n" | |
682 | +# raise 'unsupported pattern: ' + pattern + "\n" | |
683 | + print('unsupported pattern: ' + pattern + "\n") | |
684 | + next ## FIXME | |
685 | + end | |
686 | + if version == 1 | |
687 | + surface = match[1].to_i.to_s | |
688 | + interval = match[2].to_i.abs * 10 | |
689 | + method = match[3] | |
690 | + else | |
691 | + method = match[1] | |
692 | + if not match[2] | |
693 | + surface = 0 | |
694 | + else | |
695 | + surface = match[2].to_i.to_s | |
696 | + end | |
697 | + if not match[3] | |
698 | + interval = 0 | |
699 | + else | |
700 | + interval = match[3].to_i.abs | |
701 | + end | |
702 | + end | |
703 | + if method == '' | |
704 | + method = 'base' | |
705 | + end | |
706 | + if ['start', 'stop'].include?(method) | |
707 | + if version == 2 | |
708 | + group = match[2] | |
709 | + surface = -1 # XXX | |
710 | + else | |
711 | + group = match[4] | |
712 | + end | |
713 | + if group == nil | |
714 | +# raise ValueError('syntax error: {0}'.format(pattern)) | |
715 | +# raise ValueError, 'syntax error: ' + pattern + "\n" | |
716 | +# raise 'syntax error: ' + pattern + "\n" | |
717 | + print('syntax error: ' + pattern + "\n") | |
718 | + next ## FIXME | |
719 | + end | |
720 | + args = [group.to_i] | |
721 | + elsif ['alternativestart', 'alternativestop'].include?(method) | |
722 | + args = match[6] | |
723 | + if args == nil | |
724 | +# raise ValueError('syntax error: {0}'.format(pattern)) | |
725 | +# raise ValueError, 'syntax error: ' + pattern + "\n" | |
726 | +# raise 'syntax error: ' + pattern + "\n" | |
727 | + print('syntax error: ' + pattern + "\n") | |
728 | + next ## FIXME | |
729 | + end | |
730 | + t = [] | |
731 | + for x in args[1, args.length - 2].split('.') | |
732 | + for y in x.split(',') | |
733 | + t << y | |
734 | + end | |
735 | + end | |
736 | + args = [] | |
737 | + for s in t | |
738 | + args << s.to_i | |
739 | + end | |
740 | + else | |
741 | + if ['-1', '-2'].include?(surface) | |
742 | + x = 0 | |
743 | + y = 0 | |
744 | + else | |
745 | + if not match[4] | |
746 | + x = 0 | |
747 | + else | |
748 | + x = match[4].to_i | |
749 | + end | |
750 | + if not match[5] | |
751 | + y = 0 | |
752 | + else | |
753 | + y = match[5].to_i | |
754 | + end | |
755 | + end | |
756 | + args = [x, y] | |
757 | + end | |
758 | + actor.add_pattern(surface, interval, method, args) | |
759 | + end | |
760 | + else #rescue # except ValueError as error: | |
761 | + #logging.error('seriko.py: ' + error.to_s) | |
762 | + next | |
763 | + end | |
764 | + if not actor.get_patterns() | |
765 | +# logging.error( | |
766 | +# 'seriko.py: animation group #{0:d} has no pattern (ignored)'.format(actor_id)) | |
767 | + print('seriko.py: animation group #', actor_id, ' has no pattern (ignor | |
768 | +ed)', "\n") | |
769 | + next | |
770 | + end | |
771 | + actors << actor | |
772 | + end | |
773 | + temp = [] | |
774 | + for actor in actors | |
775 | + temp << [actor.get_id(), actor] | |
776 | + end | |
777 | + actors = temp | |
778 | + actors.sort() | |
779 | + temp = [] | |
780 | + for actor_id, actor in actors | |
781 | + temp << actor | |
782 | + end | |
783 | + actors = temp | |
784 | + return actors | |
785 | + end | |
786 | + | |
787 | + def self.get_mayuna(config) | |
788 | + re_mayuna_interval = Regexp.new('^([0-9]+)interval$') | |
789 | + re_mayuna_interval_value = Regexp.new('^(bind)$') | |
790 | + re_mayuna_pattern = Regexp.new('^([0-9]+|-[12])\s*,\s*([0-9]+)\s*,\s*(bind|add|reduce|insert)\s*,?\s*([+-]?[0-9]+)?\s*,?\s*([+-]?[0-9]+)?\s*,?\s*(\[[0-9]+(\.[0-9]+)*\])?$') | |
791 | + re_mayuna2_interval = Regexp.new('^animation([0-9]+)\.interval$') | |
792 | + re_mayuna2_interval_value = Regexp.new('^(bind)$') | |
793 | + re_mayuna2_pattern = Regexp.new('^(bind|add|reduce|insert)\s*,\s*([0-9]+|-[12])\s*,\s*([0-9]+)\s*,?\s*([+-]?[0-9]+)?\s*,?\s*([+-]?[0-9]+)?\s*,?\s*(\([0-9]+(\.[0-9]+)*\))?$') | |
794 | + version = nil | |
795 | + buf = [] | |
796 | + for key, value in config.each_entry | |
797 | + if version == 1 | |
798 | + match = re_mayuna_interval.match(key) | |
799 | + elsif version == 2 | |
800 | + match = re_mayuna2_interval.match(key) | |
801 | + else | |
802 | + match1 = re_mayuna_interval.match(key) | |
803 | + match2 = re_mayuna2_interval.match(key) | |
804 | + if match1 | |
805 | + version = 1 | |
806 | + match = match1 | |
807 | + elsif match2 | |
808 | + version = 2 | |
809 | + match = match2 | |
810 | + else | |
811 | + next | |
812 | + end | |
813 | + end | |
814 | + if not match | |
815 | + next | |
816 | + end | |
817 | + if version == 1 and not re_mayuna_interval_value.match(value) | |
818 | + next | |
819 | + end | |
820 | + if version == 2 and not re_mayuna2_interval_value.match(value) | |
821 | + next | |
822 | + end | |
823 | + buf << [match[1].to_i, value] | |
824 | + end | |
825 | + mayuna = [] | |
826 | + for mayuna_id, interval in buf | |
827 | + ##assert interval == 'bind' | |
828 | + actor = Seriko::Mayuna.new(mayuna_id, interval) | |
829 | + begin | |
830 | + for n in 0..127 # up to 128 patterns (0 - 127) | |
831 | + if version == 1 | |
832 | + key = mayuna_id.to_s + 'pattern' + n.to_s | |
833 | + else | |
834 | + key = 'animation' + mayuna_id.to_s + '.pattern' + n.to_s | |
835 | + end | |
836 | + if not config.include?(key) | |
837 | + key = mayuna_id.to_s + 'patturn' + n.to_s # only for version 1 | |
838 | + if not config.include?(key) | |
839 | + next # XXX | |
840 | + end | |
841 | + end | |
842 | + pattern = config[key] | |
843 | + if version == 1 | |
844 | + match = re_mayuna_pattern.match(pattern) | |
845 | + else | |
846 | + match = re_mayuna2_pattern.match(pattern) | |
847 | + end | |
848 | + if not match | |
849 | +# raise ValueError('unsupported pattern: {0}'.format(pattern)) | |
850 | +# raise ValueError, 'unsupported pattern: ' + pattern + "\n" | |
851 | +# raise 'unsupported pattern: ' + pattern + "\n" | |
852 | + print('unsupported pattern: ' + pattern + "\n") | |
853 | + next ## FIXME | |
854 | + end | |
855 | + if version == 1 | |
856 | + surface = match[1].to_i.to_s | |
857 | + interval = match[2].to_i.abs * 10 | |
858 | + method = match[3] | |
859 | + else | |
860 | + method = match[1] | |
861 | + surface = match[2].to_i.to_s | |
862 | + interval = match[3].to_i.abs | |
863 | + end | |
864 | + if not ['bind', 'add', 'reduce', 'insert'].include?(method) | |
865 | + next | |
866 | + else | |
867 | + if ['-1', '-2'].include?(surface) | |
868 | + x = 0 | |
869 | + y = 0 | |
870 | + else | |
871 | + if not match[4] | |
872 | + x = 0 | |
873 | + else | |
874 | + x = match[4].to_i | |
875 | + end | |
876 | + if not match[5] | |
877 | + y = 0 | |
878 | + else | |
879 | + y = match[5].to_i | |
880 | + end | |
881 | + end | |
882 | + args = [x, y] | |
883 | + end | |
884 | + actor.add_pattern(surface, interval, method, args) | |
885 | + end | |
886 | + rescue # except ValueError as error: | |
887 | + logging.error('seriko.py: ' + error.to_s) | |
888 | + next | |
889 | + end | |
890 | + if not actor.get_patterns() | |
891 | + ## FIXME | |
892 | + #logging.error('seriko.py: animation group #{0:d} has no pattern (ignored)'.format(mayuna_id)) | |
893 | + next | |
894 | + end | |
895 | + mayuna << actor | |
896 | + end | |
897 | + temp = [] | |
898 | + for actor in mayuna | |
899 | + temp << [actor.get_id(), actor] | |
900 | + end | |
901 | + mayuna = temp | |
902 | + mayuna.sort() | |
903 | + temp = [] | |
904 | + for actor_id, actor in mayuna | |
905 | + temp << actor | |
906 | + end | |
907 | + mayuna = temp | |
908 | + return mayuna | |
909 | + end | |
910 | + | |
911 | + | |
912 | + class TEST | |
913 | + | |
914 | + # find ~/.ninix -name 'surface*a.txt' | xargs ruby seriko.rb | |
915 | + def initialize(list_path) | |
916 | + require "ninix/config" | |
917 | +# if len(sys.argv) == 1 | |
918 | +# print('Usage:', sys.argv[0], '[surface??a.txt ...]') | |
919 | +# end | |
920 | + for filename in list_path | |
921 | + print('Reading', filename, '...', "\n") | |
922 | + for actor in Seriko.get_actors(NConfig.create_from_file(filename)) | |
923 | + print('#', actor.get_id().to_i.to_s, "\n") | |
924 | + #print(actor.__class__.__name__,) | |
925 | + print('(', actor.get_interval(), ')', "\n") | |
926 | + print('number of patterns = ', actor.get_patterns().length, "\n") | |
927 | + for pattern in actor.get_patterns() | |
928 | + print('surface=', pattern[0], ', interval=', pattern[1].to_i.to_s, ', method=', pattern[2], ', args=', pattern[3], "\n") | |
929 | + end | |
930 | + end | |
931 | + for actor in Seriko.get_mayuna(NConfig.create_from_file(filename)) | |
932 | + print('#', actor.get_id().to_i.to_s, "\n") | |
933 | + #print(actor.__class__.__name__,) | |
934 | + print('(', actor.get_interval(), ')', "\n") | |
935 | + print('number of patterns =', actor.get_patterns().length, "\n") | |
936 | + for pattern in actor.get_patterns() | |
937 | + print('surface=', pattern[0], ', interval=', pattern[1].to_i.to_s, ', method=', pattern[2], ', args=', pattern[3], "\n") | |
938 | + end | |
939 | + end | |
940 | + end | |
941 | + end | |
942 | + end | |
943 | +end | |
944 | + | |
945 | +Seriko::TEST.new(ARGV) |