Source

SlayTheSpireAPI/APIComponents/SeedHelper.ts

import java from 'java';

import { AbstractAPIComponent } from './AbstractAPIComponent';
import { Random } from './Random';

/**
 * Contains useful methods for manipulating Slay the Spire game seeds
 */
export class SeedHelper extends AbstractAPIComponent {
    /**
     * Create an instance of a SeedHelper
     * @param {string} stsJarPath Path to the `desktop-1.0.jar` Slay the Spire game file
     * @example
     * const seedHelper = new SeedHelper('./path/to/stsJar');
     */
    public constructor(stsJarPath: string) {
        super(stsJarPath);
    }

    /**
     * Get the human readable string of a seed from the {@link Random} generated from it
     * @param {Random} rng Random number generator
     * @returns {string}
     * @example
     * const seed: number = 1337;
     * const rng = new Random('./path/to/stsJar', seed);
     *
     * const seedHelper = new SeedHelper('./path/to/stsJar');
     * const humanReadableString = seedHelper.getString(rng);
     */
    // eslint rule disabled because it requires stsJar to be added to Java classpath
    // eslint-disable-next-line class-methods-use-this
    public getString(rng: Random): string {
        const seedLongValue = rng.randomLong();
        const seedString: string = java.callStaticMethodSync(
            'com.megacrit.cardcrawl.helpers.SeedHelper', 'getString', seedLongValue,
        );

        if (java.callStaticMethodSync('com.megacrit.cardcrawl.helpers.BadWordChecker',
            'containsBadWord', seedString)) {
            return java.callStaticMethodSync('com.megacrit.cardcrawl.helpers.SeedHelper',
                'generateUnoffensiveSeed', rng);
        }

        return seedString;
    }
}