Class: Miyako::Story

Inherits:
Object show all
Defined in:
lib/Miyako/API/story.rb

Overview

シーン実行クラス

用意したシーンインスタンスを実行

Defined Under Namespace

Modules: Scene Classes: ScenePool

Constant Summary collapse

@@sub_scenes =
[:sub_scene, :sub_routine]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStory

インスタンスの作成

ストーリー情報の初期か

返却値

生成したインスタンス


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/Miyako/API/story.rb', line 47

def initialize
  @prev_label = nil
  @next_label = nil

  @stack = []

  @scene_cache = Hash.new
  @scene_cache_list = Array.new
  @scene_cache_max = 20

  @hand_over = nil
end

Instance Attribute Details

#hand_overObject

Returns the value of attribute hand_over


28
29
30
# File 'lib/Miyako/API/story.rb', line 28

def hand_over
  @hand_over
end

Instance Method Details

#disposeObject

内部の情報を解放する


130
131
132
# File 'lib/Miyako/API/story.rb', line 130

def dispose
  @scene_cache.keys.each{|k| @scene_cache[del_symbol].dispose }
end

#get_scene(n, s) ⇒ Object

:nodoc:


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/Miyako/API/story.rb', line 66

def get_scene(n, s) #:nodoc:
  class_symbol = n.to_s
  if @scene_cache_list.length == @scene_cache_max
    del_symbol = @scene_cache_list.shift
    @scene_cache[del_symbol].dispose
    @scene_cache.delete(del_symbol)
  end
  @scene_cache_list.delete(class_symbol)
  @scene_cache_list.push(class_symbol)
  @scene_cache[class_symbol] ||= n.new(self)
  return @scene_cache[class_symbol]
end

#initialize_copy(obj) ⇒ Object

:nodoc:


60
61
62
63
64
# File 'lib/Miyako/API/story.rb', line 60

def initialize_copy(obj) #:nodoc:
  @stack = @stack.dup
  @scene_cache = @scene_cache.dup
  @scene_cache_list = @scene_cache_list.dup
end

#next_labelObject

:nodoc:


36
37
38
# File 'lib/Miyako/API/story.rb', line 36

def next_label #:nodoc:
  return @next_label
end

#prev_labelObject

:nodoc:


32
33
34
# File 'lib/Miyako/API/story.rb', line 32

def prev_label #:nodoc:
  return @prev_label
end

#run(n, init_ho = nil) ⇒ Object

Storyの実行を始める

“obj.run(MainScene)”と記述すると、SceneモジュールをmixinしたMainSceneクラスのインスタンスを作成し、評価を始める

n

最初に実行するシーン名(クラス名を定数で)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/Miyako/API/story.rb', line 82

def run(n, init_ho = nil)
  return nil if n == nil
  u = nil
  on = nil
  @stack = Array.new # reset
  @hand_over = init_ho
  while n != nil
    @prev_label = on
    on = n

    raise MiyakoValueError, "Illegal Script-label name! : #{n}" unless Scene.has_scene?(n.to_s)
    raise MiyakoValueError, "This scene cannot use for Standard Scene! : #{n}" if n.scene_type != :scene and !@@sub_scenes.include?(n.scene_type)
    u = get_scene(n, @stack.size) if u == nil
    u.hand_over = @hand_over
    @hand_over = nil
    u.init_inner(@prev_label, self.upper_label)
    u.setup

    Miyako.main_loop do
      bk_n = on
      n = u.update
      n, @hand_over = n if n and n.kind_of?(Array)
      u.render
      break unless n && on.eql?(n)
    end
    u.clear_hand_over
    u.next = n
    @next_label = n
    u.final
    if n.nil?
      if @@sub_scenes.include?(u.class.scene_type) && @stack.empty? == false
        n, u = @stack.pop
        next
      end
      break
    elsif @@sub_scenes.include?(n.scene_type)
      @stack.push([on, u])
      u = nil
    else
      u = nil
    end
  end
  @scene_cache_list.each{|sy| @scene_cache[sy].dispose }
  @scene_cache.clear
  @scene_cache_list.clear
end

#upper_labelObject

:nodoc:


40
41
42
# File 'lib/Miyako/API/story.rb', line 40

def upper_label #:nodoc:
  return @stack.empty? ? nil : @stack.last[0]
end