1- import { simpleHash } from "../Util"
2-
3- const PLURAL_NOUN = Symbol ( "plural!" )
4- const NOUN = Symbol ( "noun!" )
1+ const PLURAL_NOUN = Symbol ( "plural!" ) ;
2+ const NOUN = Symbol ( "noun!" ) ;
53
64const names = [
7- [ "World Famous" , NOUN ] ,
8- [ "Comically Large" , NOUN ] ,
9- [ "Comically Small" , NOUN ] ,
10- [ "Clearance Aisle" , PLURAL_NOUN ] ,
11- [ NOUN , "For Hire" ] ,
12- [ "Suspicious" , NOUN ] ,
13- [ "Sopping Wet" , PLURAL_NOUN ] ,
14- [ "Smelly" , NOUN ] ,
15- [ "Friendly" , NOUN ] ,
16- [ "Tardy" , NOUN ] ,
17- [ "Evil" , NOUN ] ,
18- [ PLURAL_NOUN , "That Bite" ] ,
19- [ "Malicious" , NOUN ] ,
20- [ "Spiteful" , NOUN ] ,
21- [ "Mister" , NOUN ] ,
22- [ "Alternate" , NOUN , "Universe" ] ,
23- [ NOUN , "Island" ] ,
24- [ NOUN , "Kingdom" ] ,
25- [ NOUN , "Empire" ] ,
26- [ NOUN , "Dynasty" ] ,
27- [ NOUN , "Cartel" ] ,
28- [ NOUN , "Cabal" ] ,
29- [ "Not Too Fond Of" , PLURAL_NOUN ] ,
30- [ "Honk For" , PLURAL_NOUN ] ,
31- [ "Canonically Evil" , NOUN ] ,
32- [ "Limited Edition" , NOUN ] ,
33- [ NOUN , "Scientist" ] ,
34- [ "Famous" , NOUN , "Collection" ] ,
35- [ "Supersonic" , NOUN , "Spaceship" ] ,
36- [ "Patent Pending" , NOUN ] ,
37- [ "Patented" , NOUN ] ,
38- [ "Space" , NOUN ] ,
39- [ "Secret" , NOUN , "Agenda" ] ,
40- [ PLURAL_NOUN , "in my walls" ] ,
41- [ "The" , PLURAL_NOUN , "are SPIES" ] ,
42- [ "Traveling" , NOUN , "Circus" ]
43- ]
5+ [ "World Famous" , NOUN ] ,
6+ [ "Comically Large" , NOUN ] ,
7+ [ "Comically Small" , NOUN ] ,
8+ [ "Clearance Aisle" , PLURAL_NOUN ] ,
9+ [ NOUN , "For Hire" ] ,
10+ [ "Suspicious" , NOUN ] ,
11+ [ "Sopping Wet" , PLURAL_NOUN ] ,
12+ [ "Smelly" , NOUN ] ,
13+ [ "Friendly" , NOUN ] ,
14+ [ "Tardy" , NOUN ] ,
15+ [ "Evil" , NOUN ] ,
16+ [ PLURAL_NOUN , "That Bite" ] ,
17+ [ "Malicious" , NOUN ] ,
18+ [ "Spiteful" , NOUN ] ,
19+ [ "Mister" , NOUN ] ,
20+ [ "Alternate" , NOUN , "Universe" ] ,
21+ [ NOUN , "Island" ] ,
22+ [ NOUN , "Kingdom" ] ,
23+ [ NOUN , "Empire" ] ,
24+ [ NOUN , "Dynasty" ] ,
25+ [ NOUN , "Cartel" ] ,
26+ [ NOUN , "Cabal" ] ,
27+ [ "Not Too Fond Of" , PLURAL_NOUN ] ,
28+ [ "Honk For" , PLURAL_NOUN ] ,
29+ [ "Canonically Evil" , NOUN ] ,
30+ [ "Limited Edition" , NOUN ] ,
31+ [ NOUN , "Scientist" ] ,
32+ [ "Famous" , NOUN , "Collection" ] ,
33+ [ "Supersonic" , NOUN , "Spaceship" ] ,
34+ [ "Patent Pending" , NOUN ] ,
35+ [ "Patented" , NOUN ] ,
36+ [ "Space" , NOUN ] ,
37+ [ "Secret" , NOUN , "Agenda" ] ,
38+ [ PLURAL_NOUN , "in my walls" ] ,
39+ [ "The" , PLURAL_NOUN , "are SPIES" ] ,
40+ [ "Traveling" , NOUN , "Circus" ] ,
41+ ] ;
4442
4543const nouns = [
46- "Snail" ,
47- "Cow" ,
48- "Giraffe" ,
49- "Donkey" ,
50- "Horse" ,
51- "Mushroom" ,
52- "Salad" ,
53- "Kitten" ,
54- "Fork" ,
55- "Apple" ,
56- "Pancake" ,
57- "Tree" ,
58- "Fern" ,
59- "Seashell" ,
60- "Turtle" ,
61- "Casserole" ,
62- "Gnome" ,
63- "Frog" ,
64- ]
44+ "Snail" ,
45+ "Cow" ,
46+ "Giraffe" ,
47+ "Donkey" ,
48+ "Horse" ,
49+ "Mushroom" ,
50+ "Salad" ,
51+ "Kitten" ,
52+ "Fork" ,
53+ "Apple" ,
54+ "Pancake" ,
55+ "Tree" ,
56+ "Fern" ,
57+ "Seashell" ,
58+ "Turtle" ,
59+ "Casserole" ,
60+ "Gnome" ,
61+ "Frog" ,
62+ ] ;
6563
6664function isSeedAcceptable ( sanitizedSeed : number ) {
67- let template = names [ sanitizedSeed % names . length ] ;
68- let noun = nouns [ Math . floor ( sanitizedSeed / names . length ) % nouns . length ] ;
65+ const template = names [ sanitizedSeed % names . length ] ;
66+ const noun = nouns [ Math . floor ( sanitizedSeed / names . length ) % nouns . length ] ;
6967
70- let totalLength =
71- template . map ( ( v ) => ( ( v as any ) ?. length ?? 0 ) ) . reduce ( ( a , b ) => a + b )
72- + template . length
73- + noun . length ;
68+ const totalLength =
69+ template . map ( ( v ) => ( v as any ) ?. length ?? 0 ) . reduce ( ( a , b ) => a + b ) +
70+ template . length +
71+ noun . length ;
7472
75- return totalLength <= 26
73+ return totalLength <= 26 ;
7674}
7775/**
7876 * Generate a random username based on a numeric seed
7977 * @param seed - the seed to use to select a username
8078 * @returns a string suitable for a player username
8179 */
82- export function getRandomUsername ( seed : number ) : string {
83- let sanitizedSeed = Math . floor ( ( seed * 2999 ) % ( names . length * nouns . length ) ) ;
84- let template = names [ sanitizedSeed % names . length ] ;
85- let noun = nouns [ Math . floor ( sanitizedSeed / names . length ) % nouns . length ] ;
86- let result : [ string ?] = [ ] ;
80+ export function getRandomUsername ( seed : number ) : string {
81+ let sanitizedSeed = Math . floor ( ( seed * 2999 ) % ( names . length * nouns . length ) ) ;
8782
88- while ( ! isSeedAcceptable ( sanitizedSeed ) ) {
89- sanitizedSeed += 1 ;
90- }
83+ while ( ! isSeedAcceptable ( sanitizedSeed ) ) {
84+ sanitizedSeed += 1 ;
85+ }
9186
92- // Convert template to some somewhat-legible word string
93- for ( let step of template ) {
94- if ( step == PLURAL_NOUN ) {
95- result . push ( `${ noun } s` ) ;
96- } else if ( step == NOUN ) {
97- result . push ( noun ) ;
98- } else {
99- result . push ( step . toString ( ) ) ;
100- }
87+ const template = names [ sanitizedSeed % names . length ] ;
88+ const noun = nouns [ Math . floor ( sanitizedSeed / names . length ) % nouns . length ] ;
89+ const result : [ string ?] = [ ] ;
90+
91+ // Convert template to some somewhat-legible word string
92+ for ( const step of template ) {
93+ if ( step === PLURAL_NOUN ) {
94+ result . push ( `${ noun } s` ) ;
95+ } else if ( step === NOUN ) {
96+ result . push ( noun ) ;
97+ } else {
98+ result . push ( step . toString ( ) ) ;
10199 }
100+ }
102101
103- return result . join ( " " )
104- }
102+ return result . join ( " " ) ;
103+ }
0 commit comments