Class: Osu::DB::Beatmap

Inherits:
Object
  • Object
show all
Defined in:
lib/osu-db/beatmap.rb

Overview

Structure of osu!.db

  • str[rdoc-ref:StringIO#read_str] #artist, #artist_unicode, #title, #title_unicode, #creator, #version: metadata section in .osu

  • str[rdoc-ref:StringIO#read_str] #audio_filename: general section in .osu

  • str[rdoc-ref:StringIO#read_str] #beatmapcode: digest of Beatmap

  • str[rdoc-ref:StringIO#read_str] #osu_filename:

  • int[rdoc-ref:StringIO#read_int] #type: see BeatmapType

  • int[rdoc-ref:StringIO#read_int] #circles, #sliders, #spinners: the number of circles, sliders and spinners

  • time[rdoc-ref:StringIO#read_time] #last_edit:

  • int[rdoc-ref:StringIO#read_int] #approach_rate, #circle_size, #hp_drain_rate, #overall_difficulty: difficulty section in .osu

  • double[rdoc-ref:StringIO#read_double] #slider_multiplier: difficulty section in .osu

  • int[rdoc-ref:StringIO#read_int] #draining_time: or play time, in second

  • int[rdoc-ref:StringIO#read_int] #total_time: the offset of the last hit object, in millisecond

  • int[rdoc-ref:StringIO#read_int] #preview_time: general section in .osu, in millisecond

  • TimingPoint #timing_points: timing points section in .osu

  • int[rdoc-ref:StringIO#read_int] #beatmapid, #beatmapsetid, #threadid: metadata section in .osu

  • int[rdoc-ref:StringIO#read_int] #ratings: user ratings for different GameMode

  • int[rdoc-ref:StringIO#read_int] #your_offset:

  • float[rdoc-ref:StringIO#read_float] #stack_leniency: general section in .osu

  • int[rdoc-ref:StringIO#read_int] #mode: see GameMode

  • str[rdoc-ref:StringIO#read_str] #source, #tags: metadata section in .osu

  • str[rdoc-ref:StringIO#read_int] #online_offset:

  • str[rdoc-ref:StringIO#read_str] #letterbox: general section in .osu

  • bool[rdoc-ref:StringIO#read_bool] #played?:

  • time[rdoc-ref:StringIO#read_time] #last_play:

  • 0

  • str[rdoc-ref:StringIO#read_str] #path: beatmap directory

  • time[rdoc-ref:StringIO#read_time] #last_sync:

  • bool[rdoc-ref:StringIO#read_bool] #ignore_hitsound?, #ignore_skin?, #disable_storyboard?: visual settings

  • int[rdoc-ref:StringIO#read_int] #background_dim: visual settings

  • 0

  • unknown

  • _0|7_

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ios = nil) ⇒ Beatmap

Returns a new instance of Beatmap.



78
79
80
# File 'lib/osu-db/beatmap.rb', line 78

def initialize(ios = nil)
  load(ios) if ios
end

Instance Attribute Details

#approach_rateObject (readonly)

Returns the value of attribute approach_rate.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def approach_rate
  @approach_rate
end

#artistObject (readonly)

Returns the value of attribute artist.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def artist
  @artist
end

#artist_unicodeObject (readonly)

Returns the value of attribute artist_unicode.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def artist_unicode
  @artist_unicode
end

#audio_filenameObject (readonly)

Returns the value of attribute audio_filename.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def audio_filename
  @audio_filename
end

#background_dimObject (readonly)

Returns the value of attribute background_dim.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def background_dim
  @background_dim
end

#beatmapcodeObject (readonly)

Returns the value of attribute beatmapcode.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def beatmapcode
  @beatmapcode
end

#beatmapidObject (readonly)

Returns the value of attribute beatmapid.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def beatmapid
  @beatmapid
end

#beatmapsetidObject (readonly)

Returns the value of attribute beatmapsetid.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def beatmapsetid
  @beatmapsetid
end

#circle_sizeObject (readonly)

Returns the value of attribute circle_size.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def circle_size
  @circle_size
end

#circlesObject (readonly)

Returns the value of attribute circles.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def circles
  @circles
end

#creatorObject (readonly)

Returns the value of attribute creator.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def creator
  @creator
end

#disable_storyboardObject (readonly) Also known as: disable_storyboard?

Returns the value of attribute disable_storyboard.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def disable_storyboard
  @disable_storyboard
end

#draining_timeObject (readonly)

Returns the value of attribute draining_time.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def draining_time
  @draining_time
end

#hp_drain_rateObject (readonly)

Returns the value of attribute hp_drain_rate.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def hp_drain_rate
  @hp_drain_rate
end

#ignore_hitsoundObject (readonly) Also known as: ignore_hitsound?

Returns the value of attribute ignore_hitsound.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def ignore_hitsound
  @ignore_hitsound
end

#ignore_skinObject (readonly) Also known as: ignore_skin?

Returns the value of attribute ignore_skin.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def ignore_skin
  @ignore_skin
end

#int1Object (readonly)

Returns the value of attribute int1.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def int1
  @int1
end

#int2Object (readonly)

Returns the value of attribute int2.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def int2
  @int2
end

#last_editObject (readonly)

Returns the value of attribute last_edit.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def last_edit
  @last_edit
end

#last_playObject (readonly)

Returns the value of attribute last_play.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def last_play
  @last_play
end

#last_syncObject (readonly)

Returns the value of attribute last_sync.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def last_sync
  @last_sync
end

#letterboxObject (readonly)

Returns the value of attribute letterbox.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def letterbox
  @letterbox
end

#modeObject (readonly)

Returns the value of attribute mode.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def mode
  @mode
end

#online_offsetObject (readonly)

Returns the value of attribute online_offset.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def online_offset
  @online_offset
end

#osu_filenameObject (readonly)

Returns the value of attribute osu_filename.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def osu_filename
  @osu_filename
end

#overall_difficultyObject (readonly)

Returns the value of attribute overall_difficulty.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def overall_difficulty
  @overall_difficulty
end

#pathObject (readonly)

Returns the value of attribute path.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def path
  @path
end

#playedObject (readonly) Also known as: played?

Returns the value of attribute played.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def played
  @played
end

#preview_timeObject (readonly)

Returns the value of attribute preview_time.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def preview_time
  @preview_time
end

#ratingsObject (readonly)

Returns the value of attribute ratings.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def ratings
  @ratings
end

#slider_multiplierObject (readonly)

Returns the value of attribute slider_multiplier.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def slider_multiplier
  @slider_multiplier
end

#slidersObject (readonly)

Returns the value of attribute sliders.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def sliders
  @sliders
end

#sourceObject (readonly)

Returns the value of attribute source.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def source
  @source
end

#spinnersObject (readonly)

Returns the value of attribute spinners.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def spinners
  @spinners
end

#stack_leniencyObject (readonly)

Returns the value of attribute stack_leniency.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def stack_leniency
  @stack_leniency
end

#tagsObject (readonly)

Returns the value of attribute tags.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def tags
  @tags
end

#threadidObject (readonly)

Returns the value of attribute threadid.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def threadid
  @threadid
end

#timing_pointsObject (readonly)

Returns the value of attribute timing_points.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def timing_points
  @timing_points
end

#titleObject (readonly)

Returns the value of attribute title.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def title
  @title
end

#title_unicodeObject (readonly)

Returns the value of attribute title_unicode.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def title_unicode
  @title_unicode
end

#total_timeObject (readonly)

Returns the value of attribute total_time.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def total_time
  @total_time
end

#typeObject (readonly)

Returns the value of attribute type.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def version
  @version
end

#your_offsetObject (readonly)

Returns the value of attribute your_offset.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def your_offset
  @your_offset
end

#zero1Object (readonly)

Returns the value of attribute zero1.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def zero1
  @zero1
end

#zero2Object (readonly)

Returns the value of attribute zero2.



60
61
62
# File 'lib/osu-db/beatmap.rb', line 60

def zero2
  @zero2
end

Instance Method Details

#audio_pathObject



82
83
84
# File 'lib/osu-db/beatmap.rb', line 82

def audio_path
  "#{path}\\#{audio_filename}".gsub('\\', File::SEPARATOR)
end

#beatmap_urlObject



90
91
92
# File 'lib/osu-db/beatmap.rb', line 90

def beatmap_url
  "http://osu.ppy.sh/b/#{beatmapid}"
end

#beatmapset_urlObject



94
95
96
# File 'lib/osu-db/beatmap.rb', line 94

def beatmapset_url
  "http://osu.ppy.sh/s/#{beatmapsetid}"
end

#load(ios) ⇒ Object



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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/osu-db/beatmap.rb', line 102

def load(ios)
  @artist         = ios.read_str
  @artist_unicode = ios.read_str
  @title          = ios.read_str
  @title_unicode  = ios.read_str
  @creator        = ios.read_str
  @version        = ios.read_str
  @audio_filename = ios.read_str
  @beatmapcode    = ios.read_str
  @osu_filename   = ios.read_str

  @type = BeatmapType[ios.read_int 1]
  @circles, @sliders, @spinners = *ios.unpack(6, 'v*')
  @last_edit = ios.read_time
  # approach_rate(??) might be different from that in .osu
  @approach_rate, @circle_size, @hp_drain_rate, @overall_difficulty =
    *ios.unpack(4, 'C*')
  @slider_multiplier = ios.read_double
  @draining_time, @total_time, @preview_time = *ios.unpack(12, 'V*')
  # PreviewTime: -1
  @preview_time = nil if @preview_time == 0xFFFFFFFF

  n = ios.read_int 4
  @timing_points = Array.new(n) do
    bpm = ios.read_double
    offset = ios.read_double
    type = ios.read_bool
    (type ? RegularTimingPoint : InheritedTimingPoint).new(offset, bpm)
  end

  @beatmapid      = ios.read_int 4
  @beatmapsetid   = ios.read_int 4
  @threadid       = ios.read_int 4
  @ratings        = ios.unpack(4, 'C*')
  @your_offset    = ios.read_signed_int 2
  @stack_leniency = ios.read_float
  @mode           = GameMode[ios.read_int 1]
  @source         = ios.read_str
  @tags           = ios.read_str
  @online_offset  = ios.read_signed_int 2


  @letterbox = ios.read_str

  @played    = !ios.read_bool
  @last_play = ios.read_time
  # if !@played && @last_play != nil
  #   raise DBCorruptError, "played=%s doesn't match last_play=%s" %
  #     [@played, @last_play].map{|i| i.inspect}
  # end

  @zero1     = ios.read_int 1           # TODO: =0
  raise if @zero1 != 0
  @path      = ios.read_str
  @last_sync = ios.read_time

  @ignore_hitsound    = ios.read_bool
  @ignore_skin        = ios.read_bool
  @disable_storyboard = ios.read_bool
  @background_dim     = ios.read_int 1
  # @disable_video is not saved

  @zero2     = ios.read_int 1           # TODO: =0
  raise if @zero2 != 0
  @int1      = ios.read_int 4           # TODO: almost=0
  @int2      = ios.read_int 1           # TODO: almost=0, otherwise=7
  raise unless @int2 == 0 || @int2 == 7 # 0 iff original mode only
end

#osu_pathObject



86
87
88
# File 'lib/osu-db/beatmap.rb', line 86

def osu_path
  "#{path}\\#{osu_filename}".gsub('\\', File::SEPARATOR)
end

#thread_urlObject



98
99
100
# File 'lib/osu-db/beatmap.rb', line 98

def thread_url
  "http://osu.ppy.sh/forum/t/#{threadid}"
end