@opendnd/personae
Version:
This tool is used to generate a person either NPC or other Edit
86 lines • 3.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@opendnd/core");
const defaults_1 = require("./defaults");
const colors = require("colors/safe");
const { cultures, races, backgrounds, klasses, typeOptions, genderOptions, raceOptions, cultureOptions, backgroundOptions, klassOptions, alignmentOptions, } = defaults_1.default;
exports.sanitizeWizardOpts = (opts) => {
if (opts.age) {
opts.age = parseInt(opts.age, 10);
}
if (!genderOptions.includes(opts.gender)) {
opts.gender = undefined;
}
if (!typeOptions.includes(opts.type)) {
opts.type = undefined;
}
if (!alignmentOptions.includes(opts.alignment)) {
opts.alignment = undefined;
}
if (opts.gender) {
opts.gender = core_1.Genders[opts.gender];
}
if (opts.type) {
opts.type = core_1.PersonTypes[opts.type];
}
if (opts.alignment) {
opts.alignment = core_1.ExpandedAlignments[opts.alignment];
}
if (opts.culture) {
Object.values(cultures).forEach((culture) => {
if (culture.name === opts.culture) {
opts.culture = culture;
}
});
}
if (opts.background) {
Object.values(backgrounds).forEach((background) => {
if (background.name === opts.background) {
opts.background = background;
}
});
}
if (opts.race) {
Object.values(races).forEach((race) => {
if (race.name === opts.race) {
opts.race = race;
}
});
}
if (opts.klass) {
Object.values(klasses).forEach((klass) => {
if (klass.name === opts.klass) {
opts.klass = klass;
}
});
}
// remove empty opts
Object.keys(opts).forEach((key) => {
if (opts[key] === "") {
opts[key] = undefined;
}
});
return opts;
};
exports.saveMsg = (resource) => {
return `Would you like to save the ${resource}? (y | n)`;
};
exports.makeQuestion = (question = "", options = "", required = false) => {
return {
info: colors.cyan(`${question} `) + colors.white(options),
required,
};
};
exports.standardQuestions = {
type: exports.makeQuestion("What type of person do you want to generate?", `(${typeOptions.join(" | ")})`),
culture: exports.makeQuestion("What is the person's culture theme?", `(${cultureOptions.join(" | ")})`),
name: exports.makeQuestion("What is this person's name?"),
age: exports.makeQuestion("What is this person's age?", "*leave blank if age group provided*"),
ageGroup: exports.makeQuestion("What is this person's age group?", "(young | middle | old) *leave blank if age provided*"),
gender: exports.makeQuestion("What's this person's gender?", `(${genderOptions.join(" | ")})`),
race: exports.makeQuestion("What race does this person have?", `(${raceOptions.join(" | ")})`),
alignment: exports.makeQuestion("What alignment does this person have?", `(${alignmentOptions.join(" | ")})`),
background: exports.makeQuestion("What background does this person have?", `(${backgroundOptions.join(" | ")})`),
klass: exports.makeQuestion("What class does this person have?", `(${klassOptions.join(" | ")})`),
};
//# sourceMappingURL=common.js.map