Class: WolfRpg::Database::Data
- Inherits:
-
Object
- Object
- WolfRpg::Database::Data
- Defined in:
- lib/wolfrpg/database.rb
Instance Attribute Summary collapse
-
#int_values ⇒ Object
Returns the value of attribute int_values.
-
#name ⇒ Object
Returns the value of attribute name.
-
#string_values ⇒ Object
Returns the value of attribute string_values.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #dump_dat(coder) ⇒ Object
- #dump_project(coder) ⇒ Object
- #each_translatable ⇒ Object
-
#initialize(coder) ⇒ Data
constructor
A new instance of Data.
- #read_dat(coder, fields) ⇒ Object
Constructor Details
#initialize(coder) ⇒ Data
Returns a new instance of Data.
250 251 252 |
# File 'lib/wolfrpg/database.rb', line 250 def initialize(coder) @name = coder.read_string end |
Instance Attribute Details
#int_values ⇒ Object
Returns the value of attribute int_values.
247 248 249 |
# File 'lib/wolfrpg/database.rb', line 247 def int_values @int_values end |
#name ⇒ Object
Returns the value of attribute name.
246 247 248 |
# File 'lib/wolfrpg/database.rb', line 246 def name @name end |
#string_values ⇒ Object
Returns the value of attribute string_values.
248 249 250 |
# File 'lib/wolfrpg/database.rb', line 248 def string_values @string_values end |
Instance Method Details
#[](key) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/wolfrpg/database.rb', line 280 def [](key) if key.is_a? Field if key.string? @string_values[key.index] else @int_values[key.index] end elsif value.is_a? Integer self[@fields[key]] else raise "Data[] takes a Field, got a #{value.class}" end end |
#[]=(key, value) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/wolfrpg/database.rb', line 294 def []=(key, value) if key.is_a? Field if key.string? @string_values[key.index] = value else @int_values[key.index] = value end elsif value.is_a? Integer self[@fields[key]] = value else raise "Data[] takes a Field, got a #{value.class}" end end |
#dump_dat(coder) ⇒ Object
271 272 273 274 275 276 277 278 |
# File 'lib/wolfrpg/database.rb', line 271 def dump_dat(coder) @int_values.each do |i| coder.write_int(i) end @string_values.each do |i| coder.write_string(i) end end |
#dump_project(coder) ⇒ Object
254 255 256 |
# File 'lib/wolfrpg/database.rb', line 254 def dump_project(coder) coder.write_string(@name) end |
#each_translatable ⇒ Object
308 309 310 311 312 313 314 |
# File 'lib/wolfrpg/database.rb', line 308 def each_translatable @fields.each do |field| next unless field.string? && field.type == 0 value = self[field] yield [value, field] unless value.empty? || value.include?("\n") end end |
#read_dat(coder, fields) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/wolfrpg/database.rb', line 258 def read_dat(coder, fields) @fields = fields @int_values = Array.new(fields.select(&:int?).size) @string_values = Array.new(fields.select(&:string?).size) @int_values.each_index do |i| @int_values[i] = coder.read_int end @string_values.each_index do |i| @string_values[i] = coder.read_string end end |