import * as fs from "node:fs";
import Logging from "log-like-a-zombie";
let log = new Logging('AvatarConversion');
log.i(`RR Config Conversion Tool by @zombieb`);
class FinalAvatarItem {
constructor() {
this.AvatarItemDesc = new String();
this.AvatarItemType = 0,
this.PlatformMask = 0,
this.FriendlyName = new String();
this.Tooltip = 'For use with development builds only!',
this.Rarity = 0
}
}
function formatItemName(str) {
// Remove parentheses
str = str.replace(/[\(\)]/g, '');
// Remove first underscore and everything before it
let underscoreIndex = str.indexOf('_');
if (underscoreIndex !== -1) {
str = str.substring(underscoreIndex + 1);
}
// Add a space before each capital letter and after each underscore
str = str.replace(/([A-Z])|(_)/g, ' $1').trim();
// Remove any remaining underscores
str = str.replace(/_/g, '');
// Remove extra spaces
str = str.replace(/\s+/g, ' ');
return str;
}
function formatItemDesc(visualData) {
let d = "";
if (typeof visualData.prefabGuid !== 'undefined') d = d + `${visualData.prefabGuid},`;
else d = d + ',';
if (typeof visualData.maskGuid !== 'undefined') d = d + `${visualData.maskGuid},`;
else d = d + ',';
if (typeof visualData.swatchGuid !== 'undefined') d = d + `${visualData.swatchGuid},`;
else d = d + ',';
log.d(`Created item visual data: '${d}'`);
return d;
}
// Read only db
const db = JSON.parse(fs.readFileSync('./raw.json'));
log.d(`Imported raw config`);
let final = [];
const coerce = (val, i, arr) => {
let d = new FinalAvatarItem();
d.AvatarItemDesc = formatItemDesc(val._avatarItemVisualData);
d.FriendlyName = formatItemName(val._avatarItemData.Name);
final.push(d);
}
db.tutorialAvatarItems.forEach(coerce);
db.defaultUnlockedAvatarItems.forEach(coerce);
db.initialAvatarItems.forEach(coerce);
db.defaultTorsoAvatarItems.forEach(coerce);
db.allPossibleCombinations.forEach(coerce);
fs.writeFileSync('./rawNew.json', Buffer.from(JSON.stringify(final)), {encoding:'utf8',flag:'w'});