All data, including map data, is loaded with the DataManager class. That is a perfect place to start if you're looking to load any sort of Data. Now, I would actually recommend you create your own function to load the data, because you need to be able to manipulate it the way you want it and not have MV do what it does with it's own maps.
PHP:
DataManager.loadDataFile = function(name, src) {
var xhr = new XMLHttpRequest();
var url = 'data/' + src;
xhr.open('GET', url);
xhr.overrideMimeType('application/json');
xhr.onload = function() {
if (xhr.status < 400) {
window[name] = JSON.parse(xhr.responseText);
DataManager.onLoad(window[name]);
}
};
xhr.onerror = this._mapLoader || function() {
DataManager._errorUrl = DataManager._errorUrl || url;
};
window[name] = null;
xhr.send();
};
This function here will load any data file in the data/ directory. This function however will make a new GLOBAL variable, and we don't want that, so you should create your own function with the same way of loading the file, but without the extra boilerplate.
The following function is from my Core plugin, feel free to use it. It's made with ES6 so it may be a bit confusing but It's rather easy to understand and you only need the core concept to make your own.
PHP:
function ajaxLoadFile (path, type = 'application/json', onload, onerror, context) {
const xhr = new window.XMLHttpRequest()
xhr.open('GET', path)
xhr.overrideMimeType(type)
xhr.onload = () => {
if (xhr.status < 400) {
onload.call(context, xhr.responseText)
}
}
xhr.onerror = (err) => onerror.call(context, err)
xhr.send()
}
This one is more standard can can be used to load whatever file you would like and then it will send the results in a callback function. So once the file is loaded the onload argument which should be a function will be called with the result of the data passed into it.
PHP:
function loadSuccess (response) {
console.log('Success!', response)
console.log('Parsed Data', JSON.parse(response))
}
function loadFailed (error) {
console.error(error)
}
ajaxLoadFile('directory/to/file', 'application/json', loadSuccess, loadFailed)
The above ajaxLoadFile will look for the file, and the type is a json file, then if it finds it and no errors loading it, then it will call the loadSuccess function, otherwise, it will call loadFailed. The context, which is not used in this case is only required when calling this function from a class / constructor function where you need to call a function which has this keyword in it.
For Example, this is where the context argument would be required.
PHP:
MyClass.prototype.loadSuccess (response) {
console.log('Success!', response)
console.log('Parsed Data', JSON.parse(response))
}
MyClass.prototype.loadFailed (error) {
console.error(error)
}
MyClass.prototype.loadFile (path) {
ajaxLoadFile(path, 'application/json', this.loadSuccess, this.loadFailed, this)
}
Now that that part is out of the way, to actually transfer your player to that map is a bit different, it's something I never really played around with. Although, I'm guessing you just simply assign the global $dataMap variable to your recently parsed map file from above. Then at some point re-initialize the map so it loads the latest changes. I will have to look into this more, later on, maybe I can come up with a quick prototype of what you're trying to achieve
I'm sure some of this is confusing if you've never dealt with it before so feel free to ask questions. I will also tag
@Kino because he knows all about loading files/data files as well and may have already done something like what you're asking.