Skip to content

Commit

Permalink
[#342] Add race type
Browse files Browse the repository at this point in the history
  • Loading branch information
arbron committed Jul 21, 2023
1 parent 64a4270 commit 350268d
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 9 deletions.
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"ITEM.TypeFeaturePl": "Features",
"ITEM.TypeLoot": "Loot",
"ITEM.TypeLootPl": "Loot",
"ITEM.TypeRace": "Race",
"ITEM.TypeRacePl": "Races",
"ITEM.TypeSpell": "Spell",
"ITEM.TypeSpellPl": "Spells",
"ITEM.TypeSubclass": "Subclass",
Expand Down Expand Up @@ -866,6 +868,7 @@
"DND5E.PropertyTotal": "Total",
"DND5E.Quantity": "Quantity",
"DND5E.Race": "Race",
"DND5E.RaceName": "Race Name",
"DND5E.RacialTraits": "Racial Traits",
"DND5E.Range": "Range",
"DND5E.RangeDistance": "Distance",
Expand Down
9 changes: 7 additions & 2 deletions module/applications/actor/character-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class ActorSheet5eCharacter extends ActorSheet5e {
}

// Partition items by category
let {items, spells, feats, backgrounds, classes, subclasses} = context.items.reduce((obj, item) => {
let {items, spells, feats, races, backgrounds, classes, subclasses} = context.items.reduce((obj, item) => {
const {quantity, uses, recharge, target} = item.system;

// Item details
Expand Down Expand Up @@ -89,12 +89,13 @@ export default class ActorSheet5eCharacter extends ActorSheet5e {
// Classify items into types
if ( item.type === "spell" ) obj.spells.push(item);
else if ( item.type === "feat" ) obj.feats.push(item);
else if ( item.type === "race" ) obj.races.push(item);
else if ( item.type === "background" ) obj.backgrounds.push(item);
else if ( item.type === "class" ) obj.classes.push(item);
else if ( item.type === "subclass" ) obj.subclasses.push(item);
else if ( Object.keys(inventory).includes(item.type) ) obj.items.push(item);
return obj;
}, { items: [], spells: [], feats: [], backgrounds: [], classes: [], subclasses: [] });
}, { items: [], spells: [], feats: [], races: [], backgrounds: [], classes: [], subclasses: [] });

// Apply active item filters
items = this._filterItems(items, this._filters.inventory);
Expand Down Expand Up @@ -140,6 +141,9 @@ export default class ActorSheet5eCharacter extends ActorSheet5e {

// Organize Features
const features = {
race: {
label: "ITEM.TypeRace", items: races,
hasActions: false, dataset: {type: "race"} },
background: {
label: CONFIG.Item.typeLabels.background, items: backgrounds,
hasActions: false, dataset: {type: "background"} },
Expand All @@ -164,6 +168,7 @@ export default class ActorSheet5eCharacter extends ActorSheet5e {
context.spellbook = spellbook;
context.preparedSpells = nPrepared;
context.features = Object.values(features);
context.labels.race = races[0]?.name;
context.labels.background = backgrounds[0]?.name;
}

Expand Down
3 changes: 3 additions & 0 deletions module/data/item/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ContainerData from "./container.mjs";
import EquipmentData from "./equipment.mjs";
import FeatData from "./feat.mjs";
import LootData from "./loot.mjs";
import RaceData from "./race.mjs";
import SpellData from "./spell.mjs";
import SubclassData from "./subclass.mjs";
import ToolData from "./tool.mjs";
Expand All @@ -18,6 +19,7 @@ export {
EquipmentData,
FeatData,
LootData,
RaceData,
SpellData,
SubclassData,
ToolData,
Expand All @@ -38,6 +40,7 @@ export const config = {
equipment: EquipmentData,
feat: FeatData,
loot: LootData,
race: RaceData,
spell: SpellData,
subclass: SubclassData,
tool: ToolData,
Expand Down
20 changes: 20 additions & 0 deletions module/data/item/race.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import SystemDataModel from "../abstract.mjs";
import { AdvancementField, IdentifierField } from "../fields.mjs";
import ItemDescriptionTemplate from "./templates/item-description.mjs";

/**
* Data definition for Race items.
* @mixes ItemDescriptionTemplate
*
* @property {string} identifier Identifier slug for this race.
* @property {object[]} advancement Advancement objects for this race.
*/
export default class RaceData extends SystemDataModel.mixin(ItemDescriptionTemplate) {
/** @inheritdoc */
static defineSchema() {
return this.mergeSchema(super.defineSchema(), {
identifier: new IdentifierField({required: true, label: "DND5E.Identifier"}),
advancement: new foundry.data.fields.ArrayField(new AdvancementField(), {label: "DND5E.AdvancementTitle"})
});
}
}
2 changes: 1 addition & 1 deletion module/documents/advancement/advancement.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Advancement extends BaseAdvancement {
title: game.i18n.localize("DND5E.AdvancementTitle"),
hint: "",
multiLevel: false,
validItemTypes: new Set(["background", "class", "subclass"]),
validItemTypes: new Set(["background", "class", "race", "subclass"]),
apps: {
config: AdvancementConfig,
flow: AdvancementFlow
Expand Down
2 changes: 1 addition & 1 deletion module/documents/advancement/item-choice.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class ItemChoiceAdvancement extends ItemGrantAdvancement {

/** @inheritdoc */
get levels() {
return Array.from(Object.keys(this.configuration.choices));
return Array.from(Object.keys(this.configuration.choices).map(l => Number(l)));
}

/* -------------------------------------------- */
Expand Down
7 changes: 6 additions & 1 deletion template.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
}
},
"Item": {
"types": ["weapon", "equipment", "consumable", "tool", "loot", "background", "class", "subclass", "spell", "feat", "backpack"],
"types": ["weapon", "equipment", "consumable", "tool", "loot", "race", "background", "class", "subclass", "spell", "feat", "backpack"],
"templates": {
"itemDescription": {
"description": {
Expand Down Expand Up @@ -676,6 +676,11 @@
"proficient": null,
"bonus": ""
},
"race": {
"templates": ["itemDescription"],
"identifier": "",
"advancement": []
},
"spell": {
"templates": ["itemDescription", "activatedEffect", "action"],
"level": 1,
Expand Down
10 changes: 8 additions & 2 deletions templates/actors/character-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@
{{!-- Character Summary --}}
<ul class="summary flexrow">
<li class="race">
<input type="text" name="system.details.race" value="{{system.details.race}}" placeholder="{{ localize 'DND5E.Race' }}"/>
{{#if labels.race}}
<span data-tooltip="DND5E.Race">{{labels.race}}</span>
{{else}}
<input type="text" name="system.details.race" value="{{system.details.race}}"
placeholder="{{ localize 'DND5E.Race' }}"/>
{{/if}}
</li>
<li class="background">
{{#if labels.background}}
<span data-tooltip="DND5E.Background">{{labels.background}}</span>
{{else}}
<input type="text" name="system.details.background" value="{{system.details.background}}" placeholder="{{ localize 'DND5E.Background' }}"/>
<input type="text" name="system.details.background" value="{{system.details.background}}"
placeholder="{{ localize 'DND5E.Background' }}"/>
{{/if}}
</li>
<li class="alignment">
Expand Down
4 changes: 2 additions & 2 deletions templates/advancement/item-choice-config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@

<div class="right-column level-list">
<p class="hint">{{localize "DND5E.AdvancementItemChoiceLevelsHint"}}</p>
{{#each levels as |level|}}
{{#each levels as |label level|}}
<div class="form-group">
<label>{{level}}</label>
<label>{{label}}</label>
<div class="form-fields">
{{numberInput (lookup ../configuration.choices level) placeholder="0"
name=(concat "configuration.choices." level) min=1 step=1}}
Expand Down
43 changes: 43 additions & 0 deletions templates/items/race.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<form class="{{cssClass}} flexcol" autocomplete="off">
{{!-- Item Sheet Header --}}
<header class="sheet-header flexrow">
<img class="profile" src="{{item.img}}" title="{{item.name}}" data-edit="img">

<div class="header-details flexrow">
<h1 class="charname">
<input name="name" type="text" value="{{item.name}}" placeholder="{{localize 'DND5E.RaceName'}}">
</h1>

<div class="item-subtitle">
<h4 class="item-type">{{itemType}}</h4>
<span class="item-status">{{itemStatus}}</span>
</div>

<ul class="summary flexrow">
<li>
<input type="text" name="system.source" value="{{system.source}}" placeholder="{{localize 'DND5E.Source'}}">
</li>
</ul>
</div>
</header>

{{!-- Item Sheet Navigation --}}
<nav class="sheet-navigation tabs" data-group="primary">
<a class="item active" data-tab="description">{{localize "DND5E.Description"}}</a>
<a class="item" data-tab="advancement">{{localize "DND5E.AdvancementTitle"}}</a>
</nav>

{{!-- Item Sheet Body --}}
<section class="sheet-body">

{{!-- Description Tab --}}
<div class="tab flexrow active" data-group="primary" data-tab="description">
{{editor descriptionHTML target="system.description.value" button=true editable=editable
engine="prosemirror" collaborate=false}}
</div>

{{!-- Advancement Tab --}}
{{> "dnd5e.item-advancement"}}

</section>
</form>

0 comments on commit 350268d

Please sign in to comment.