Module:GameData/doc: Difference between revisions

Update to support 2023 Birthday event
(Update for v1.2/AoD)
(Update to support 2023 Birthday event)
 
(3 intermediate revisions by the same user not shown)
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 16: Line 18:
melvorF: { displayName: "Full Version", url: "https://" + location.hostname + this.baseDir + "melvorFull.json" },
melvorF: { displayName: "Full Version", url: "https://" + location.hostname + this.baseDir + "melvorFull.json" },
melvorTotH: { displayName: "Throne of the Herald", url: "https://" + location.hostname + this.baseDir + "melvorTotH.json" },
melvorTotH: { displayName: "Throne of the Herald", url: "https://" + location.hostname + this.baseDir + "melvorTotH.json" },
melvorAoD: { displayName: "Atlas of Discovery", url: "https://" + location.hostname + this.baseDir + "melvorExpansion2.json" }
melvorAoD: { displayName: "Atlas of Discovery", url: "https://" + location.hostname + this.baseDir + "melvorExpansion2.json" },
melvorBirthday2023: { displayName: "Melvor Birthday 2023", url: "https://" + location.hostname + this.baseDir + "melvorBirthday2023.json" }
};
};
// Check all required namespaces are registered, as there are still some bits of data extracted from in-game rather than the data packages
// Check all required namespaces are registered, as there are still some bits of data extracted from in-game rather than the data packages
Line 84: Line 87:
}
}
escapeQuotes(data) {
escapeQuotes(data) {
var newData = data.replace(/\'/g, "\\\'");
var newData = data.replace(/\\/g, '\\\\')
newData = newData.replace(/\\\"/g, "\\\\\"");
newData = newData.replace(/'/g, "\\'");
newData = newData.replace(/"/g, '\\"');
return newData;
return newData;
}
}
Line 131: Line 135:
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 138: Line 142:


// 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) {