Module: DataManager

Defined in:
DataManager.rb

Overview

** DataManager


This module manages the database and game objects. Almost all of the

global variables used by the game are initialized by this module.

Class Method Summary (collapse)

Class Method Details

+ (Object) check_player_location


  • Check Player Start Location Existence




73
74
75
76
77
78
# File 'DataManager.rb', line 73

def self.check_player_location
  if $data_system.start_map_id == 0
    msgbox(Vocab::PlayerPosError)
    exit
  end
end

+ (Object) create_game_objects


  • Create Game Objects




82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'DataManager.rb', line 82

def self.create_game_objects
  $game_temp          = Game_Temp.new
  $game_system        = Game_System.new
  $game_timer         = Game_Timer.new
  $game_message       = Game_Message.new
  $game_switches      = Game_Switches.new
  $game_variables     = Game_Variables.new
  $game_self_switches = Game_SelfSwitches.new
  $game_actors        = Game_Actors.new
  $game_party         = Game_Party.new
  $game_troop         = Game_Troop.new
  $game_map           = Game_Map.new
  $game_player        = Game_Player.new
end

+ (Object) delete_save_file(index)


  • Delete Save File




193
194
195
# File 'DataManager.rb', line 193

def self.delete_save_file(index)
  File.delete(make_filename(index)) rescue nil
end

+ (Object) extract_save_contents(contents)


  • Extract Save Contents




226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'DataManager.rb', line 226

def self.extract_save_contents(contents)
  $game_system        = contents[:system]
  $game_timer         = contents[:timer]
  $game_message       = contents[:message]
  $game_switches      = contents[:switches]
  $game_variables     = contents[:variables]
  $game_self_switches = contents[:self_switches]
  $game_actors        = contents[:actors]
  $game_party         = contents[:party]
  $game_troop         = contents[:troop]
  $game_map           = contents[:map]
  $game_player        = contents[:player]
end

+ (Object) init


  • Initialize Module




16
17
18
19
20
21
# File 'DataManager.rb', line 16

def self.init
  @last_savefile_index = 0
  load_database
  create_game_objects
  setup_battle_test if $BTEST
end

+ (Object) last_savefile_index


  • Get Index of File Most Recently Accessed




264
265
266
# File 'DataManager.rb', line 264

def self.last_savefile_index
  @last_savefile_index
end

+ (Object) latest_savefile_index


  • Get File Index with Latest Update Date




258
259
260
# File 'DataManager.rb', line 258

def self.latest_savefile_index
  savefile_max.times.max_by {|i| savefile_time_stamp(i) }
end

+ (Object) load_battle_test_database


  • Load Battle Test Database




55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'DataManager.rb', line 55

def self.load_battle_test_database
  $data_actors        = load_data("Data/BT_Actors.rvdata2")
  $data_classes       = load_data("Data/BT_Classes.rvdata2")
  $data_skills        = load_data("Data/BT_Skills.rvdata2")
  $data_items         = load_data("Data/BT_Items.rvdata2")
  $data_weapons       = load_data("Data/BT_Weapons.rvdata2")
  $data_armors        = load_data("Data/BT_Armors.rvdata2")
  $data_enemies       = load_data("Data/BT_Enemies.rvdata2")
  $data_troops        = load_data("Data/BT_Troops.rvdata2")
  $data_states        = load_data("Data/BT_States.rvdata2")
  $data_animations    = load_data("Data/BT_Animations.rvdata2")
  $data_tilesets      = load_data("Data/BT_Tilesets.rvdata2")
  $data_common_events = load_data("Data/BT_CommonEvents.rvdata2")
  $data_system        = load_data("Data/BT_System.rvdata2")
end

+ (Object) load_database


  • Load Database




25
26
27
28
29
30
31
32
# File 'DataManager.rb', line 25

def self.load_database
  if $BTEST
    load_battle_test_database
  else
    load_normal_database
    check_player_location
  end
end

+ (Object) load_game(index)


  • Execute Load




148
149
150
# File 'DataManager.rb', line 148

def self.load_game(index)
  load_game_without_rescue(index) rescue false
end

+ (Object) load_game_without_rescue(index)


  • Execute Load (No Exception Processing)




172
173
174
175
176
177
178
179
180
# File 'DataManager.rb', line 172

def self.load_game_without_rescue(index)
  File.open(make_filename(index), "rb") do |file|
    Marshal.load(file)
    extract_save_contents(Marshal.load(file))
    reload_map_if_updated
    @last_savefile_index = index
  end
  return true
end

+ (Object) load_header(index)


  • Load Save Header




154
155
156
# File 'DataManager.rb', line 154

def self.load_header(index)
  load_header_without_rescue(index) rescue nil
end

+ (Object) load_header_without_rescue(index)


  • Load Save Header (No Exception Processing)




