This commit is contained in:
Kalle
2026-07-30 14:01:18 +03:00
parent fa75457cd3
commit 5e17c6c7cc
3 changed files with 32 additions and 17 deletions

View File

@@ -1,22 +1,26 @@
import {
IN_GAME_NAME,
sanitizeInGameName,
} from "~/features/user-page/in-game-name";
import { abilities } from "~/modules/in-game-lists/abilities";
import {
clothesGearIds,
headGearIds,
shoesGearIds,
} from "~/modules/in-game-lists/gear-ids";
import { modesShort, rankedModesShort } from "~/modules/in-game-lists/modes";
import { rankedModesShort } from "~/modules/in-game-lists/modes";
import { stageIds } from "~/modules/in-game-lists/stage-ids";
import type {
Ability,
BuildAbilitiesTuple,
MainWeaponId,
ModeShort,
ModeWithStage,
} from "~/modules/in-game-lists/types";
import {
canonicalWeaponSplId,
mainWeaponIds,
} from "~/modules/in-game-lists/weapon-ids";
import invariant from "~/utils/invariant";
import { faker } from "./faker";
const STACKABLE_ABILITIES = abilities
@@ -46,23 +50,20 @@ export function gear() {
};
}
// xxx: prolly inline
/** A non-empty subset of the modes, e.g. the ones a build is made for. */
export function modes(): ModeShort[] {
return faker.helpers.arrayElements(modesShort, { min: 1, max: 3 });
}
const IN_GAME_NAME_MAX_LENGTH = 10;
// xxx: match the actual rules for this
/** An in-game name with its discriminator, e.g. `Agent 4#1859`. */
/**
* An in-game name with its discriminator, e.g. `Agent 4#1859`. `name` is sanitized and
* truncated the way the real thing is, so the result always passes `inGameNameIsValid`.
*/
export function inGameName(name = faker.person.firstName()): string {
const tag = faker.string.alphanumeric({
length: faker.helpers.arrayElement([4, 5]),
const discriminator = faker.string.alphanumeric({
length: {
min: IN_GAME_NAME.DISCRIMINATOR_MIN_LENGTH,
max: IN_GAME_NAME.DISCRIMINATOR_MAX_LENGTH,
},
casing: "lower",
});
return `${[...name].slice(0, IN_GAME_NAME_MAX_LENGTH).join("")}#${tag}`;
return `${sanitizedName(name)}#${discriminator}`;
}
/**
@@ -86,6 +87,16 @@ export function buildAbilities(): BuildAbilitiesTuple {
return [gearAbilities(), gearAbilities(), gearAbilities()];
}
function sanitizedName(name: string): string {
const characters = [...sanitizeInGameName(name)].slice(
0,
IN_GAME_NAME.NAME_MAX_LENGTH,
);
invariant(characters.length > 0, `No valid in-game name characters: ${name}`);
return characters.join("");
}
function gearAbilities(): [Ability, Ability, Ability, Ability] {
const draw = () => faker.helpers.arrayElement(STACKABLE_ABILITIES);

View File

@@ -1,4 +1,5 @@
import * as BuildRepository from "~/features/builds/BuildRepository.server";
import { modesShort } from "~/modules/in-game-lists/modes";
import { defineFactory } from "../core/defineFactory";
import { faker } from "../core/faker";
import * as SplatoonFaker from "../core/SplatoonFaker";
@@ -18,7 +19,10 @@ export const { create, createMany } = defineFactory({
defaults: () => ({
title: faker.lorem.words(3),
description: faker.number.float(1) < 0.4 ? faker.lorem.paragraph() : null,
modes: faker.number.float(1) < 0.7 ? SplatoonFaker.modes() : null,
modes:
faker.number.float(1) < 0.7
? faker.helpers.arrayElements(modesShort, { min: 1, max: 3 })
: null,
...(faker.number.float(1) < 0.85 ? SplatoonFaker.gear() : NO_GEAR),
weaponSplIds: SplatoonFaker.mainWeapons(
faker.helpers.arrayElement([1, 1, 1, 1, 2, 2, 3, 4, 5]),

View File

@@ -1,6 +1,6 @@
import type { FormsTranslationKey } from "~/form/types";
const IN_GAME_NAME = {
export const IN_GAME_NAME = {
NAME_MAX_LENGTH: 10,
DISCRIMINATOR_MIN_LENGTH: 4,
DISCRIMINATOR_MAX_LENGTH: 5,