[HTML5] Export/Import save data

caranille

Villager
Member
Joined
Jan 21, 2015
Messages
9
Reaction score
0
First Language
French
Primarily Uses
Hi guys,


i'm making my own game with RPG Maker MV but i have an question.


Is that a plugin exist to export and Import the savedata in a file ?


Exemple: i have became the game and i save my progression but i want to continue the game in other computer or smartphone.


Because if my gamers use ccleaner or update her browser they lost her save ^^


Thanks for your answer ;)


Regards
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
I made this a while ago, so you may try if it suits your needs: http://pastebin.com/pGkW3Ssv


It's not a full plugin, though, since it was mainly used for debugging.
 

caranille

Villager
Member
Joined
Jan 21, 2015
Messages
9
Reaction score
0
First Language
French
Primarily Uses
Thanks for your help and for understand me (because i'm french and i don't speak english like you :p)


But i am an newbie on JS ^^ why use it ? i copy/past in on an js file and i add it in the plugin folder ?


And why you don't make an official plugin for this ? Because make an HTML5 game but can't keep the save is weird :p


Regards and thanks very much for you help, i test it in the evening
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
I'll see what i can do. It's been a while, since i wrote a proper plugin, so that might be a good opportunity to remove some of the rust :D
 

caranille

Villager
Member
Joined
Jan 21, 2015
Messages
9
Reaction score
0
First Language
French
Primarily Uses
I have read your help in the file header but i'm lost :p


Have you an exemple for use it ? You say it


To export a savefile from local web storage to a file, call the following function:
  IAVRA.SAVEMANAGER.exportWebStorage(savefileId);


and for import use it IAVRA.SAVEMANAGER.importWebStorage(savefileId);


but where can i add this for add an sub menu into my game for launch it :p


Regards
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
As i said, it's not a real plugin, so there are no visual elements, only JavaScript functions. I made a new version, that's not quite finished:


/*:
* @plugindesc v0.01 Offers a number of functions to export saves to files and import them again.
* @author Iavra
*/

(function($, undefined) {
"use strict";

/**
* Loads a given file, parses its content as json and passes it to a given callback. Throws an exception, if the
* file can't be loaded.
*/
var _loadFile = function(url, callback) {
var request = new XMLHttpRequest();
request.overrideMimeType('application/json');
request.open('GET', url);
request.onload = function() { callback(JsonEx.parse(LZString.decompressFromBase64(request.responseText))); };
request.onerror = function() { throw new Error('Couldn\'t load the file \'' + url + '\'.'); };
request.send();
};

/**
* Creates a download with the given data under the given filename. JavaScript can't write directly to the file
* system, unless we are using Node.js, which can't be guaranteed.
*/
var _saveFile = function(filename, data) {
var element = document.createElement('a');
var encoded = encodeURIComponent(LZString.compressToBase64(JsonEx.stringify(data)));
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encoded);
element.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
element.dispatchEvent(event);
} else { element.click(); }
};

//=============================================================================
// IAVRA.SAVE
//=============================================================================

$.SAVE = {
export: function(id) {
var info = DataManager.loadSavefileInfo(id), data = StorageManager.load(id);
if(!info || !data) { throw new Error('Couldn\'t find the savefile \'' + id + '\'.'); }
_saveFile('%1.save'.format(id.padZero(3)), {info: info, data: data});
},
import: function(id, url) {
var globalInfo = DataManager.loadGlobalInfo();
_loadFile(url, function(data) {
globalInfo[id] = data.info;
DataManager.saveGlobalInfo(globalInfo);
StorageManager.save(id, data.data);
})
}
}

})(this.IAVRA || (this.IAVRA = {}));


It offers 2 functions:


IAVRA.SAVE.export(id);
IAVRA.SAVE.import(id, url);


The first one exports the given save to a file and opens a download window. The second one takes the url to such a file and imports it under the given savefile id.


That said, the export currently only really works in web mode (game opened in browser) and not in local mode (testplay in MV, for example), since i can't get the download to work.
 

caranille

Villager
Member
Joined
Jan 21, 2015
Messages
9
Reaction score
0
First Language
French
Primarily Uses
Yes i understand,


If you can't export and import if the game is not in an http server it's normal, beacause it's use the webstorage and the webstorage work with an domaine (Exemple: http://localhost) but not work with file://index.html


Okay if i undertsand it i copy past this code in js.file i add this on the index.html with src and i call the function with my form choice (button etc...) ?


i follow you if you continue it ;)


Regards
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

DenRebrov wrote on Celianna's profile.
Seliana, will you be making desert tiles in the ancient dungeon?
Working on a casual shirt and jeans for female MZ gen. Woo.
Crazy idea: a crossover game made to showcase different RPG Maker games. Dimension crossing is involved and you get to play as different people's characters in some wacky nonsense plot.
HexMozart88 wrote on Citali's profile.
Kikuo!
The lack of bike trails and bungee jump areas in this city should be criminalized.

Forum statistics

Threads
107,421
Messages
1,029,607
Members
139,550
Latest member
GodChosenTheGame
Top