#==============================================================================
#                      「セーブスロット固定」(ACE) Ver.1.0
#   製作者:奈々(なな)
#   へぷたなすくろーる http://heptanas.mamagoto.com/
#
#   ◇使用規約
#   使用される場合はスクリプト作成者として「奈々」を明記して下さい。
#   スクリプトの改変は自由に行って頂いて構いませんが
#   その場合も元のスクリプトの作成者として名前を載せて下さい。
#   また配布前に必ず、ブログにある利用規約を確認して下さい。
#
#------------------------------------------------------------------------------
#   
#   ゲーム開始時にセーブスロットを選択します。
#   以降、セーブ画面では選択したスロットへの上書きセーブしか行えません。
#   またセーブスロット数の変更とオートセーブを実装します。
#   
#   使い方は、イベントコマンドのスクリプトで以下を入力します。
#   
#   n7_auto_save        オートセーブを行います。
#   n7_manual_save      セーブスロットを選択するセーブを行います。
#   
#==============================================================================
#   ◇初期設定
module Nana
module Fixed_Save_Slot
  
  #セーブスロットの数を指定します。
  Max = 4

  #通常セーブ時のメッセージを指定します。
  SaveMessage = "セーブしますか?"

end
end
#   ↑ここまで
#==============================================================================

#==============================================================================
# ■ Game_Interpreter
#------------------------------------------------------------------------------
#  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、
# Game_Troop クラス、Game_Event クラスの内部で使用されます。
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # ● オートセーブ
  #--------------------------------------------------------------------------
  def n7_auto_save
    unless DataManager.save_game($game_system.save_slot)
      p "オートセーブに失敗しました。"
    end
  end
  #--------------------------------------------------------------------------
  # ● 手動セーブ
  #--------------------------------------------------------------------------
  def n7_manual_save
    SceneManager.call(Scene_Starting_Save)
    Fiber.yield
  end
end
#==============================================================================
# ■ Game_System
#------------------------------------------------------------------------------
#  システム周りのデータを扱うクラスです。セーブやメニューの禁止状態などを保存
# します。このクラスのインスタンスは $game_system で参照されます。
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :save_slot                # セーブスロット
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  alias n7_fss_initialize initialize
  def initialize
    n7_fss_initialize
    @save_slot = 0
  end
end

#==============================================================================
# ■ DataManager
#------------------------------------------------------------------------------
#  データベースとゲームオブジェクトを管理するモジュールです。ゲームで使用する
# ほぼ全てのグローバル変数はこのモジュールで初期化されます。
#==============================================================================

module DataManager
  #--------------------------------------------------------------------------
  # ● セーブファイルの最大数
  #--------------------------------------------------------------------------
  def self.savefile_max
    return Nana::Fixed_Save_Slot::Max
  end
end

#==============================================================================
# ■ Scene_Save
#------------------------------------------------------------------------------
#  セーブ画面の処理を行うクラスです。
#==============================================================================

class Scene_Save < Scene_File
  #--------------------------------------------------------------------------
  # ● ヘルプウィンドウのテキストを取得
  #--------------------------------------------------------------------------
  def help_window_text
    Nana::Fixed_Save_Slot::SaveMessage
  end
  #--------------------------------------------------------------------------
  # ● 最初に選択状態にするファイルインデックスを取得
  #--------------------------------------------------------------------------
  def first_savefile_index
    $game_system.save_slot
  end
  #--------------------------------------------------------------------------
  # ● カーソルの更新
  #--------------------------------------------------------------------------
  def update_cursor
  end
end

#==============================================================================
# ■ Scene_Starting_Save
#------------------------------------------------------------------------------
#  ゲーム開始時に行うセーブ画面の処理を行うクラスです。
#==============================================================================

class Scene_Starting_Save < Scene_File
  #--------------------------------------------------------------------------
  # ● ヘルプウィンドウのテキストを取得
  #--------------------------------------------------------------------------
  def help_window_text
    Vocab::SaveMessage
  end
  #--------------------------------------------------------------------------
  # ● 最初に選択状態にするファイルインデックスを取得
  #--------------------------------------------------------------------------
  def first_savefile_index
    DataManager.last_savefile_index
  end
  #--------------------------------------------------------------------------
  # ● セーブファイルの決定
  #--------------------------------------------------------------------------
  def on_savefile_ok
    super
    if DataManager.save_game(@index)
      on_save_success
    else
      Sound.play_buzzer
    end
  end
  #--------------------------------------------------------------------------
  # ● セーブ成功時の処理
  #--------------------------------------------------------------------------
  def on_save_success
    $game_system.save_slot = @index
    Sound.play_save
    return_scene
  end
  #--------------------------------------------------------------------------
  # ● セーブファイル[キャンセル]
  #--------------------------------------------------------------------------
  def on_savefile_cancel
    Sound.play_cancel
    SceneManager.goto(Scene_Title)
  end
end

#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  タイトル画面の処理を行うクラスです。
#==============================================================================

class Scene_Title < Scene_Base
  #--------------------------------------------------------------------------
  # ● コマンド[ニューゲーム]
  #--------------------------------------------------------------------------
  alias n7_fss_command_new_game command_new_game
  def command_new_game
    n7_fss_command_new_game
    SceneManager.call(Scene_Starting_Save)
  end
end