Module:GameData/doc: Difference between revisions

Update documentation in line with changes to how data is loaded
m (Auron956 moved page Module:GameData/data/doc to Module:GameData/doc without leaving a redirect: Page this was previously documenting is now redundant)
(Update documentation in line with changes to how data is loaded)
Line 1: Line 1:
The '''GameData''' module is the source of all game data which many other Lua modules rely upon. This module deals with the initial loading of the game data structure, and then enables other modules to access this both via a library of functions (preferred) and in its raw format.
To generate game data, do the following:
To generate game data, do the following:
# Navigate to https://melvoridle.com within your preferred web browser
# Navigate to https://melvoridle.com within your preferred web browser
Line 5: Line 7:
# Open the browser console/developer mode (usually by hitting the F12 key for most browsers)
# Open the browser console/developer mode (usually by hitting the F12 key for most browsers)
# Within the browser console, enter the following code then hit enter. If successful, the game data should appear within the console
# Within the browser console, enter the following code then hit enter. If successful, the game data should appear within the console
# Copy the game data & update [[Module:GameData/data]] and [[Module:GameData/data2]] accordingly
# Copy the game data & update [[Module:GameData/data.json]] and [[Module:GameData/data2.json]] accordingly


{{SpoilerBox|color=default|title=Code|text=<syntaxhighlight lang="javascript" line>class Wiki {
{{SpoilerBox|color=default|title=Code|text=<syntaxhighlight lang="javascript" line>class Wiki {
Line 132: Line 134:
const result = await this.getWikiData();
const result = await this.getWikiData();
}
}
let dataObjText;
console.log('Printing data for game version ' + this.getGameVersion());
this.printPages.forEach((page) => {
this.printPages.forEach((page) => {
const inclCat = this.getCategoriesForPage(page);
const inclCat = this.getCategoriesForPage(page);
Line 139: Line 141:


// Convert game data into a JSON string for export
// Convert game data into a JSON string for export
dataObjText = undefined;
let dataText;
if (this.prettyPrint) {
if (this.prettyPrint) {
dataObjText = this.escapeQuotes(JSON.stringify(gameDataFiltered, undefined, '\t'));
dataText = JSON.stringify(gameDataFiltered, undefined, '\t');
}
}
else {
else {
dataObjText = "{" + Object.keys(gameDataFiltered).map((k) => this.formatJSONData(k, gameDataFiltered[k])).join(",' ..\n'") + "}"; //JSON.stringify(gameDataFiltered);
dataText = JSON.stringify(gameDataFiltered);
}
}
 
let dataText = '-- Version: ' + this.getGameVersion();
dataText += "\r\n\r\nlocal gameData = mw.text.jsonDecode('";
dataText += dataObjText;
dataText += "')\r\n\r\nreturn gameData";
console.log(`For page "${ page.destination }" (${ dataText.length.toLocaleString() } bytes):`);
console.log(`For page "${ page.destination }" (${ dataText.length.toLocaleString() } bytes):`);
if (dataText.length > this.maxPageBytes) {
if (dataText.length > this.maxPageBytes) {