Class: RubyGS::SaveFile

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_gs/save_file_reader.rb

Overview

Represents a Gold/Silver/Crystal save file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(save, filename, gs) ⇒ SaveFile

Returns a new instance of SaveFile.



60
61
62
# File 'lib/ruby_gs/save_file_reader.rb', line 60

def initialize save, filename, gs
  @save, @gs, @filename = save, gs, filename
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



106
107
108
# File 'lib/ruby_gs/save_file_reader.rb', line 106

def method_missing(sym, *args, &block)
  @save.send(sym, *args, &block)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



58
59
60
# File 'lib/ruby_gs/save_file_reader.rb', line 58

def filename
  @filename
end

#gsObject (readonly)

Returns the value of attribute gs.



58
59
60
# File 'lib/ruby_gs/save_file_reader.rb', line 58

def gs
  @gs
end

#saveObject

Returns the value of attribute save.



57
58
59
# File 'lib/ruby_gs/save_file_reader.rb', line 57

def save
  @save
end

Instance Method Details

#hatch_team_egg(slot) ⇒ Object

A convenience method for turning an Egg into a Pokemon.



100
101
102
103
104
# File 'lib/ruby_gs/save_file_reader.rb', line 100

def hatch_team_egg slot
  raise "slot index must be between 0 and 5, inclusive" if !(0..5).include? slot
  @save.team.species_list[slot].assign  @save.team.pokemon[slot].species
  @save.team.pokemon[slot].happiness = 20
end

#set_team_egg(slot, egg_cycles) ⇒ Object

A convenience method for turning a PartyPokemon into an Egg and setting the steps required to hatch it.



92
93
94
95
96
# File 'lib/ruby_gs/save_file_reader.rb', line 92

def set_team_egg slot, egg_cycles
  raise "slot index must be between 0 and 5, inclusive" if !(0..5).include? slot
  @save.team.species_list[slot] = 0xFD
  @save.team.pokemon[slot].happiness = egg_cycles
end

#set_team_species(slot, species) ⇒ Object

A convenience method for setting the species of a PartyPokemon in its structure and in the Team species_list.



84
85
86
87
88
# File 'lib/ruby_gs/save_file_reader.rb', line 84

def set_team_species slot, species
  return if !(0..5).include? slot
  @save.team.pokemon[slot].species.assign species
  @save.team.species_list[slot].assign species
end

#verify_checksumsObject



64
65
66
67
68
69
70
71
# File 'lib/ruby_gs/save_file_reader.rb', line 64

def verify_checksums
  case gs
  when true
    return verify_gs_checksums
  when false
    return verify_c_checksums
  end 
end

#write(loc = @filename) ⇒ Object

Writes the save structure to file.

If loc is not provided, it will write directly to the original file.



77
78
79
80
# File 'lib/ruby_gs/save_file_reader.rb', line 77

def write(loc = @filename)
  @save.write(File.open(loc, "wb"))
  verify_checksums
end