Skip to content

Commit

Permalink
14 Adds Shadowdark character name
Browse files Browse the repository at this point in the history
  • Loading branch information
riccjohn committed Feb 22, 2023
1 parent 8d9dcea commit 0e317fd
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/shadowdark/ShadowdarkCharacter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ShadowdarkCharacter from './ShadowdarkCharacter'
import { Dice } from '@/dice'
import { names } from './data'

describe('ShadowdarkCharacter', () => {
describe('initialization', () => {
Expand Down Expand Up @@ -147,7 +147,17 @@ describe('ShadowdarkCharacter', () => {
expect(humanCharacters.every( character => character.languages.length === 2)).toBeTruthy()
})
})

test('assigns a name based on the race', () => {
const character = new ShadowdarkCharacter()
character.generate()

const characterRace = character.race.name.toLowerCase()
const allNames: Record<string, string[]> = names

expect(allNames[characterRace].includes(character.name)).toBeTruthy()
})
})
})
})
})
Expand Down
19 changes: 14 additions & 5 deletions src/shadowdark/ShadowdarkCharacter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dice } from '@/dice'
import { expandObjectKeys } from '@/helpers'
import { abilityModifiers, languages as allLanguages, races } from './data'
import { abilityModifiers, languages as allLanguages, races, names } from './data'
class ShadowdarkCharacter {
private abilities: IShadowdarkAbilities = {
strength: { score: 10, modifier: 0 },
Expand All @@ -13,10 +13,10 @@ class ShadowdarkCharacter {

public race: IShadowdarkRace = {} as IShadowdarkRace
public languages: string[] = []
constructor() {}
public name: string = ''

public generate = () => {
this.abilities = this.generateAbilityScores()
this.generateAbilityScores()
this.generateRace()
}

Expand Down Expand Up @@ -48,7 +48,7 @@ class ShadowdarkCharacter {
return this.abilities.wisdom
}

private generateAbilityScores = (): IShadowdarkAbilities => {
private generateAbilityScores = (): void => {
const abilityScoreRolls = this.rollAbilityScores()

const abilityModifiersMap = expandObjectKeys(abilityModifiers)
Expand All @@ -65,7 +65,7 @@ class ShadowdarkCharacter {
const [strength, dexterity, constitution, intelligence, wisdom, charisma] =
abilitiesWithModifiers

return {
this.abilities = {
strength,
dexterity,
constitution,
Expand All @@ -83,6 +83,15 @@ class ShadowdarkCharacter {

this.languages = languages
this.race = race
this.name = this.rollName(race)
}

private rollName = (race: IShadowdarkRace): string => {
const raceName = (race.name as string).toLowerCase()
const namesByRace: Record<string, string[]> = names
const namesForRace = namesByRace[raceName]

return namesForRace[Dice.roll(namesForRace.length - 1)]
}

private determineLanguages = (race: IShadowdarkRace): string[] => {
Expand Down
5 changes: 3 additions & 2 deletions src/shadowdark/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as abilityModifiers } from "./abilityModifiers.json"
export { default as races } from "./races.json"
export { default as abilityModifiers } from './abilityModifiers.json'
export { default as languages } from './languages.json'
export { default as names } from './names.json'
export { default as races } from "./races.json"
134 changes: 134 additions & 0 deletions src/shadowdark/data/names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"dwarf": [
"Hilde",
"Torbin",
"Marga",
"Bruno",
"Karina",
"Naugrim",
"Brenna",
"Darvin",
"Elga",
"Alric",
"Isolde",
"Gendry",
"Bruga",
"Junnor",
"Vidrid",
"Torson",
"Brielle",
"Ulfgar",
"Sarna",
"Grimm"
],
"elf": [
"Eliara",
"Ryarn",
"Sariel",
"Tirolas",
"Galira",
"Varos",
"Daeniel",
"Axidor",
"Hiralia",
"Cyrwin",
"Lothiel",
"Zaphiel",
"Nayra",
"Ithior",
"Amriel",
"Elyon",
"Jirwyn",
"Natinel",
"Fiora",
"Ruhiel"
],
"goblin": [
"Iggs",
"Tark",
"Nix",
"Lenk",
"Roke",
"Fitz",
"Tila",
"Riggs",
"Prim",
"Zeb",
"Finn",
"Borg",
"Yark",
"Deeg",
"Nibs",
"Brak",
"Fink",
"Rizzo",
"Squib",
"Grix"
],
"halfling": [
"Willow",
"Benny",
"Annie",
"Tucker",
"Marie",
"Hobb",
"Cora",
"Gordie",
"Rose",
"Ardo",
"Alma",
"Norbert",
"Jennie",
"Barvin",
"Tilly",
"Pike",
"Lydia",
"Marlow",
"Astrid",
"Jasper"
],
"half-orc": [
"Vara",
"Gralk",
"Ranna",
"Korv",
"Zasha",
"Hrogar",
"Klara",
"Tragan",
"Brolga",
"Drago",
"Yelena",
"Krull",
"Ulara",
"Tulk",
"Shiraal",
"Wulf",
"Ivara",
"Hirok",
"Aja",
"Zoraan"
],
"human": [
"Zali",
"Bram",
"Clara",
"Nattias",
"Rina",
"Denton",
"Mirena",
"Aran",
"Morgan",
"Giralt",
"Tamra",
"Oscar",
"Ishana",
"Rogar",
"Jasmin",
"Tarin",
"Yuri",
"Malchor",
"Lienna",
"Godfrey"
]
}

1 comment on commit 0e317fd

@vercel
Copy link

@vercel vercel bot commented on 0e317fd Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

osr-tools – ./

osr-tools-git-main-riccjohn.vercel.app
osr-tools.vercel.app
osr-tools-riccjohn.vercel.app

Please sign in to comment.