184
185
186
187
188
189
# File 'DataManager.rb', line 184

def self.load_header_without_rescue(index)
  File.open(make_filename(index), "rb") do |file|
    return Marshal.load(file)
  end
  return nil
end

+ (Object) load_normal_database


  • Load Normal Database




36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'DataManager.rb', line 36

def self.load_normal_database
  $data_actors        = load_data("Data/Actors.rvdata2")
  $data_classes       = load_data("Data/Classes.rvdata2")
  $data_skills        = load_data("Data/Skills.rvdata2")
  $data_items         = load_data("Data/Items.rvdata2")
  $data_weapons       = load_data("Data/Weapons.rvdata2")
  $data_armors        = load_data("Data/Armors.rvdata2")
  $data_enemies       = load_data("Data/Enemies.rvdata2")
  $data_troops        = load_data("Data/Troops.rvdata2")
  $data_states        = load_data("Data/States.rvdata2")
  $data_animations    = load_data("Data/Animations.rvdata2")
  $data_tilesets      = load_data("Data/Tilesets.rvdata2")
  $data_common_events = load_data("Data/CommonEvents.rvdata2")
  $data_system        = load_data("Data/System.rvdata2")
  $data_mapinfos      = load_data("Data/MapInfos.rvdata2")
end

+ (Object) make_filename(index)


  • Create Filename

    index : File Index



131
132
133
# File 'DataManager.rb', line 131

def self.make_filename(index)
  sprintf("Save%02d.rvdata2", index + 1)
end

+ (Object) make_save_contents


  • Create Save Contents




208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'DataManager.rb', line 208

def self.make_save_contents
  contents = {}
  contents[:system]        = $game_system
  contents[:timer]         = $game_timer
  contents[:message]       = $game_message
  contents[:switches]      = $game_switches
  contents[:variables]     = $game_variables
  contents[:self_switches] = $game_self_switches
  contents[:actors]        = $game_actors
  contents[:party]         = $game_party
  contents[:troop]         = $game_troop
  contents[:map]           = $game_map
  contents[:player]        = $game_player
  contents
end

+ (Object) make_save_header


  • Create Save Header




199
200
201
202
203
204
# File 'DataManager.rb', line 199

def self.make_save_header
  header = {}
  header[:characters] = $game_party.characters_for_savefile
  header[:playtime_s] = $game_system.playtime_s
  header
end

+ (Object) reload_map_if_updated


  • Reload Map if Data Is Updated




242
243
244
245
246
247
248
# File 'DataManager.rb', line 242

def self.reload_map_if_updated
  if $game_system.version_id != $data_system.version_id
    $game_map.setup($game_map.map_id)
    $game_player.center($game_player.x, $game_player.y)
    $game_player.make_encounter_count
  end
end

+ (Boolean) save_file_exists?


  • Determine Existence of Save File


Returns:

  • (Boolean)


118
119
120
# File 'DataManager.rb', line 118

def self.save_file_exists?
  !Dir.glob('Save*.rvdata2').empty?
end

+ (Object) save_game(index)


  • Execute Save




137
138
139
140
141
142
143
144
# File 'DataManager.rb', line 137

def self.save_game(index)
  begin
    save_game_without_rescue(index)
  rescue
    delete_save_file(index)
    false
  end
end

+ (Object) save_game_without_rescue(index)


  • Execute Save (No Exception Processing)




160
161
162
163
164
165
166
167
168
# File 'DataManager.rb', line 160

def self.save_game_without_rescue(index)
  File.open(make_filename(index), "wb") do |file|
    $game_system.on_before_save
    Marshal.dump(make_save_header, file)
    Marshal.dump(make_save_contents, file)
    @last_savefile_index = index
  end
  return true
end

+ (Object) savefile_max


  • Maximum Number of Save Files




124
125
126
# File 'DataManager.rb', line 124

def self.savefile_max
  return 16
end

+ (Object) savefile_time_stamp(index)


  • Get Update Date of Save File




252
253
254
# File 'DataManager.rb', line 252

def self.savefile_time_stamp(index)
  File.mtime(make_filename(index)) rescue Time.at(0)
end

+ (Object) setup_battle_test


  • Set Up Battle Test




110
111
112
113
114
# File 'DataManager.rb', line 110

def self.setup_battle_test
  $game_party.setup_battle_test
  BattleManager.setup($data_system.test_troop_id)
  BattleManager.play_battle_bgm
end

+ (Object) setup_new_game


  • Set Up New Game




99
100
101
102
103
104
105
106
# File 'DataManager.rb', line 99

def self.setup_new_game
  create_game_objects
  $game_party.setup_starting_members
  $game_map.setup($data_system.start_map_id)
  $game_player.moveto($data_system.start_x, $data_system.start_y)
  $game_player.refresh
  Graphics.frame_count = 0
end