Class: Osb::Storyboard

Inherits:
Object
  • Object
show all
Defined in:
lib/osb/storyboard.rb

Overview

Represent an osu! storyboard. Each sprite or animation can be added directly to the storyboard instance, or through an intermediate group. A group can have multiple nested groups in itself.

Instance Method Summary collapse

Constructor Details

#initializeStoryboard

Returns a new instance of Storyboard.



125
126
127
# File 'lib/osb/storyboard.rb', line 125

def initialize
  @layers = Internal::LayerManager.new
end

Instance Method Details

#<<(object) ⇒ self

Add an Osb::Sprite, Osb::Animation, Osb::Sample, Osb::Video, Osb::Background or Osb::Group to this storyboard. Alias for #add.

Parameters:

Returns:

  • (self)


163
164
165
# File 'lib/osb/storyboard.rb', line 163

def <<(object)
  self.add(object)
end

#add(object) ⇒ self

Add an Osb::Sprite, Osb::Animation, Osb::Sample, Osb::Video, Osb::Background or Osb::Group to this storyboard.

Parameters:

Returns:

  • (self)


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/osb/storyboard.rb', line 134

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.

Parameters:

  • out_path (String)

    path to .osb or .osu file



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/osb/storyboard.rb', line 204

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_sString

Returns the storyboard string.

Returns:

  • (String)


169
170
171
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
# File 'lib/osb/storyboard.rb', line 169

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")
  overlay_layer =
    @layers.overlay.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" + overlay_layer + "\n" +
      "//Storyboard Sound Samples\n" + samples_layer + "\n"
end