Class: Osb::Storyboard
- Inherits:
-
Object
- Object
- Osb::Storyboard
- Defined in:
- lib/osb/storyboard.rb
Overview
Instance Method Summary collapse
-
#<<(object) ⇒ self
Alias for #add.
- #add(object) ⇒ self
-
#generate(out_path) ⇒ void
Generate an osb or osu file for this storyboard.
-
#initialize ⇒ Storyboard
constructor
A new instance of Storyboard.
-
#to_s ⇒ String
Returns the storyboard string.
Constructor Details
#initialize ⇒ Storyboard
Returns a new instance of Storyboard.
127 128 129 |
# File 'lib/osb/storyboard.rb', line 127 def initialize @layers = Internal::LayerManager.new end |
Instance Method Details
#<<(object) ⇒ self
Alias for #add. Add a Osb::Sprite, Animation, Osb::Sample, Video, Background or Group to this storyboard.
166 167 168 |
# File 'lib/osb/storyboard.rb', line 166 def <<(object) self.add(object) end |
#add(object) ⇒ self
Add a Osb::Sprite, Animation, Osb::Sample, Video, Background or Group to this storyboard.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/osb/storyboard.rb', line 136 def add(object) Internal.assert_type!( object, [ Osb::Group, Osb::Sprite, Osb::Animation, Osb::Video, Osb::Background, Osb::Sample ], "object" ) case object when Osb::Sprite, Osb::Animation, Osb::Sample, Osb::Video, Osb::Background @layers.add(object) when Osb::Group @layers.concat(object) end return self end |
#generate(out_path) ⇒ void
This method returns an undefined value.
Generate an osb or osu file for this storyboard.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/osb/storyboard.rb', line 207 def generate(out_path) Internal.assert_file_name_ext!(out_path, %w[osb osu]) case File.extname(out_path) when ".osu" unless File.exist?(out_path) raise InvalidValueError, "Cannot find osu file." end out_osu_file = "" File .readlines(out_path) .each do |line| if line.match(/[Events]/) out_osu_file += self.to_s else out_osu_file += line end end File.new(out_path, "w").write(out_osu_file) when ".osb" File.new(out_path, "w").write(self.to_s) else raise InvalidValueError, "Not osu or osb file." # should not be here end end |
#to_s ⇒ String
Returns the storyboard string.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/osb/storyboard.rb', line 172 def to_s bg_and_video_layer = @layers.bg_and_video.map { |object| object.command }.join("\n") background_layer = @layers .background .map { |object| object.commands.join("\n") } .join("\n") fail_layer = @layers.fail.map { |object| object.commands.join("\n") }.join("\n") pass_layer = @layers.pass.map { |object| object.commands.join("\n") }.join("\n") foreground_layer = @layers .foreground .map { |object| object.commands.join("\n") } .join("\n") = @layers..map { |object| object.commands.join("\n") }.join("\n") samples_layer = @layers.samples.map { |object| object.command }.join("\n") osb_string = "[Events]\n" osb_string += "//Background and Video events\n" + bg_and_video_layer + "\n" + "//Storyboard Layer 0 (Background)\n" + background_layer + "\n" + "//Storyboard Layer 1 (Fail)\n" + fail_layer + "\n" + "//Storyboard Layer 2 (Pass)\n" + pass_layer + "\n" + "//Storyboard Layer 3 (Foreground)\n" + foreground_layer + "\n" + "//Storyboard Layer 4 (Overlay)\n" + + "\n" + "//Storyboard Sound Samples\n" + samples_layer + "\n" end |