diff --git a/devNotes/twine JS.txt b/devNotes/twine JS.txt index 22737f700c0463accd88153c61f7c16e18528a0a..e7f362055c6c0cedc90670fb4f74a1954b0bfdf5 100644 --- a/devNotes/twine JS.txt +++ b/devNotes/twine JS.txt @@ -26213,28 +26213,33 @@ window.nationalityToRace = function nationalityToRace(slave) { slave.race = hashChoice(setup.raceSelector[slave.nationality] || setup.raceSelector[""]); }; +window.generateName = function generateName(nationality, race, male) { + const lookup = (male ? setup.malenamePoolSelector : setup.namePoolSelector); + const result = jsEither( + lookup[nationality + "." + race] || lookup[nationality] || + (male ? setup.whiteAmericanMaleNames : setup.whiteAmericanSlaveNames)); + /* fallback for males without specific male name sets: return female name */ + if(male && !result) { + return generateName(nationality, race, false); + } + return result; +}; + +window.generateSurname = function generateSurname(nationality, race, male) { + const result = jsEither( + setup.surnamePoolSelector[nationality + "." + race] || + setup.surnamePoolSelector[nationality] || + setup.whiteAmericanSlaveSurnames); + /* TODO: Look up male alternatives if male == true */ + return result || 0; +}; + window.nationalityToName = function nationalityToName(slave) { const V = State.variables; const male = (slave.genes === "XY"); - if(male) { - /* try male pools first */ - slave.birthName = - jsEither(setup.malenamePoolSelector[slave.nationality + "." + slave.race] || - setup.malenamePoolSelector[slave.nationality] || - setup.whiteAmericanMaleNames); - } - if(!male || !slave.birthName) { - /* not male, or male names not defined yet */ - slave.birthName = - jsEither(setup.namePoolSelector[slave.nationality + "." + slave.race] || - setup.namePoolSelector[slave.nationality] || - setup.whiteAmericanSlaveNames); - } - slave.birthSurname = - jsEither(setup.surnamePoolSelector[slave.nationality + "." + slave.race] || - setup.surnamePoolSelector[slave.nationality] || - setup.whiteAmericanSlaveSurnames); + slave.birthName = generateName(slave.nationality, slave.race, male); + slave.birthSurname = generateSurname(slave.nationality, slave.race, male); slave.slaveName = slave.birthName; slave.slaveSurname = slave.birthSurname; if (V.useFSNames === 1) { diff --git a/src/js/slaveGenerationJS.tw b/src/js/slaveGenerationJS.tw index 36bbd5905bb83d870902e92dea2d48ad4869ce43..18b3394a497622f1f8288c0074385d4e254c544c 100644 --- a/src/js/slaveGenerationJS.tw +++ b/src/js/slaveGenerationJS.tw @@ -48,28 +48,33 @@ window.nationalityToRace = function nationalityToRace(slave) { slave.race = hashChoice(setup.raceSelector[slave.nationality] || setup.raceSelector[""]); }; +window.generateName = function generateName(nationality, race, male) { + const lookup = (male ? setup.malenamePoolSelector : setup.namePoolSelector); + const result = jsEither( + lookup[nationality + "." + race] || lookup[nationality] || + (male ? setup.whiteAmericanMaleNames : setup.whiteAmericanSlaveNames)); + /* fallback for males without specific male name sets: return female name */ + if(male && !result) { + return generateName(nationality, race, false); + } + return result; +}; + +window.generateSurname = function generateSurname(nationality, race, male) { + const result = jsEither( + setup.surnamePoolSelector[nationality + "." + race] || + setup.surnamePoolSelector[nationality] || + setup.whiteAmericanSlaveSurnames); + /* TODO: Look up male alternatives if male == true */ + return result || 0; +}; + window.nationalityToName = function nationalityToName(slave) { const V = State.variables; const male = (slave.genes === "XY"); - if(male) { - /* try male pools first */ - slave.birthName = - jsEither(setup.malenamePoolSelector[slave.nationality + "." + slave.race] || - setup.malenamePoolSelector[slave.nationality] || - setup.whiteAmericanMaleNames); - } - if(!male || !slave.birthName) { - /* not male, or male names not defined yet */ - slave.birthName = - jsEither(setup.namePoolSelector[slave.nationality + "." + slave.race] || - setup.namePoolSelector[slave.nationality] || - setup.whiteAmericanSlaveNames); - } - slave.birthSurname = - jsEither(setup.surnamePoolSelector[slave.nationality + "." + slave.race] || - setup.surnamePoolSelector[slave.nationality] || - setup.whiteAmericanSlaveSurnames); + slave.birthName = generateName(slave.nationality, slave.race, male); + slave.birthSurname = generateSurname(slave.nationality, slave.race, male); slave.slaveName = slave.birthName; slave.slaveSurname = slave.birthSurname; if (V.useFSNames === 1) {