Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*:
- * Save Testers
- *
- * @plugindesc Allows testers saving/loading their own paces in different folders.
- * @author Dr.Yami and Archeia
- *
- * @help This plugin does not provide plugin commands.
- * Create a TESTER_ID.txt on your desktop. Place a name inside it.
- * If you place the Master Key (Nessiah by default), you will be able to access
- * all your beta tester's save files.
- *
- * @param Master Key
- * @desc Project master, uses to access testers savefiles.
- * Default: Nessiah
- * @default Nessiah
- *
- */
- var DrYami = DrYami || {};
- DrYami.SaveTesters = {};
- DrYami.SaveTesters.Params = PluginManager.parameters('SaveTesters');
- DrYami.SaveTesters.MasterKey = String(DrYami.SaveTesters.Params['Master Key']);
- (function () {
- if (!Utils.isNwjs()) return;
- var fs = require('fs');
- var keyFilename = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'] + '/Desktop/TESTER_ID.txt';
- StorageManager.testerKey = "";
- var _loadDatabase = DataManager.loadDatabase;
- DataManager.loadDatabase = function () {
- _loadDatabase.call(this);
- StorageManager.testerKey = StorageManager.getTesterKey();
- StorageManager.createSaveFolder();
- };
- StorageManager.getTesterKey = function () {
- if (!fs.existsSync(keyFilename)) {
- this.generateTesterKey();
- }
- return String(fs.readFileSync(keyFilename));
- };
- StorageManager.generateTesterKey = function () {
- var key = this.generateRandomString();
- while (fs.existsSync(this.localFileDirectoryPath() + key)) {
- key = this.generateRandomString();
- }
- fs.writeFileSync(keyFilename, key);
- };
- StorageManager.generateRandomString = function (length) {
- length = length || 8;
- var text = "";
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- for (var i = 0; i < length; i++)
- text += chars.charAt(Math.floor(Math.random() * chars.length));
- return text;
- };
- StorageManager.localFilePath = function (savefileId) {
- var name;
- var key = StorageManager.testerKey;
- if (savefileId < 0) {
- name = 'config.rpgsave';
- } else if (savefileId === 0) {
- name = 'global.rpgsave';
- } else {
- name = 'file%1.rpgsave'.format(savefileId);
- }
- return this.localFileDirectoryPath() + key + '/' + name;
- };
- StorageManager.createSaveFolder = function () {
- var orgdirPath = this.localFileDirectoryPath();
- var dirPath = this.localFileDirectoryPath() + StorageManager.testerKey;
- if (!fs.existsSync(orgdirPath)) fs.mkdirSync(orgdirPath);
- if (!fs.existsSync(dirPath)) fs.mkdirSync(dirPath);
- };
- StorageManager.getAllTesterKeys = function () {
- var srcpath = this.localFileDirectoryPath();
- var path = require('path');
- return fs.readdirSync(srcpath).filter(function (file) {
- return fs.statSync(path.join(srcpath, file)).isDirectory();
- });
- };
- StorageManager.isMasterKey = function () {
- return StorageManager.testerKey === DrYami.SaveTesters.MasterKey;
- };
- function Window_SaveMasterKey() {
- this.initialize.apply(this, arguments);
- }
- Window_SaveMasterKey.prototype = Object.create(Window_Command.prototype);
- Window_SaveMasterKey.prototype.constructor = Window_SaveMasterKey;
- Window_SaveMasterKey.prototype.initialize = function () {
- Window_Command.prototype.initialize.call(this, 0, 0);
- this.updatePlacement();
- };
- Window_SaveMasterKey.prototype.windowWidth = function () {
- return 320;
- };
- Window_SaveMasterKey.prototype.updatePlacement = function () {
- this.x = (Graphics.boxWidth - this.width) / 2;
- this.y = (Graphics.boxHeight - this.height) / 2;
- };
- Window_SaveMasterKey.prototype.makeCommandList = function () {
- var keys = StorageManager.getAllTesterKeys();
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
- this.addCommand(key, key);
- }
- };
- var _Scene_Boot_start = Scene_Boot.prototype.start;
- Scene_Boot.prototype.start = function () {
- if (!DataManager.isBattleTest() && !DataManager.isEventTest()
- && StorageManager.isMasterKey()) {
- this.checkPlayerLocation();
- DataManager.setupNewGame();
- SceneManager.goto(Scene_SaveMaster);
- this.updateDocumentTitle();
- Window_TitleCommand.initCommandPosition();
- } else {
- _Scene_Boot_start.call(this);
- }
- };
- function Scene_SaveMaster() {
- this.initialize.apply(this, arguments);
- }
- Scene_SaveMaster.prototype = Object.create(Scene_Base.prototype);
- Scene_SaveMaster.prototype.constructor = Scene_SaveMaster;
- Scene_SaveMaster.prototype.initialize = function () {
- Scene_Base.prototype.initialize.call(this);
- };
- Scene_SaveMaster.prototype.create = function () {
- Scene_Base.prototype.create.call(this);
- this.createWindowLayer();
- this.createWindows();
- };
- Scene_SaveMaster.prototype.createWindows = function () {
- this._windowSaveMaster = new Window_SaveMasterKey();
- this._windowSaveMaster.setHandler('ok', this._commandOk.bind(this));
- this.addWindow(this._windowSaveMaster);
- };
- Scene_SaveMaster.prototype._commandOk = function () {
- var key = this._windowSaveMaster.currentSymbol();
- StorageManager.testerKey = key;
- SceneManager.goto(Scene_Title);
- };
- } ());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement