This post aims to incite you to share your ways to implement notetags in RMMV plugins.
In general, we don't want to edit the data JSON files directly, so there are generally 2 notetag reading timings:
1. Upon the start of the game
2. Upon using those notetags
I'll start by sharing my notetag implementation template with the 1st notetag reading timing:
I wrapped my entire setup in Author_Name.Plugin_Name to hope that mine won't pollute any "public namespace" like DataManager or even the global one.
Now I can access the notetag with name "notetag_name" stored in data with type "data_type" and id data_id using the below plugin call:
For instance:(DoubleX RMMV Equip Prerequisites)
What do you think about such setups? What's your setup instead and how you think about yours as well? Let's share your setups and comments on them here.
In general, we don't want to edit the data JSON files directly, so there are generally 2 notetag reading timings:
1. Upon the start of the game
2. Upon using those notetags
I'll start by sharing my notetag implementation template with the 1st notetag reading timing:
JavaScript:
Author_Name.Plugin_Name = {
/* General form:
data_type: {
note_name: {},
}, */
data_type_1: {
note_name_i_j: {}
/* ... */
},
data_type_2: {
note_name_i_j: {}
/* ... */
},
data_type_3: {
note_name_i_j: {}
/* ... */
},
/* ... */
data_type_n: {
note_name_i_j: {}
/* ... */
},
/* General form:
$dataTypes.forEach(function(data) {
if (data) {
this.load_notes("type", data);
}
}); */
load_all_notes: function() {
$dataTypes1.forEach(function(data) {
if (data) {
this.load_notes("type1", data);
}
});
$dataTypes2.forEach(function(data) {
if (data) {
this.load_notes("type2", data);
}
});
$dataTypes3.forEach(function(data) {
if (data) {
this.load_notes("type3", data);
}
});
/* ... */
$dataTypesN.forEach(function(data) {
if (data) {
this.load_notes("typeN", data);
}
});
return true;
}, // load_all_notes
// Additional notetag loading functions will be added when appropriate
/* type: The type of the data
data: The data to have its notetags read */
load_notes: function(type, data) {
var id = data.id;
Object.keys(this[type]).forEach(function(note) {
this[type][note][id] = note_init_val;
});
data.note.split(/[\r\n]+/).forEach(function(line) {
// The notetag reading implementations are written here
//
});
} // load_notes
}; // Author_Name.Plugin_Name
/*----------------------------------------------------------------------------
* * Edit class: DataManager
*----------------------------------------------------------------------------*/
DataManager.isDatabaseLoaded = (function(isDatabaseLoadedPluginName) {
return function() {
// Rewritten
isDatabaseLoadedPluginName.apply(this, arguments) &&
Author_Name.Plugin_Name.load_all_notes();
/
};
})(DataManager.isDatabaseLoaded);
Now I can access the notetag with name "notetag_name" stored in data with type "data_type" and id data_id using the below plugin call:
JavaScript:
Author_Name.Plugin_Name["data_type"][notetag_name][data_id]
JavaScript:
DoubleX_RMMV.Equip_Prerequisites = {
/* General form:
data_type: {
note_name: {},
}, */
weapons: {
no_weapon_req: {},
no_armor_req: {},
weapon_req: {},
armor_req: {},
stat_req: {},
var_req: {},
},
armors: {
no_weapon_req: {},
no_armor_req: {},
weapon_req: {},
armor_req: {},
stat_req: {},
var_req: {},
},
/* General form:
$dataTypes.forEach(function(data) {
if (data) {
this.load_notes(data, "type");
}
}); */
load_all_notes: function() {
$dataWeapons.forEach(function(data) {
if (data) {
this.load_notes(data, "weapons");
}
});
$dataArmors.forEach(function(data) {
if (data) {
this.load_notes(data, "armors");
}
});
}, // load_all_notes
/* data: The data to have its notetags read
type: The type of the data */
load_notes: function(data, type) {
var id = data.id.toString();
Object.keys(this[type]).forEach(function(note) {
this[type][note][id] = [];
});
var lines = data.note.split(/[\r\n]+/);
var no_weapon_note = /<no weapon req:\s*(\d+)>/;
var no_armor_note = /<no armor req:\s*(\d+)>/;
var weapon_note = /<weapon req:\s*(\d+)>/;
var armor_note = /<armor req:\s*(\d+)>/;
var stat_note = /<stat req:\s*(.+),\s*(\w+),\s*(\w+)>/;
var var_note = /<var req:\s*(\d+),\s*(\w+),\s*(\w+)>/;
var num, vals;
lines.forEach(function(line) {
if (line.test(no_weapon_note)) {
vals = line.match(no_weapon_note);
this[type]["no_weapon_req"][id].push(Number(vals[0]));
} else if (line.test(no_armor_note)) {
vals = line.match(no_armor_note);
this[type]["no_armor_req"][id].push(Number(vals[0]));
} else if (line.test(weapon_note)) {
vals = line.match(weapon_note);
this[type]["weapon_req"][id].push(Number(vals[0]));
} else if (line.test(armor_note)) {
vals = line.match(armor_note);
this[type]["armor_req"][id].push(Number(vals[0]));
} else if (line.test(stat_note)) {
vals = line.match(stat_note);
num = Number(vals[2]);
if (!isNaN(num)) {
vals[2] = num;
}
this[type]["stat_req"][id].push(vals);
} else if (line.test(var_note)) {
vals = line.match(var_note);
vals[0] = Number(vals[0]);
num = Number(vals[2]);
if (!isNaN(num)) {
vals[2] = num;
}
this[type]["var_req"][id].push(vals);
}
});
}, // load_notes
};
//----------------------------------------------------------------------------//
// * Edit class: DataManager //
//----------------------------------------------------------------------------//
DataManager.loadDatabase = (function(loadDatabaseEquipPrerequisites) {
return function() {
loadDatabaseEquipPrerequisites.apply(this, arguments);
DoubleX_RMMV.Equip_Prerequisites.load_all_notes(); // Added
};
})(DataManager.loadDatabase);
What do you think about such setups? What's your setup instead and how you think about yours as well? Let's share your setups and comments on them here.
Last edited: