Yeah, and I'm also thinking about these issues too, as I'm comparing between DataManager.isDatabaseLoaded and DataManager.extractMetadata.
Right now, what I can see is this(I'm trying to figure out the full picture):
Extreme case 1 - Only 1 datatype has notetags
Example:
Spoiler
Using DataManager.extractMetadata -
AuthorName.PluginName.DataManager_loadDataFile = DataManager.loadDataFile;DataManager.loadDataFile = function(name, src) { this._pluginNameSrc = src; // Added to mark the current source file name AuthorName.PluginName.DataManager_loadDataFile.call(this, name, src);}; // DataManager.loadDataFileAuthorName.PluginName.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;DataManager.isDatabaseLoaded = function() { this._pluginNameSrc = undefined; // Added return AuthorName.PluginName.DataManager_isDatabaseLoaded.call(this);}; // DataManager.isDatabaseLoadedAuthorName.PluginName.DataManager_extractMetadata = DataManager.extractMetadata;DataManager.extractMetadata = function(data) { AuthorName.PluginName.DataManager_extractMetadata.call(this, data); // Added to load all skill notetags if the current source file is Skills if (this._pluginNameSrc.match(/Skills/)) { this.loadPluginNameSkillNotes(data); } //}; // DataManager.extractMetadataUsing DataManager.isDatabaseLoaded -
AuthorName.PluginName.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;DataManager.isDatabaseLoaded = function() { // Rewritten if (AuthorName.PluginName.DataManager_isDatabaseLoaded.call(this)) { return false; } this.loadAllPluginNameNotes(); return true; //}; // DataManager.isDatabaseLoadedDataManager.loadAllPluginNameNotes = function() { // New $dataSkills.forEach(function(skill) { if (skill) { this.loadPluginNameSkillNotes(skill); } }, this);} // DataManager.loadAllPluginNameNotes
Spoiler
Extreme case 2 - All datatype has different notetags needing different notetag reading functions
Example:
Using DataManager.extractMetadata -
AuthorName.PluginName.DataManager_loadDataFile = DataManager.loadDataFile;DataManager.loadDataFile = function(name, src) { this._pluginNameSrc = src; // Added to mark the current source file name AuthorName.PluginName.DataManager_loadDataFile.call(this, name, src);}; // DataManager.loadDataFileAuthorName.PluginName.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;DataManager.isDatabaseLoaded = function() { this._pluginNameSrc = undefined; // Added return AuthorName.PluginName.DataManager_isDatabaseLoaded.call(this);}; // DataManager.isDatabaseLoadedAuthorName.PluginName.DataManager_extractMetadata = DataManager.extractMetadata;DataManager.extractMetadata = function(data) { AuthorName.PluginName.DataManager_extractMetadata.call(this, data); // Added to load each data type notetag via its own notetag reading function this.loadAllPluginNameNotes(data); //}; // DataManager.extractMetadataDataManager.loadAllPluginNameNotes = function(data) { // New if (this._pluginNameSrc.match(/Actors/)) { this.loadPluginNameActorNotes(data); } else if (this._pluginNameSrc.match(/Classes/)) { this.loadPluginNameClassNotes(data); } else if (this._pluginNameSrc.match(/Skills/)) { this.loadPluginNameSkillNotes(data); } else if (this._pluginNameSrc.match(/Items/)) { this.loadPluginNameItemNotes(data); } else if (this._pluginNameSrc.match(/Weapons/)) { this.loadPluginNameWeaponNotes(data); } else if (this._pluginNameSrc.match(/Armors/)) { this.loadPluginNameArmorNotes(data); } else if (this._pluginNameSrc.match(/Enemies/)) { this.loadPluginNameEnemyNotes(data); } else if (this._pluginNameSrc.match(/Troops/)) { this.loadPluginNameTroopNotes(data); } else if (this._pluginNameSrc.match(/States/)) { this.loadPluginNameStateNotes(data); } else if (this._pluginNameSrc.match(/Animations/)) { this.loadPluginNameAnimationNotes(data); } else if (this._pluginNameSrc.match(/Tilesets/)) { this.loadPluginNameTilesetNotes(data); } else if (this._pluginNameSrc.match(/CommonEvents/)) { this.loadPluginNameCommonEventNotes(data); } else if (this._pluginNameSrc.match(/System/)) { this.loadPluginNameSystemNotes(data); } else if (this._pluginNameSrc.match(/MapInfos/)) { this.loadPluginNameMapInfoNotes(data); }}; // DataManager.loadAllPluginNameNotesUsing DataManager.isDatabaseLoaded -
AuthorName.PluginName.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;DataManager.isDatabaseLoaded = function() { // Rewritten if (AuthorName.PluginName.DataManager_isDatabaseLoaded.call(this)) { return false; } this.loadAllPluginNameNotes(); return true; //}; // DataManager.isDatabaseLoadedDataManager.loadAllPluginNameNotes = function() { // New $dataActors.forEach(function(actor) { if (actor) { this.loadPluginNameSkillNotes(actor); } }, this); $dataClasses.forEach(function(class) { if (class) { this.loadPluginNameClassNotes(class); } }, this); $dataSkills.forEach(function(skill) { if (skill) { this.loadPluginNameSkillNotes(skill); } }, this); $dataItems.forEach(function(item) { if (item) { this.loadPluginNameItemNotes(item); } }, this); $dataWeapons.forEach(function(weapon) { if (weapon) { this.loadPluginNameWeaponNotes(weapon); } }, this); $dataArmors.forEach(function(armor) { if (armor) { this.loadPluginNameArmorNotes(armor); } }, this); $dataEnemies.forEach(function(enemy) { if (enemy) { this.loadPluginNameEnemyNotes(enemy); } }, this); $dataTroops.forEach(function(troop) { if (troop) { this.loadPluginNameTroopNotes(troop); } }, this); $dataStates.forEach(function(state) { if (state) { this.loadPluginNameStateNotes(state); } }, this); $dataAnimations.forEach(function(animation) { if (animation) { this.loadPluginNameAnimationNotes(animation); } }, this); $dataTilesets.forEach(function(tileset) { if (tileset) { this.loadPluginNameTilesetNotes(tileset); } }, this); $dataCommonEvents.forEach(function(commonEvent) { if (commonEvent) { this.loadPluginNameCommonEventNotes(commonEvent); } }, this); $dataSystem.forEach(function(system) { if (system) { this.loadPluginNameSystemNotes(system); } }, this); $dataMapInfos.forEach(function(mapInfo) { if (mapInfo) { this.loadPluginNameMapInfoNotes(mapInfo); } }, this);} // DataManager.loadAllPluginNameNotes
While I personally prefer to use DataManager.isDatabaseLoaded, if that's really proven to be absolutely 100% evil under any possible circumstance, I'll switch to use DataManager.extractMetadata instead
🙂
P.S.: I somehow suspect that DataManager.isDatabaseLoaded is the only timing that can be used to load custom plugin notetags conveniently, even though it's supposed to be referentially transparent(no side effects). If that's the case, then the issue might lie in the very default RMMV codebase itself, as violating the referential transparency in DataManager.isDatabaseLoaded would be the best balance for we plugin developers in this case. Of course, that's just my wild guess
😀
In the times I've made the shifts regarding notetag loading, this is what I've came up with:
- DataManager.extractMetaData fails to distinguish types of data.
- DataManager.onLoad loads strictly in the order of actors, classes, skills, items, weapons, armors, enemies, troops, states, animations, tilesets, common events, system, and types. This becomes a problem when you need an actor notetag to reference something in say, an enemy notetag.
- Scene_Boot.start is a no go for me because some plugins completely overwrite it.
- Scene_Boot.create also gets overwritten in some plugins.
- Scene_Boot.terminate occurs too late, in some instances where functions that fun in Scene_Boot.start already occur and require the note data.
So yes, you're right in that RPG Maker MV doesn't have a reliable location to safely load up custom notetag data. DataManager.postDatabaseLoaded would have been lovely if it existed. For that reason, I figured the earliest and safest place to load notetag data is within DataManager.isDatabaseLoaded where it will most likely not be overwritten.
I received this report of an error occurring, which is what got me onto this topic:
http://forums.rpgmakerweb.com/index.php?/topic/46515-preload-manager/?p=510196
Based on your code the error shouldn't really happen (it seems like one of the $data* arrays are nil in this example), so I'm not saying that the notetag reading being placed in the isDatabaseLoaded() function necessarily is the culprit, but it made me aware of it and I just see it as bad practice to put data altering code into a function meant to simply read the status of file loading. As you've seen I call this function repeatedly until I can ensure that the database is fully loaded, and I figure it's likely that many other plugins will do this too (it's why it's there), which means your notetags will be read over and over perhaps dozens of time on startup.
The error most likely came from the person tampering with the JSON file as there should be a notedata entry for each database entry.
And what you consider to be bad practice, I consider to be perfectly fine. isDatabaseLoaded() should return true or false depending on if the entirity of the database is completely loaded, is it not? To me, I deem that the database is not completely loaded unless the notetag data within it is loaded and parsed. So unless my notetags, which I deem to be part of each and every database entry's data, are loaded, isDatabaseLoaded() returning true/false without my notetags loaded in there is delivering false information. If you are able to suggest a better timing for me to load notetags without encountering any of the above listed problems, I'll see to your suggestion.
And no, not really. I estimate that a good 99.99% of the plugins created now and within the future will not run DataManager.isDatabaseLoaded() any time past the initial opening steps. It's a one-to-two time run at best. This is because once the database is loaded, there is no further reason to check it again mid-game to see if it has been loaded.
Then Yanfly might do something like this to stick with his/her way:
Spoiler
AuthorName.PluginName.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;DataManager.isDatabaseLoaded = function() {
// Rewritten
if (!AuthorName.PluginName.DataManager_isDatabaseLoaded.call(this)) {
return false;
}
if (!this._isPluginNameNotesLoaded) {
this.loadAllPluginNameNotes();
}
return this._isPluginNameNotesLoaded;
//
}; // DataManager.isDatabaseLoaded
DataManager.loadAllPluginNameNotes = function() { // New
// The notetag reading codes go here
//
this._isPluginNameNotesLoaded = true;
} // DataManager.isDatabaseLoaded
Of course he/she will have to be 100% sure that his/her notetag reading codes will always work as intended
🙂
Not quite, I've tried that before and sometimes, $data_ arrays reset themselves to their default editor state until isDatabaseLoaded is set true indefinitely.