Newer
Older
rr-item-conversion / scripts / equipment.mjs
import * as fs from "node:fs";
import Logging from "log-like-a-zombie";

let log = new Logging('EquipmentConversion');

log.i(`RR Config Conversion Tool by @zombieb`);

class FinalEquipmentItem {
    constructor() {
        this.PlatformMask = 0;
        this.IsPlatformLocked = false;
        this.Tooltip = 'For use with development builds only!';
        this.Rarity = GiftRarity.Uncommon;
    }
}

function formatFriendlyName(prefix, name) {
    function removeItemAll(arr, value) {
        var i = 0;
        while (i < arr.length) {
            if (arr[i] === value) {
                arr.splice(i, 1);
            } else {
                ++i;
            }
        }
        return arr;
    }

    let formattedPrefix = String(prefix).replace('[', '');
    formattedPrefix = formattedPrefix.replace(']', '');

    let item = String(name).replace(formattedPrefix, '');
    item = item.substring(1, item.length);

    let arr = String(item).split('_');
    arr = removeItemAll(arr, 'Skin');

    // Exceptions. Some have spelling errors or simply don't look good.
    if (arr.includes('aintBallRifleScoped')) removeItemAll(arr, 'aintBallRifleScoped');
    if (arr.includes('PINK')) arr[arr.indexOf('PINK')] = 'Pink';
    if (arr.includes('wood')) arr[arr.indexOf('wood')] = 'Wood';
    if (arr.includes('Watermeon')) arr[arr.indexOf('Watermeon')] = 'Watermelon';

    return name = arr.toString().replace(',', ' ');
}
    
// Read only db
const db = JSON.parse(fs.readFileSync('./raw.json'));
log.d(`Imported raw config`);
let final = [];

const coerce = (rootVal, i, arr) => {
    rootVal.skins.forEach((localVal, i, arr) => {
        let d = new FinalEquipmentItem();
        d.PrefabName = rootVal.equipment.prefabName;
        d.ModificationGuid = localVal.skinGuid;
        d.FriendlyName = formatFriendlyName(rootVal.equipment.prefabName, localVal.skinAssetName);
        log.d(`Created equipment ${d.FriendlyName} with guid ${d.ModificationGuid}`);

        final.push(d);
    });
}

db.toolSkinMaps.forEach(coerce);

fs.writeFileSync('./rawNew.json', Buffer.from(JSON.stringify(final)), { encoding: 'utf8', flag: 'w' });

const GiftRarity = {
    Common: 0,
    Uncommon: 10,
    Rare: 20,
    Epic: 30,
    Legendary: 50
}