赞 | 3 |
VIP | 0 |
好人卡 | 39 |
积分 | 1 |
经验 | 101436 |
最后登录 | 2017-9-1 |
在线时间 | 2276 小时 |
Lv1.梦旅人 路人党员
- 梦石
- 0
- 星屑
- 52
- 在线时间
- 2276 小时
- 注册时间
- 2010-12-30
- 帖子
- 3225
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 英顺的马甲 于 2011-4-25 16:37 编辑
首发地址:http://www.our-story.tk/read.php?tid=64
用法与File相似
比如说将变量存进aaa.txt- #储存部分
- f = FWrite.open("aaa.txt",true)
- f.save(123)
- f.save(456)
- f.save(789)
- f.close
- # 读取部分
- f = FWrite.open("aaa.txt",true)
- p f.load,f.load,f.load # => 123,456,789
- f.close
复制代码 脚本:- module FWrite
- class Text
- def initialize(file,b)
- @file = file
- @b = b
- @pos_save = 0
- @pos_load = 0
- end
- def save(obj)
- defl = Zlib::Deflate.new
- if @pos_save == 0
- File.open(@file,"wb"){ |f|
- f.write(defl.deflate(Marshal.dump([obj]),4))
- }
- @pos_save += 1 if @b
- else
- obj2 = nil
- inf = Zlib::Inflate.new
- File.open(@file,"rb"){|f|
- obj2 = inf.inflate(f.read)
- inf.finish
- }
- obj2 = Marshal.load(obj2)
- obj2.push(obj)
- File.open(@file,"wb"){ |f|
- f.write(defl.deflate(Marshal.dump(obj2),4))
- }
- @pos_save += 1
- end
- end
- def load
- inf = Zlib::Inflate.new
- if @pos_load == 0
- obj = nil
- File.open(@file,"rb"){|f|
- obj = inf.inflate(f.read)
- inf.finish
- }
- obj = Marshal.load(obj)
- @pos_load += 1 if @b
- return obj[0]
- else
- obj = nil
- File.open(@file,"rb"){|f|
- obj = inf.inflate(f.read)
- inf.finish
- }
- obj = Marshal.load(obj)
- @pos_load += 1
- return obj[@pos_load - 1]
- end
- end
- def close
- @file = nil
- @b = false
- @pos_save = 0
- @pos_load = 0
- end
- end
- def self.open(file,b = false)
- return Text.new(file,b)
- end
- end
复制代码 注意:
不支持FWrite.open("aaa.txt",true){|f|f.load}写法
存档脚本修改:- class Scene_Save < Scene_File
- def write_save_data(file)
- characters = []
- for i in 0...$game_party.actors.size
- actor = $game_party.actors[i]
- characters.push([actor.character_name, actor.character_hue])
- end
- f = FRwrite.open(make_filename(@file_index),true)
- f.save(characters)
- f.save(Graphics.frame_count)
- $game_system.save_count += 1
- $game_system.magic_number = $data_system.magic_number
- f.save($game_system)
- f.save($game_switches)
- f.save($game_variables)
- f.save($game_self_switches)
- f.save($game_screen)
- f.save($game_actors)
- f.save($game_party)
- f.save($game_troop)
- f.save($game_map)
- f.save($game_player)
- f.close
- end
- end
- class Scene_Load < Scene_File
- def read_save_data(file)
- f = FRwrite.open(make_filename(@file_index),true)
- Graphics.frame_count = f.load
- $game_system = f.load
- $game_switches = f.load
- $game_variables = f.load
- $game_self_switches = f.load
- $game_screen = f.load
- $game_actors = f.load
- $game_party = f.load
- $game_troop = f.load
- $game_map = f.load
- $game_player = f.load
- f.close
- if $game_system.magic_number != $data_system.magic_number
- $game_map.setup($game_map.map_id)
- $game_player.center($game_player.x, $game_player.y)
- end
- $game_party.refresh
- end
- end
- class Window_SaveFile < Window_Base
- def initialize(file_index, filename)
- super(0, 64 + file_index % 4 * 104, 640, 104)
- self.contents = Bitmap.new(width - 32, height - 32)
- @file_index = file_index
- @filename = "Save#{@file_index + 1}.rxdata"
- @time_stamp = Time.at(0)
- @file_exist = FileTest.exist?(@filename)
- if @file_exist
- file = FWrite.open(@filename, true)
- @time_stamp = file.mtime
- @characters = f.load(file)
- @frame_count = f.load(file)
- @game_system = f.load(file)
- @game_switches = f.load(file)
- @game_variables = f.load(file)
- @total_sec = @frame_count / Graphics.frame_rate
- file.close
- end
- refresh
- @selected = false
- end
- end
复制代码 正努力将此脚本与Base64字符串加密算法结合加密,由于"/000"的关系无法结合,头疼当中。。。 |
|