注册会员 登录
Project1 返回首页

未知循环 https://rpg.blue/?2631579 [收藏] [复制] [分享] [RSS]

日志

保存变量到配置文件

已有 727 次阅读2016-3-4 12:37 |个人分类:事件| 变量

/*:
 * @plugindesc 保存一些变量到游戏项目的配置文件
 * @author 夏末渐离
 * @help
 * 1.为变量赋值
 * 2.缓存变量的值,插件指令Push 变量序号
 * 3.将2存到本地的config.rpgsave里,插件指令SaveAll
 * 4.重进游戏,载入原缓存变量的值,插件指令LoadAll
 */
(function(){
    function XM_MyJsonArray(){
        this.myJson = [];
        this.set = function (x) {
            var index=Number(x);
            var value = $gameVariables.value(index);
            this.myJson[index]=value;
        };
        this.applyData=ConfigManager.applyData;
        this.loadConfig=function(config){
            if(config.myData!=undefined)
            this.myJson=config.myData;
        };
        this.pluginCommand=Game_Interpreter.prototype.pluginCommand;
        this.loadAll=function(){
            ConfigManager.load();
            if(this.myJson==undefined)return;
            for (var i = 0; i < this.myJson.length; i++)
            {
                if(this.myJson[i]==null)continue;
                $gameVariables.setValue(i,this.myJson[i]);
            }
        }
    }
    var XM_Array=new XM_MyJsonArray();
    ConfigManager.save = function() {
        var config=this.makeData();
        if(config.myData!=XM_Array.myJson)
            config.myData=XM_Array.myJson;
        StorageManager.save(-1, JSON.stringify(config));
    };
   ConfigManager.applyData = function (config) {
        XM_Array.applyData.call(this, config);
        XM_Array.loadConfig(config);
    };
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        XM_Array.pluginCommand.call(this, command, args);
        if (command === 'Push') {
            XM_Array.set(args);
        }
        if(command==='SaveAll'){
            ConfigManager.save();
        }
        if(command==='LoadAll'){
            XM_Array.loadAll();
        }
    };
}());

鸡蛋

鲜花

评论 (0 个评论)

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-15 02:38

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部