Skip to content

Commit

Permalink
Merge pull request #29 from crash1115/dev
Browse files Browse the repository at this point in the history
v0.4.5 - Patching Foundry 0.7.x
  • Loading branch information
crash1115 authored Sep 29, 2020
2 parents 13c9c01 + 3b61afd commit 64de048
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
![GitHub All Releases](https://img.shields.io/github/downloads/crash1115/5e-training/total) ![GitHub Releases](https://img.shields.io/github/downloads/crash1115/5e-training/latest/total) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/crash1115/5e-training?label=latest%20version)

WARNING: Using versions of this module lower than 0.4.5 with versions of Foundry above 0.7.0 can result in PERMANENT loss of downtime activities. If you're upgrading to Foundry 0.7.x PLEASE make sure you're running version 0.4.5 of Downtime Tracking.

# Crash's 5e Downtime Tracking
Does your group do a lot of downtime activities? Do you have a hard time keeping track of it all? Then this is the mod for you!

Expand Down
12 changes: 10 additions & 2 deletions audit-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ export default class AuditLog extends FormApplication {
}
}

// Update actor and flags
flags.trainingItems = activities;
actor.update({'flags.5e-training': null}).then(function(){
// Foundry versions 0.7.0 and earlier required the use of a workaround to get the flags to set properly
// In 0.7.1 and onward, this workaround resulted in data loss and was no longer required.
// Check for core version here, and do the right thing so nothing gets nuked.
if(game.data.version < "0.7.1"){
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
} else {
actor.update({'flags.5e-training': flags});
});
}

}

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Version 0.4.5
Compatibility patch for 0.7.1+
- Modifies the way flags are updated to prevent data loss when using Foundry core versions higher than 0.7.0

## Version 0.4.4
Improvements:
- Added the ability to select tools in addition to skills and ability checks. Tools are limited to those the actor has in their inventory. This means they're not available on NPC sheets.
Expand Down
8 changes: 4 additions & 4 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "5e-training",
"title": "Crash's 5e Downtime Tracking",
"description": "Adds a section to the character sheet to keep track of downtime activity progression. Track proficiency training, spell scribing, and anything else you can think of.",
"version": "0.4.4",
"version": "0.4.5",
"author": "CRASH1115#2944",
"minimumCoreVersion": "0.6.0",
"compatibleCoreVersion": "0.7.0",
"minimumCoreVersion": "0.6.6",
"compatibleCoreVersion": "0.7.2",
"systems": ["dnd5e"],
"esmodules": ["training.js"],
"styles": ["styles/training.css"],
Expand All @@ -23,5 +23,5 @@
],
"url": "https://github.com/crash1115/5e-training",
"manifest": "https://raw.githubusercontent.com/crash1115/5e-training/master/module.json",
"download": "https://github.com/crash1115/5e-training/releases/download/v0.4.4/5e-training.zip"
"download": "https://github.com/crash1115/5e-training/releases/download/v0.4.5/5e-training.zip"
}
46 changes: 22 additions & 24 deletions training.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ async function addTrainingTab(app, html, data) {
}
// Update flags and actor
flags.trainingItems.push(newActivity);
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags)
}
}
}).render(true);
Expand Down Expand Up @@ -332,9 +330,7 @@ async function addTrainingTab(app, html, data) {
}
// Update flags and actor
flags.trainingItems[trainingIdx] = activity;
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags);
}
}
}).render(true);
Expand Down Expand Up @@ -365,9 +361,7 @@ async function addTrainingTab(app, html, data) {
if (del) {
// Delete item and update actor
flags.trainingItems.splice(trainingIdx, 1);
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags);
}
}
}).render(true);
Expand Down Expand Up @@ -407,9 +401,7 @@ async function addTrainingTab(app, html, data) {

// Update flags and actor
flags.trainingItems[trainingIdx] = activity;
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags);
});

// ROLL TO TRAIN
Expand All @@ -436,9 +428,7 @@ async function addTrainingTab(app, html, data) {
checkCompletion(actor, activity);
// Update flags and actor
flags.trainingItems[trainingIdx] = activity;
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags);
});
}
// Progression Type: Ability Check or DC - SKILL
Expand All @@ -454,9 +444,7 @@ async function addTrainingTab(app, html, data) {
checkCompletion(actor, activity);
// Update flags and actor
flags.trainingItems[trainingIdx] = activity;
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags);
});
}
// Progression Type: Ability Check or DC - TOOL
Expand All @@ -475,9 +463,7 @@ async function addTrainingTab(app, html, data) {
checkCompletion(actor, activity);
// Update flags and actor
flags.trainingItems[trainingIdx] = activity;
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags);
});
} else {
ui.notifications.warn("Crash's 5e Downtime Tracking: " + game.i18n.localize("C5ETRAINING.ToolNotFoundWarning"));
Expand All @@ -492,9 +478,7 @@ async function addTrainingTab(app, html, data) {
checkCompletion(actor, activity);
// Update flags and actor
flags.trainingItems[trainingIdx] = activity;
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
updateDowntimeFlag(actor, flags);
}
});

Expand Down Expand Up @@ -687,6 +671,20 @@ function determineRollType(activity){
return rollType;
}

// Updates the actor flags
// Foundry versions 0.7.0 and earlier required the use of a workaround to get the flags to set properly
// In 0.7.1 and onward, this workaround resulted in data loss and was no longer required.
// Check for core version here, and do the right thing so nothing gets nuked.
async function updateDowntimeFlag(actor, flags){
if(game.data.version < "0.7.1"){
actor.update({'flags.5e-training': null}).then(function(){
actor.update({'flags.5e-training': flags});
});
} else {
actor.update({'flags.5e-training': flags});
}
}

Hooks.on(`renderActorSheet`, (app, html, data) => {
addTrainingTab(app, html, data).then(function(){
if (app.activateTrainingTab) {
Expand Down

0 comments on commit 64de048

Please sign in to comment.