DEV Community

Ephriam Henderson
Ephriam Henderson

Posted on

Day 8 [D&D Character Sheets]

Report

I missed yesterday! Unfortunately I felt ill all day. I made it through work(remote now) but afterwards I couldn't do anything but lie down. So no code yesterday... Today I got back at it though and coded for a little longer than usual.

I added character entry to my seeder so I could begin designing my character sheet page, started that character sheet design, and learned a few thing about sass.

When I was writing my seeder I realized that my character entry is pretty huge, I've worked with large complex objects from APIs before , but this may be first time I've had to write something with this many keys. Most of the time my tables only consist of a few columns, And those columns don't usually have nested data in them! Through the whole process of writing this I was checking the schema to remember what keys existed and there are even more fields to add! This made me wonder how I could make this less tedious to write.

// db/seeder.js
mongoose.model("Race", require("./models/race"));
mongoose.model("Class", require("./models/class"));
mongoose.model("Character", require("./models/character"))
mongoose.model("Player", require("./models/player"))

mongoose
    .connect(dbConfig.CONNECTION_URL, {
        useNewUrlParser: true,
        useUnifiedTopology: true
    })
    .then(async db => {
        const seedData = require("./seedData.json");
        await db.models.Race.create(seedData.races);
        await db.models.Class.create(seedData.classes);

        const elf = await db.models.Race.findOne({name: "Elf"})
        const player = await db.models.Player.create({
            username: "admin",
            email: "ephriamhenderson@ephriamhenderson.dev",
            password: 'password'
        })
        await db.models.Character.create({
            shortName: "Aria",
            longName: "Aria Wyndsong",
            race: elf.id,
            "class": await db.models.Class.findOne({name: "Warlock"}).id,
            player: player.id,
            description: "Aria is awesome.",
            age: 72,
            urlSlug: "",
            stats: {
                abilities: {
                    strength: 10,
                    dexterity: 12,
                    constitution: 10,
                    intelligence: 13,
                    wisdom: 14,
                    charisma: 16,
                },
                skills: {
                    acrobatics: {
                        skill: {
                            proficiency: false,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    animalHandling: {
                        skill: {
                            proficiency: false,
                            value: 2,
                            additionalModifiers: []
                        }
                    },
                    arcana: {
                        skill: {
                            proficiency: true,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    athletics: {
                        skill: {
                            proficiency: false,
                            value: 0,
                            additionalModifiers: []
                        }
                    },
                    deception: {
                        skill: {
                            proficiency: false,
                            value: 3,
                            additionalModifiers: []
                        }
                    },
                    history: {
                        skill: {
                            proficiency: true,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    insight: {
                        skill: {
                            proficiency: true,
                            value: 2,
                            additionalModifiers: []
                        }
                    },
                    intimidation: {
                        skill: {
                            proficiency: false,
                            value: 3,
                            additionalModifiers: []
                        }
                    },
                    acrobatics: {
                        skill: {
                            proficiency: false,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    investigation: {
                        skill: {
                            proficiency: true,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    medicine: {
                        skill: {
                            proficiency: false,
                            value: 2,
                            additionalModifiers: []
                        }
                    },
                    perception: {
                        skill: {
                            proficiency: true,
                            value: 2,
                            additionalModifiers: []
                        }
                    },
                    persuasion: {
                        skill: {
                            proficiency: false,
                            value: 3,
                            additionalModifiers: []
                        }
                    },
                    religion: {
                        skill: {
                            proficiency: false,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    sleightOfHand: {
                        skill: {
                            proficiency: false,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    stealth: {
                        skill: {
                            proficiency: false,
                            value: 1,
                            additionalModifiers: []
                        }
                    },
                    survival: {
                        skill: {
                            proficiency: false,
                            value: 2,
                            additionalModifiers: []
                        }
                    }
                },
                speed: elf.stats.speed,
                proficiencyBonus: 2
            }
        })
        return db;
    })
    .then(db => {
        db.disconnect();
    });

Creating a class that could create these objects with less direct inputs for me. Much of the skills section could be generated with class methods. The problem is that it'd be another thing to maintain along with the schema.

I did some searching in the mongoose docs figuring that there was probably a way to do what what I wanted with the mongoose schema. Turns out you can use functions as values and write setters and getters into your schema. By checking the docs hopefully I'll have saved myself some time and complexity. Tomorrow's code snippet will be those additions to the character schema.

Project

[100days] The DND Character Sheet App

This is the first project of my 100 days of coding This is an app to keep D&D character sheets.

Stack

I'll be using Node.js and building a full-stack Express app with MongoDB.

Requirements

Minimum Viable

  • Present a D&D Character Sheet
    • The sheet should display all the same info as the first page of the 5e Official sheet.
  • Users should be able to log in and create player-characters.
  • Users should be able to edit character sheets.
  • Users should be able to organize character sheets into groups (parties/tables)
  • Sheets should auto calculate basic stats like ability modifiers
    • Support Proficiency Bonuses

Cake

  • Extend character creation to allow the user to use any of the three common stat gen methods
    • Point Buy
    • Standard Array
    • Roll
  • Extend the character sheet to all the info in the 5e official sheet.
  • Allow for image uploads for character portraits.
  • Allow for…

The First project will be an app to keep D&D character sheets.

Stack

I'll be using Node.js and building a full-stack Express app with MongoDB.

Requirements

Minimum Viable

  • [ ] Investigate automating or finding a source of info for the data in the SRD.
  • [ ] Present a D&D Character Sheet
    • [ ] The sheet should display all the same info as the first page of the 5e Official sheet.
  • [ ] Users should be able to log in and create player-characters.
  • [ ] Users should be able to edit character sheets.
  • [ ] Users should be able to organize character sheets into groups (parties/tables)
  • [ ] Sheets should auto calculate basic stats like ability modifiers.
    • [ ] Support Proficiency Bonuses

Cake

  • [ ] Extend character creation to allow the user to use any of the three common stat gen methods.
    • [ ] Point Buy
    • [ ] Standard Array
    • [ ] Roll
  • [ ] Extend the character sheet to all the info in the 5e official sheet.
  • [ ] Allow for image uploads for character portraits.
  • [ ] Allow for extended descriptions/backstories.
    • [ ] Characters should have nice full page backstories.
    • [ ] Preferably use a markdown editor.

Top comments (0)