Skip to content

Commit f322646

Browse files
committed
Fixed token vision not updating
1 parent 0534b60 commit f322646

File tree

7 files changed

+57
-30
lines changed

7 files changed

+57
-30
lines changed

gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ gulp.task('link', () => {
121121
gulp.task('build', gulp.series(
122122
'move-non-convertible-files',
123123
'compile-and-copy-ts',
124-
'compile-minify-and-copy-sass'
124+
//'compile-minify-and-copy-sass'
125125
));
126126

127127
gulp.task('build-watch', () => {
@@ -131,5 +131,5 @@ gulp.task('build-watch', () => {
131131
'!./src/styles/**/*.scss'
132132
], gulp.series('move-non-convertible-files'));
133133
gulp.watch('./src/scripts/**/*.ts', gulp.series('compile-and-copy-ts'));
134-
gulp.watch('./src/styles/**/*.scss', gulp.series('compile-minify-and-copy-sass'));
134+
//gulp.watch('./src/styles/**/*.scss', gulp.series('compile-minify-and-copy-sass'));
135135
});

src/module.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
"name": "Foundry-MGL",
33
"title": "Foundry Meters, Grams & Liters",
44
"description": "An expandable module that allows for easy and quick conversion of any data in the imperial system to the metric system.",
5-
"author": ["HadaIonut"],
6-
"version": "1.0.1",
5+
"author": "HadaIonut",
6+
"authors": [
7+
{
8+
"name": "HadaIonut",
9+
"discord": "assassinduke#0983",
10+
"url": "https://github.com/HadaIonut"
11+
}
12+
],
13+
"version": "1.1.0",
714
"esmodules": ["scripts/foundry-mgl.js"],
815
"styles": ["styles/foundry-mgl.css"],
916
"languages":
@@ -16,7 +23,7 @@
1623
"minimumCoreVersion": "0.6.5",
1724
"compatibleCoreVersion": "0.7.7",
1825
"url": "https://github.com/HadaIonut/Foundry-mgl",
19-
"manifest": "https://github.com/HadaIonut/Foundry-mgl/releases/download/v1.0.1/module.json",
20-
"download": "https://github.com/HadaIonut/Foundry-mgl/releases/download/v1.0.1/module.zip",
26+
"manifest": "https://github.com/HadaIonut/Foundry-mgl/releases/download/v1.1.0/module.json",
27+
"download": "https://github.com/HadaIonut/Foundry-mgl/releases/download/v1.1.0/module.zip",
2128
"changelog": ""
2229
}

src/scripts/Dnd5e/BatchConversion.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
actorDataConverter,
2+
actorDataConverter, actorTokenConverter,
33
convertDistance, convertStringFromImperialToMetric,
44
convertText,
55
convertValueToMetric,
@@ -38,14 +38,20 @@ const itemsUpdater = (items: any[]): void => {
3838
const actorUpdater = (actor: any, loading): void => {
3939
const actorClone = JSON.parse(JSON.stringify(actor));
4040

41-
actorClone.data = actorDataConverter(actorClone.data);
41+
if (!actor.getFlag("Foundry-MGL", "converted")) {
42+
actorClone.data = actorDataConverter(actorClone.data);
43+
actorClone.token = actorTokenConverter(actorClone.token);
44+
}
4245

43-
actor.update(actorClone)
46+
actor.setFlag("Foundry-MGL", "converted", true)
4447
.then(() => {
45-
itemsUpdater(actor.items.entries);
46-
loading();
48+
actor.update(actorClone)
49+
.then(() => {
50+
itemsUpdater(actor.items.entries);
51+
loading();
52+
})
53+
.catch((e) => createErrorMessage(e, 'actor.update', actorClone.data))
4754
})
48-
.catch((e) => createErrorMessage(e, 'actor.update', actorClone.data))
4955
}
5056

5157
const journalUpdater = (journal: any, loading): void => {

src/scripts/Dnd5e/Compendium5eConverter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
actorDataConverter,
2+
actorDataConverter, actorTokenConverter,
33
convertDistance,
44
convertStringFromImperialToMetric,
55
convertText,
@@ -26,6 +26,7 @@ const itemsUpdater = (items: any[], onlyLabel?: boolean, onlyUnit?:boolean): any
2626

2727
const actorUpdater = (actor: any, onlyLabel?: boolean, onlyUnit?:boolean): any => {
2828
actor.data = actorDataConverter(actor.data);
29+
actor.token = actorTokenConverter(actor.token);
2930
actor.items = itemsUpdater(actor.items, onlyLabel, onlyUnit);
3031
return actor;
3132
}

src/scripts/Dnd5e/Dnd5eConverterNew.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
actorDataConverter, convertDistance,
2+
actorDataConverter, actorTokenConverter, convertDistance,
33
convertStringFromImperialToMetric, convertText,
44
convertValueToMetric, labelConverter,
55
} from "../Utils/ConversionEngineNew";
@@ -39,10 +39,14 @@ const itemsUpdater = async (items: Array<any>, onlyLabel?: boolean, onlyUnit?:bo
3939
const actorUpdater = async (actor: any, onlyLabel?: boolean, onlyUnit?:boolean): Promise<void> => {
4040
const actorClone = JSON.parse(JSON.stringify(actor));
4141

42-
actorClone.data = actorDataConverter(actorClone.data);
42+
if (!actor.getFlag("Foundry-MGL", "converted")) {
43+
actorClone.data = actorDataConverter(actorClone.data);
44+
actorClone.token = actorTokenConverter(actorClone.token);
45+
}
4346

4447
try {
4548
await actor.update(actorClone);
49+
await actor.setFlag("Foundry-MGL", "converted", true);
4650
} catch (e) {
4751
createErrorMessage(e, 'actor.update', actorClone.data);
4852
}

src/scripts/MetricModule.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ class MetricModule {
6565
// break;
6666
// }
6767
// })
68-
let unitFix = $(`<a class="popout" style><i class="fas fa-ruler"></i>Unit fix</a>`);
69-
unitFix.on('click', ()=> {
70-
switch (type) {
71-
case 'actor':
72-
actorUpdater(actor, true, true);
73-
break;
74-
case 'item':
75-
itemUpdater(actor, true, true);
76-
break;
77-
case 'compendium':
78-
compendiumUpdater(actor, true, true);
79-
break;
80-
}
81-
})
68+
// let unitFix = $(`<a class="popout" style><i class="fas fa-ruler"></i>Unit fix</a>`);
69+
// unitFix.on('click', ()=> {
70+
// switch (type) {
71+
// case 'actor':
72+
// actorUpdater(actor, true, true);
73+
// break;
74+
// case 'item':
75+
// itemUpdater(actor, true, true);
76+
// break;
77+
// case 'compendium':
78+
// compendiumUpdater(actor, true, true);
79+
// break;
80+
// }
81+
// })
8282
element.after(button);
83-
element.after(unitFix);
83+
//element.after(unitFix);
8484
//element.after(labelButton);
8585
}
8686

src/scripts/Utils/ConversionEngineNew.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ const actorDataConverter = (data: any): any => {
171171
return data;
172172
}
173173

174+
const actorTokenConverter = (token: any) => {
175+
token.brightLight = convertValueToMetric(token.brightLight, 'feet');
176+
token.brightSight = convertValueToMetric(token.brightSight, 'feet');
177+
token.dimLight = convertValueToMetric(token.dimLight, 'feet');
178+
token.dimSight = convertValueToMetric(token.dimSight, 'feet');
179+
return token;
180+
}
181+
174182
const labelConverter = (label: string): string => {
175183
return label.replace(/(([0-9]+) \/ )?([0-9]+) ([\w]+)/, (_0, _1, optionalValue, mainValue, unit) => {
176184
if (optionalValue)
@@ -215,6 +223,7 @@ export {
215223
imperialReplacer,
216224
convertText,
217225
actorDataConverter,
226+
actorTokenConverter,
218227
convertDistance,
219228
labelConverter,
220229
relinkText

0 commit comments

Comments
 (0)