Skip to content

Commit

Permalink
[#342] Add creature type handling, set default creature type on chara…
Browse files Browse the repository at this point in the history
…cters
  • Loading branch information
arbron committed Nov 7, 2023
1 parent 7f404b4 commit 35b7293
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion module/applications/actor/base-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ export default class ActorSheet5e extends ActorSheet {
try {
const shouldRemoveAdvancements = await AdvancementConfirmationDialog.forDelete(item);
if ( shouldRemoveAdvancements ) return manager.render(true);
else return item.delete({ shouldRemoveAdvancements });
return item.delete({ shouldRemoveAdvancements });
} catch(err) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion module/data/actor/character.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class CharacterData extends CreatureTemplate {
required: true, fallback: true, label: "DND5E.Background"
}),
originalClass: new foundry.data.fields.StringField({required: true, label: "DND5E.ClassOriginal"}),
type: new CreatureTypeField({ swarm: false }),
type: new CreatureTypeField({ swarm: false }, { initial: { value: "humanoid" }}),
xp: new foundry.data.fields.SchemaField({
value: new foundry.data.fields.NumberField({
required: true, nullable: false, integer: true, min: 0, initial: 0, label: "DND5E.ExperiencePointsCurrent"
Expand Down
12 changes: 8 additions & 4 deletions module/data/item/race.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ export default class RaceData extends SystemDataModel.mixin(ItemDescriptionTempl
}
}
if ( this.senses.special ) {
updates[system.attributes.senses.special] = attributes.senses.special
? `${attributes.senses.special}:${this.senses.special}` : this.senses.special;
updates[system.attributes.senses.special] = [attributes.senses.special, this.senses.special].filterJoin(";");
}
updates["system.attributes.senses.units"] = this.senses.units;

// TODO: Set creature type once defined on actor
if ( this.type.value ) updates["system.details.type.value"] = this.type.value;
if ( this.type.subtype ) updates["system.details.type.subtype"] = this.type.subtype;
if ( this.type.custom ) updates["system.details.type.custom"] = this.type.custom;

this.parent.actor.update(updates);
}
Expand Down Expand Up @@ -148,7 +149,10 @@ export default class RaceData extends SystemDataModel.mixin(ItemDescriptionTempl
updates[system.attributes.senses.special] = attributes.senses.special.replace(this.senses.special, "");
}

// TODO: Unset creature type once defined on actor
const type = this.parent.actor.system.details.type;
if ( this.type.value === type.value ) updates["system.details.type.value"] = "humanoid";
if ( this.type.subtype === type.subtype ) updates["system.details.type.subtype"] = "";
if ( this.type.custom === type.custom ) updates["system.details.type.custom"] = "";

await this.parent.actor.update(updates);
}
Expand Down

0 comments on commit 35b7293

Please sign in to comment.