Skip to content

Commit

Permalink
D&D5E System Release 0.86
Browse files Browse the repository at this point in the history
  • Loading branch information
aaclayton committed Apr 2, 2020
1 parent c9ab646 commit 985eea4
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 445 deletions.
21 changes: 17 additions & 4 deletions dnd5e.css
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,12 @@
.dnd5e.sheet.actor .inventory-list .item .item-name h4 {
margin: 0;
}
.dnd5e.sheet.actor .inventory-list .item .item-name:hover .item-image {
background-image: url("/icons/svg/d20-grey.svg") !important;
}
.dnd5e.sheet.actor .inventory-list .item .item-name .item-image:hover {
.dnd5e.sheet.actor .inventory-list .item .item-name.rollable .item-image:hover {
background-image: url("/icons/svg/d20-black.svg") !important;
}
.dnd5e.sheet.actor .inventory-list .item .item-name.rollable:hover .item-image {
background-image: url("/icons/svg/d20-grey.svg") !important;
}
.dnd5e.sheet.actor .inventory-list .item .item-name i.attuned {
color: #7a7971;
}
Expand Down Expand Up @@ -856,6 +856,19 @@
text-align: center;
border-right: 1px solid #c9c7b8;
}
.dnd5e.sheet.actor .spell-component {
line-height: 14px;
}
.dnd5e.sheet.actor .spell-component.C,
.dnd5e.sheet.actor .spell-component.R {
display: inline-block;
padding-top: 1px;
width: 16px;
color: #c9c7b8;
background: rgba(0, 0, 0, 0.4);
border: 1px solid transparent;
border-radius: 8px;
}
.dnd5e.sheet.actor .spellbook-empty .item-controls {
flex: 1;
}
Expand Down
18 changes: 15 additions & 3 deletions dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Hooks.once("setup", function() {
const toLocalize = [
"abilities", "alignments", "conditionTypes", "consumableTypes", "currencies", "damageTypes", "distanceUnits", "equipmentTypes",
"healingTypes", "itemActionTypes", "limitedUsePeriods", "senses", "skills", "spellComponents", "spellLevels", "spellPreparationModes",
"spellSchools", "spellScalingModes", "targetTypes", "timePeriods", "weaponProperties", "weaponTypes", "languages"
"spellSchools", "spellScalingModes", "targetTypes", "timePeriods", "weaponProperties", "weaponTypes", "languages", "polymorphSettings"
];
for ( let o of toLocalize ) {
CONFIG.DND5E[o] = Object.entries(CONFIG.DND5E[o]).reduce((obj, e) => {
Expand All @@ -90,9 +90,21 @@ Hooks.once("setup", function() {
* Once the entire VTT framework is initialized, check to see if we should perform a data migration
*/
Hooks.once("ready", function() {

// Determine whether a system migration is required and feasible
const currentVersion = game.settings.get("dnd5e", "systemMigrationVersion");
const NEEDS_MIGRATION_VERSION = 0.84;
let needMigration = game.settings.get("dnd5e", "systemMigrationVersion") < NEEDS_MIGRATION_VERSION;
if ( needMigration && game.user.isGM ) migrations.migrateWorld();
const COMPATIBLE_MIGRATION_VERSION = 0.80;
let needMigration = (currentVersion < NEEDS_MIGRATION_VERSION) || (currentVersion === null);
const canMigrate = currentVersion >= COMPATIBLE_MIGRATION_VERSION;

// Perform the migration
if ( needMigration && game.user.isGM ) {
if ( !canMigrate ) {
ui.notifications.error(`Your D&D5E system data is from too old a Foundry version and cannot be reliably migrated to the latest version. The process will be attempted, but errors may occur.`, {permanent: true});
}
migrations.migrateWorld();
}

// Wait to register hotbar drop hook on ready so that modules could register earlier if they want to
Hooks.on("hotbarDrop", (bar, data, slot) => create5eMacro(data, slot));
Expand Down
22 changes: 17 additions & 5 deletions less/actors.less
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,12 @@
margin: 0;
}

&:hover .item-image {
background-image: url("/icons/svg/d20-grey.svg") !important;
}

.item-image:hover {
&.rollable .item-image:hover {
background-image: url("/icons/svg/d20-black.svg") !important;
}
&.rollable:hover .item-image {
background-image: url("/icons/svg/d20-grey.svg") !important;
}

i.attuned {
color: @colorTan;
Expand Down Expand Up @@ -587,6 +586,19 @@
border-right: 1px solid @colorFaint;
}

.spell-component {
line-height: 14px;
&.C, &.R {
display: inline-block;
padding-top: 1px;
width: 16px;
color: @colorFaint;
background: rgba(0, 0, 0, 0.4);
border: 1px solid transparent;
border-radius: 8px;
}
}

// Empty spellbook controls
.spellbook-empty .item-controls { flex: 1; }

Expand Down
53 changes: 23 additions & 30 deletions module/actor/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,40 +731,34 @@ export class Actor5e extends Actor {
return ui.notifications.warn(`You are not allowed to polymorph this actor!`);
}

// Get the original Actor data
// Get the original Actor data and the new source data
const o = duplicate(this.data);
o.flags.dnd5e = o.flags.dnd5e || {};

// Get the source Actor data
const source = duplicate(target.data);
source.flags.dnd5e = source.flags.dnd5e || {};
delete source.flags.dnd5e.isPolymorphed;
delete source.flags.dnd5e.originalActor;

// Prepare new data to merge from the source
const d = {
name: `${o.name} (${source.name})`,
data: source.data,
items: source.items,
token: source.token,
img: source.img,
flags: source.flags
type: o.type, // Remain the same actor type
name: `${o.name} (${source.name})`, // Append the new shape to your old name
data: source.data, // Get the data model of your new form
items: source.items, // Get the items of your new form
token: source.token, // New token configuration
img: source.img, // New appearance
permission: o.permission, // Use the original actor permissions
folder: o.folder, // Be displayed in the same sidebar folder
flags: o.flags // Use the original actor flags
};
delete d.data.resources;
delete d.data.currency;
delete d.data.bonuses;
delete d.token.actorId;

// Merge original data
mergeObject(d, {
"type": o.type, // The new actor must be of the same type
"token.actorLink": o.token.actorLink,
"token.name": d.name,
"folder": o.folder,
"data.details.alignment": o.data.details.alignment,
"data.attributes.exhaustion": o.data.attributes.exhaustion,
"data.attributes.inspiration": o.data.attributes.inspiration
});

// Additional adjustments
delete d.data.resources; // Don't change your resource pools
delete d.data.currency; // Don't lose currency
delete d.data.bonuses; // Don't lose global bonuses
delete d.token.actorId; // Don't reference the old actor ID
d.token.actorLink = o.token.actorLink; // Keep your actor link
d.token.name = d.name; // Token name same as actor name
d.data.details.alignment = o.data.details.alignment; // Don't change alignment
d.data.attributes.exhaustion = o.data.attributes.exhaustion; // Keep your prior exhaustion level
d.data.attributes.inspiration = o.data.attributes.inspiration; // Keep inspiration

// Keep Token configurations
const tokenConfig = ["displayName", "vision", "actorLink", "disposition", "displayBars", "bar1", "bar2"];
Expand Down Expand Up @@ -809,9 +803,8 @@ export class Actor5e extends Actor {
if (keepVision) d.data.traits.senses = o.data.traits.senses;

// Set new data flags
if ( !this.isPolymorphed || !d.flags.dnd5e.originalActor ) d.flags.dnd5e.originalActor = this.id;
d.flags.dnd5e.isPolymorphed = true;
if (o.flags.dnd5e.isPolymorphed) d.flags.dnd5e.originalActor = o.flags.dnd5e.originalActor;
else d.flags.dnd5e.originalActor = o._id;

// Update unlinked Tokens in place since they can simply be re-dropped from the base actor
if (this.isToken) {
Expand Down Expand Up @@ -875,7 +868,7 @@ export class Actor5e extends Actor {

// Delete the polymorphed Actor and maybe re-render the original sheet
const isRendered = this.sheet.rendered;
await this.delete();
if ( game.user.isGM ) await this.delete();
original.sheet.render(isRendered);
return original;
}
Expand Down
7 changes: 6 additions & 1 deletion module/actor/sheets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ export class ActorSheet5e extends ActorSheet {
html.find('.item .item-recharge').click(event => this._onItemRecharge(event));
}

// Otherwise remove rollable classes
else {
html.find(".rollable").each((i, el) => el.classList.remove("rollable"));
}

// Handle default listeners last so system listeners are triggered first
super.activateListeners(html);
}
Expand Down Expand Up @@ -396,7 +401,7 @@ export class ActorSheet5e extends ActorSheet {

// Handle a polymorph
if (data && (data.type === "Actor")) {
if (game.user.isGM || (game.settings.get('dnd5e', 'allowPolymorphing') && this.owner)) {
if (game.user.isGM || (game.settings.get('dnd5e', 'allowPolymorphing') && this.actor.owner)) {
return this._onDropPolymorph(event, data);
}
}
Expand Down
4 changes: 1 addition & 3 deletions module/actor/sheets/npc.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ export class ActorSheet5eNPC extends ActorSheet5e {
if ( item.data.activation.type ) features.actions.items.push(item);
else features.passive.items.push(item);
}
else if (["equipment", "consumable", "tool", "loot"].includes(item.type)) {
features.equipment.items.push(item);
}
else features.equipment.items.push(item);
}

// Assign and return
Expand Down
2 changes: 1 addition & 1 deletion module/apps/ability-use-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AbilityUseDialog extends Dialog {
uses: uses,
recharges: !!recharge.value,
isCharged: recharge.charged,
hasPlaceableTemplate: game.user.isTrusted && item.hasAreaTarget,
hasPlaceableTemplate: game.user.can("TEMPLATE_CREATE") && item.hasAreaTarget,
perLabel: CONFIG.DND5E.limitedUsePeriods[uses.per]
});

Expand Down
2 changes: 1 addition & 1 deletion module/apps/spell-cast-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class SpellCastDialog extends Dialog {
canCast: canCast,
canUpcast: canUpcast,
spellLevels,
hasPlaceableTemplate: game.user.isTrusted && item.hasAreaTarget
hasPlaceableTemplate: game.user.can("TEMPLATE_CREATE") && item.hasAreaTarget
});

// Create the Dialog and return as a Promise
Expand Down
8 changes: 5 additions & 3 deletions module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ export class Item5e extends Item {
if ( itemData.type === "spell" ) {
labels.level = C.spellLevels[data.level];
labels.school = C.spellSchools[data.school];
labels.components = Object.entries(data.components).map(c => {
c[1] === true ? c[0].titleCase().slice(0,1) : null
}).filterJoin(",");
labels.components = Object.entries(data.components).reduce((arr, c) => {
if ( c[1] !== true ) return arr;
arr.push(c[0].titleCase().slice(0, 1));
return arr;
}, []);
}

// Feat Items
Expand Down
Loading

0 comments on commit 985eea4

Please sign in to comment.