#==============================================================================
# ** Game_GlobSwitches
#==============================================================================
# @author RyanBern
# @date 2017.11.03
# @license (RBLv1)[[url]https://rpg.blue/forum.php?mod=viewthread&tid=403387[/url]]
#------------------------------------------------------------------------------
# This class handles global switches.
# Refer to "$game_glob_switches" for the instance of this class.
#------------------------------------------------------------------------------
# 用法:插入到 Main 前,所有脚本之后即可使用,无需额外设置。下面的两个设置
# 区域根据需求自行改变。
# 用全局变量 $game_glob_switches 表示所有全局开关,例如,读取 1 号全局
# 开关请使用:$game_glob_switches[1]
# 写入请使用:$game_glob_switches[1] = true
# 注意:在事件脚本中如果要写入,请在最后一行随便写点注释,否则游戏会卡死(RGSS
# 的 BUG)
#==============================================================================
class Game_GlobSwitches
#--------------------------------------------------------------------------
# * Constants
#--------------------------------------------------------------------------
FileName = "Global.rxdata" # 全局开关文件名
Autosave = false # 全局开关改变时是否自动存档
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get Switch
# switch_id : switch ID
#--------------------------------------------------------------------------
def [](switch_id)
@data[switch_id] == nil ? false : @data[switch_id]
end
#--------------------------------------------------------------------------
# * Set Switch
# switch_id : switch ID
# value : ON (true) / OFF (false)
#--------------------------------------------------------------------------
def []=(switch_id, value)
@data[switch_id] = value
save_glob_data if Autosave
end
#--------------------------------------------------------------------------
# * Class methods
#--------------------------------------------------------------------------
def self.save_glob_data
filename = FileName
file = File.open(filename, "wb")
Marshal.dump($game_glob_switches, file)
file.close
end
def self.load_glob_data
filename = FileName
# check if the file exists
if File.exist?(filename)
file = File.open(filename, "rb")
$game_glob_switches = Marshal.load(file)
file.close
else
$game_glob_switches = Game_GlobSwitches.new
save_glob_data
end
end
end
#==============================================================================
# ** Plug into Game_System and Interperter
#==============================================================================
class Game_System
alias rb_initialize_20171103 initialize
def initialize
rb_initialize_20171103
Game_GlobSwitches.load_glob_data
end
end
class Interpreter
def save_glob_data; Game_GlobSwitches.save_glob_data; end;
def load_glob_data; Game_GlobSwitches.load_glob_data; end;
end