Module: Osb::Commandable
Instance Method Summary collapse
-
#additive_color_blending(start_time:, end_time:) ⇒ Object
Use additive-color blending instead of alpha-blending.
-
#color(start_time:, end_time: start_time, easing: Easing::Linear, start_color:, end_color: start_color) ⇒ Object
The virtual light source colour on the object.
-
#fade(start_time:, end_time: start_time, easing: Easing::Linear, start_opacity:, end_opacity: start_opacity) ⇒ Object
Change the opacity of the object (how transparent it is).
-
#flip(start_time:, end_time:, horizontally: true, vertically: false) ⇒ Object
Flip the object horizontally or vertically.
-
#move(start_time:, end_time: start_time, easing: Easing::Linear, start_position:, end_position: start_position) ⇒ Object
Move the object to a new position in the play area.
-
#move_x(start_time:, end_time: start_time, easing: Easing::Linear, start_x:, end_x: start_x) ⇒ Object
Move the object along the x axis.
-
#move_y(start_time:, end_time: start_time, easing: Easing::Linear, start_y:, end_y: start_y) ⇒ Object
Move the object along the y axis.
-
#rotate(start_time:, end_time: start_time, easing: Easing::Linear, start_angle:, end_angle: start_angle) ⇒ Object
Rotate the object around its origin.
-
#scale(start_time:, end_time: start_time, easing: Easing::Linear, start_scale:, end_scale: start_scale) ⇒ Object
Change the size of the object relative to its original size.
-
#trigger(on:, start_time:, end_time:) {|_self| ... } ⇒ Object
Add a group of commands on a specific condition.
Instance Method Details
#additive_color_blending(start_time:, end_time:) ⇒ Object
Use additive-color blending instead of alpha-blending.
307 308 309 310 311 312 313 314 315 |
# File 'lib/osb/commandable.rb', line 307 def additive_color_blending(start_time:, end_time:) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) tabs = " " * self.tab_level command = "#{tabs}P,#{start_time},#{end_time},A" @commands << command end |
#color(start_time:, end_time: start_time, easing: Easing::Linear, start_color:, end_color: start_color) ⇒ Object
The virtual light source colour on the object. The colours of the pixels on the object are determined subtractively.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/osb/commandable.rb', line 253 def color( start_time:, end_time: start_time, easing: Easing::Linear, start_color:, end_color: start_color ) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) Internal.raise_if_invalid_easing!(easing) Internal.assert_type!(start_color, Osb::Color, "start_color") Internal.assert_type!(end_color, Osb::Color, "end_color") end_time = "" if start_time == end_time tabs = " " * self.tab_level command = "#{tabs}C,#{start_time},#{end_time},#{start_color.r},#{start_color.g},#{start_color.b}" if end_color != start_color command += ",#{end_color.r},#{end_color.g},#{end_color.b}" end @commands << command end |
#fade(start_time:, end_time: start_time, easing: Easing::Linear, start_opacity:, end_opacity: start_opacity) ⇒ Object
Change the opacity of the object (how transparent it is).
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/osb/commandable.rb', line 45 def fade( start_time:, end_time: start_time, easing: Easing::Linear, start_opacity:, end_opacity: start_opacity ) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) Internal.raise_if_invalid_easing!(easing) Internal.assert_type!(start_opacity, Numeric, "start_opacity") Internal.assert_type!(end_opacity, Numeric, "end_opacity") Internal.assert_value!(start_opacity, 0..1, "start_opacity") Internal.assert_value!(end_opacity, 0..1, "end_opacity") end_time = "" if start_time == end_time tabs = " " * self.tab_level command = "#{tabs}F,#{start_time},#{end_time},#{start_opacity}" command += ",#{end_opacity}" if end_opacity != start_opacity @commands << command end |
#flip(start_time:, end_time:, horizontally: true, vertically: false) ⇒ Object
Flip the object horizontally or vertically.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/osb/commandable.rb', line 282 def flip(start_time:, end_time:, horizontally: true, vertically: false) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) Internal.assert_type!(horizontally, Internal::Boolean, "horizontally") Internal.assert_type!(vertically, Internal::Boolean, "vertically") if horizontally && vertically raise InvalidValueError, "Cannot flip an object both horizontally and vertically." end if !horizontally && !vertically raise InvalidValueError, "Specify a direction to flip." end direction = horizontally ? "H" : "V" end_time = "" if start_time == end_time tabs = " " * self.tab_level command = "#{tabs}P,#{start_time},#{end_time},#{direction}" @commands << command end |
#move(start_time:, end_time: start_time, easing: Easing::Linear, start_position:, end_position: start_position) ⇒ Object
Move the object to a new position in the play area.
74 75 76 77 78 79 80 81 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 |
# File 'lib/osb/commandable.rb', line 74 def move( start_time:, end_time: start_time, easing: Easing::Linear, start_position:, end_position: start_position ) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) Internal.raise_if_invalid_easing!(easing) Internal.assert_type!( start_position, [Osb::Vector2, T[Array][Numeric]], "start_position" ) Internal.assert_type!( end_position, [Osb::Vector2, T[Array][Numeric]], "end_position" ) if start_position.is_a?(Array) start_position = Osb::Vector2.new(start_position) end end_position = Osb::Vector2.new(end_position) if end_position.is_a?(Array) end_time = "" if start_time == end_time tabs = " " * self.tab_level command = "#{tabs}M,#{start_time},#{end_time},#{start_position.x},#{start_position.y}" command += ",#{end_position.x},#{end_position.y}" if end_position != start_position @commands << command end |
#move_x(start_time:, end_time: start_time, easing: Easing::Linear, start_x:, end_x: start_x) ⇒ Object
Move the object along the x axis.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/osb/commandable.rb', line 114 def move_x( start_time:, end_time: start_time, easing: Easing::Linear, start_x:, end_x: start_x ) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) Internal.raise_if_invalid_easing!(easing) Internal.assert_type!(start_x, Numeric, "start_x") Internal.assert_type!(end_x, Numeric, "end_x") end_time = "" if start_time == end_time tabs = " " * self.tab_level command = "#{tabs}MX,#{start_time},#{end_time},#{start_x}" command += ",#{end_x}" if end_x @commands << command end |
#move_y(start_time:, end_time: start_time, easing: Easing::Linear, start_y:, end_y: start_y) ⇒ Object
Move the object along the y axis.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/osb/commandable.rb', line 141 def move_y( start_time:, end_time: start_time, easing: Easing::Linear, start_y:, end_y: start_y ) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) if end_time Internal.raise_if_invalid_easing!(easing) Internal.assert_type!(start_y, Numeric, "start_y") Internal.assert_type!(end_y, Numeric, "end_y") end_time = "" if start_time == end_time tabs = " " * self.tab_level command = "#{tabs}MY,#{start_time},#{end_time},#{start_y}" command += ",#{end_y}" if end_y != start_y @commands << command end |
#rotate(start_time:, end_time: start_time, easing: Easing::Linear, start_angle:, end_angle: start_angle) ⇒ Object
Rotate the object around its origin.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/osb/commandable.rb', line 226 def rotate( start_time:, end_time: start_time, easing: Easing::Linear, start_angle:, end_angle: start_angle ) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) Internal.raise_if_invalid_easing!(easing) Internal.assert_type!(start_angle, Numeric, "start_angle") Internal.assert_type!(end_angle, Numeric, "end_angle") end_time = "" if start_time == end_time tabs = " " * self.tab_level command = "#{tabs}R,#{start_time},#{end_time},#{start_angle}" command += ",#{end_angle}" if end_angle != start_angle @commands << command end |
#scale(start_time:, end_time: start_time, easing: Easing::Linear, start_scale:, end_scale: start_scale) ⇒ Object
Change the size of the object relative to its original size. Will scale seperatedly if given Osb::Vector2s or Array<Numeric>s. The scaling is affected by the object’s origin
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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/osb/commandable.rb', line 170 def scale( start_time:, end_time: start_time, easing: Easing::Linear, start_scale:, end_scale: start_scale ) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) if end_time Internal.raise_if_invalid_easing!(easing) Internal.assert_type!( start_scale, [Numeric, T[Array][Numeric], Osb::Vector2], "start_scale" ) Internal.assert_type!( end_scale, [Numeric, T[Array][Numeric], Osb::Vector2], "end_scale" ) end_time = "" if start_time == end_time tabs = " " * self.tab_level if start_scale.is_a?(Numeric) unless end_scale.is_a?(Numeric) raise InvalidValueError, "start_scale and end_scale must be either both Numeric values or Vector2-like values." end command = "#{tabs}S,#{start_time},#{end_time},#{start_scale}" command += ",#{end_scale}" if end_scale != start_scale @commands << command else if end_scale.is_a?(Numeric) raise InvalidValueError, "start_scale and end_scale must be either both Numeric values or Vector2-like values." end start_scale = Osb::Vector2.new(start_scale) if start_scale.is_a?(Array) end_scale = Osb::Vector2.new(end_scale) if end_scale.is_a?(Array) command = "#{tabs}V,#{start_time},#{end_time},#{start_scale.x},#{start_scale.y}" command += ",#{end_scale.x},#{end_scale.y}" if end_scale @commands << command end end |
#trigger(on:, start_time:, end_time:) {|_self| ... } ⇒ Object
Add a group of commands on a specific condition. ‘#trigger` can only be called on an empty object declaration (no commands). Pass a block to this method call to specify which commands to run if the condition is met.
In addition to the “implicit” player feedback via the separate Pass/Fail layers, you can use one of several Trigger conditions to cause a series of events to happen whenever that condition is fulfilled within a certain time period. Note that ‘start_time` and `end_time` of any commands called inside the block become relative to the `start_time` and `end_time` of the `#trigger` command.
While osu! supports trigger on hitsounds playing, we decided to not include it in because it is unreliable/unpredictable.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/osb/commandable.rb', line 341 def trigger(on:, start_time:, end_time:) self.raise_if_trigger_called! Internal.raise_if_invalid_start_time!(start_time) Internal.raise_if_invalid_end_time!(end_time) Internal.assert_type!(on, String, "on") Internal.assert_value!(on, %w[Passing Failing], "on") unless block_given? raise InvalidValueError, "Do not use an empty trigger." end if @commands.size > 1 raise RuntimeError, "Do not call #trigger after any other commands." end if @is_in_trigger raise RuntimeError, "Do not call #trigger inside another #trigger block." end command = " T,#{on},#{start_time},#{end_time}" @commands << command @is_in_trigger = true yield self unless @commands.size > 1 raise InvalidValueError, "Do not use an empty trigger." end @is_in_trigger = false @trigger_called = true end |