Skip to content

Commit 61ccbd8

Browse files
committed
fix typescript
1 parent b00a8bf commit 61ccbd8

File tree

14 files changed

+1750
-3663
lines changed

14 files changed

+1750
-3663
lines changed

module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "Beaver's System Interface",
33
"description": "An Interface to uniformly access system dependent implementations",
44
"id": "beavers-system-interface",
5-
"version": "2.3.0",
5+
"version": "2.3.1",
66
"authors": [
77
{
88
"name": "angryBeaver",

package-lock.json

Lines changed: 1652 additions & 3345 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
{
22
"name": "beavers-system-interface",
33
"title": "Beaver's System Interface",
4-
"version": "2.3.0",
4+
"version": "2.3.1",
55
"description": "Beaver's System Interface",
66
"#devDir": "c:\\vtts\\v13.342\\Data\\modules",
77
"devDir": "c:\\vtts\\v12.331\\Data\\modules",
88
"#devDir": "c:\\vtts\\v11.315\\Data\\modules",
99
"main": "src/main.js",
10+
"types": "./src/index.d.ts",
11+
"exports": {
12+
".": {
13+
"types": "./src/index.d.ts"
14+
}
15+
},
1016
"scripts": {
1117
"type": "npx -p typescript tsc src/types.ts --declaration --emitDeclarationOnly --outDir dist/src",
1218
"build": "npx gulp",
@@ -28,8 +34,7 @@
2834
},
2935
"devDependencies": {
3036
"beavers-gamepad": "^2.0.0",
31-
"@ethaks/fvtt-quench": "^0.6.0",
32-
"@league-of-foundry-developers/foundry-vtt-types": "^12.331.3-beta",
37+
"@league-of-foundry-developers/foundry-vtt-types": "^13.346.0-beta",
3338
"@types/jest": "^27.4.1",
3439
"del": "^6.0.0",
3540
"gulp": "^4.0.2",

src/CoreSystem.ts

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {SelectDialog} from "./apps/SelectDialog.js";
2-
import {TokenMovement} from "./classes/TokenMovement.js";
32
import {Initiator} from "./classes/Initiator.js";
43

54
export class CoreSystem implements BeaverSystem {
@@ -15,13 +14,13 @@ export class CoreSystem implements BeaverSystem {
1514
// @ts-ignore
1615
ui.notifications.error("Beavers System Interface | missing module BSA - " + game.system.id + " <a href='https://github.com/AngryBeaver/beavers-system-interface/wiki/BSA-x-links'>module links</a>",{permanent:true});
1716
console.error("The following modules will not work", this._modules);
18-
throw Error(game['i18n'].localize("beaversSystemInterface.SystemNotFound"));
17+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.SystemNotFound"));
1918
}
2019
if(this._modules.length === 0){
21-
console.warn(game['i18n'].localize("beaversSystemInterface.NoModulesRegistered"))
20+
console.warn((game as foundry.Game)['i18n'].localize("beaversSystemInterface.NoModulesRegistered"))
2221
}
2322
if(this._implementation === undefined){
24-
console.warn(game['i18n'].localize("beaversSystemInterface.NoImplementationRegistered"))
23+
console.warn((game as foundry.Game)['i18n'].localize("beaversSystemInterface.NoImplementationRegistered"))
2524
}
2625
}
2726

@@ -49,7 +48,7 @@ export class CoreSystem implements BeaverSystem {
4948
}
5049

5150
register(implementation) {
52-
if (implementation.id === game["system"].id) {
51+
if (implementation.id === (game as foundry.Game)["system"].id) {
5352
this._implementation = implementation;
5453
}
5554
}
@@ -84,7 +83,7 @@ export class CoreSystem implements BeaverSystem {
8483
if (this._implementation?.configSkills !== undefined) {
8584
return this._implementation.configSkills;
8685
} else {
87-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configSkills');
86+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configSkills');
8887
}
8988
}
9089

@@ -93,7 +92,7 @@ export class CoreSystem implements BeaverSystem {
9392
if (this._implementation?.configAbilities !== undefined) {
9493
return this._implementation.configAbilities;
9594
} else {
96-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configAbilities');
95+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configAbilities');
9796
}
9897
}
9998

@@ -105,7 +104,7 @@ export class CoreSystem implements BeaverSystem {
105104
return this._implementation.configCurrencies;
106105
} else {
107106
this._checkImplementation();
108-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configCurrencies');
107+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configCurrencies');
109108
}
110109
}
111110

@@ -114,7 +113,7 @@ export class CoreSystem implements BeaverSystem {
114113
if (this._implementation?.configCanRollAbility !== undefined) {
115114
return this._implementation.configCanRollAbility;
116115
} else {
117-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configCanRollAbility');
116+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configCanRollAbility');
118117
}
119118
}
120119

@@ -123,7 +122,7 @@ export class CoreSystem implements BeaverSystem {
123122
if (this._implementation?.configLootItemType !== undefined) {
124123
return this._implementation.configLootItemType;
125124
} else {
126-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configLootItemType');
125+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + ' configLootItemType');
127126
}
128127
}
129128

@@ -158,7 +157,7 @@ export class CoreSystem implements BeaverSystem {
158157
if (this._implementation?.actorRollAbility !== undefined) {
159158
return this._implementation.actorRollAbility(actor, abilityId);
160159
} else {
161-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorRollAbility');
160+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorRollAbility');
162161
}
163162
}
164163

@@ -167,7 +166,7 @@ export class CoreSystem implements BeaverSystem {
167166
if (this._implementation?.actorRollSkill !== undefined) {
168167
return this._implementation.actorRollSkill(actor, skillId);
169168
} else {
170-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorRollSkill');
169+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorRollSkill');
171170
}
172171
}
173172

@@ -176,7 +175,7 @@ export class CoreSystem implements BeaverSystem {
176175
if (this._implementation?.actorRollTool !== undefined) {
177176
return this._implementation.actorRollTool(actor, item);
178177
} else {
179-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorRollTool');
178+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorRollTool');
180179
}
181180
}
182181

@@ -186,7 +185,7 @@ export class CoreSystem implements BeaverSystem {
186185
} else {
187186
if(this._configCurrencies===undefined){
188187
this._checkImplementation();
189-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorGetCurrencies');
188+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorGetCurrencies');
190189
}
191190
return this._actorCurrenciesGet(actor);
192191
}
@@ -216,7 +215,7 @@ export class CoreSystem implements BeaverSystem {
216215
const addValue = beaversSystemInterface.currenciesToLowestValue(add);
217216
const result = actorValue + addValue;
218217
if (result < 0) {
219-
throw new Error(game['i18n'].localize("beaversSystemInterface.NotEnoughMoney"));
218+
throw new Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.NotEnoughMoney"));
220219
}
221220
return beaversSystemInterface.currencyToCurrencies(result);
222221
}
@@ -225,7 +224,7 @@ export class CoreSystem implements BeaverSystem {
225224
for(const [key, value] of Object.entries(add)){
226225
const sum = source[key] + value;
227226
if(sum< 0){
228-
throw new Error(game['i18n'].localize("beaversSystemInterface.NotEnoughMoney"));
227+
throw new Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.NotEnoughMoney"));
229228
}
230229
resultCurrencies[key] = sum;
231230
}
@@ -237,8 +236,8 @@ export class CoreSystem implements BeaverSystem {
237236
if(doExchange){
238237
console.warn("actorCurrenciesAdd is deprecated plz upgrade your bsa-x module");
239238
}else{
240-
ui.notifications?.error(game['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
241-
throw Error(game['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
239+
ui.notifications?.error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
240+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
242241
}
243242
return await this._implementation.actorCurrenciesAdd(actor, currencies);
244243
}
@@ -248,7 +247,7 @@ export class CoreSystem implements BeaverSystem {
248247
return await this._implementation.actorCurrenciesStore(actor, resultCurrencies);
249248
} else {
250249
if(this._configCurrencies===undefined){
251-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorCurrenciesAdd');
250+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorCurrenciesAdd');
252251
}
253252
await this._actorStoreCurrency(actor, resultCurrencies);
254253
}
@@ -284,19 +283,19 @@ export class CoreSystem implements BeaverSystem {
284283
await actor.createEmbeddedDocuments("Item", createItems);
285284
}
286285

287-
actorCurrenciesCanAdd(actor, currencies: Currencies): boolean {
286+
actorCurrenciesCanAdd(actor:Actor, currencies: Currencies): boolean {
288287
const actorCurrencies = this.actorCurrenciesGet(actor);
289288
const payValue = this.currenciesToLowestValue(currencies);
290289
const actorValue = this.currenciesToLowestValue(actorCurrencies);
291290
return 0 > actorValue + payValue;
292291
}
293292

294-
actorSheetAddTab(sheet, html, actor, tabData: { id: string, label: string, html: string }, tabBody:string): void {
293+
actorSheetAddTab(sheet, html, actor:Actor, tabData: { id: string, label: string, html: string }, tabBody:string): void {
295294
this._checkImplementation();
296295
if (this._implementation?.actorSheetAddTab !== undefined) {
297296
return this._implementation.actorSheetAddTab(sheet, html, actor, tabData, tabBody);
298297
} else {
299-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorSheetAddTab');
298+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'actorSheetAddTab');
300299
}
301300
}
302301

@@ -353,7 +352,7 @@ export class CoreSystem implements BeaverSystem {
353352
if(actorFindings.quantity != 0) {
354353
const remainingQuantity = component.quantity + actorFindings.quantity;
355354
if (remainingQuantity < 0) {
356-
throw new Error("Beavers System Interface | "+game['i18n'].localize("beaversSystemInterface.RemainingQuantityLessThenZero")+ component.name);
355+
throw new Error("Beavers System Interface | "+(game as foundry.Game)['i18n'].localize("beaversSystemInterface.RemainingQuantityLessThenZero")+ component.name);
357356
}
358357
let equivalentQuantity = 0;
359358
const equivalentComponent:Component[] = [];
@@ -404,11 +403,12 @@ export class CoreSystem implements BeaverSystem {
404403
}
405404
} else {
406405
if (component.quantity < 0) {
407-
throw new Error("Beavers System Interface | "+game['i18n'].localize("beaversSystemInterface.RemainingQuantityLessThenZero")+ component.name);
406+
throw new Error("Beavers System Interface | "+(game as foundry.Game)['i18n'].localize("beaversSystemInterface.RemainingQuantityLessThenZero")+ component.name);
408407
}
409408
if(component.quantity !=0) {
410409
const entity = await component.getEntity();
411410
const data = entity.toObject(true);
411+
// @ts-ignore
412412
data.flags = foundry.utils.mergeObject(data.flags,component.flags||{},{insertKeys:true})
413413
this.objectAttributeSet(data, beaversSystemInterface.itemQuantityAttribute, component.quantity);
414414
itemChange.create.push(data)
@@ -427,7 +427,7 @@ export class CoreSystem implements BeaverSystem {
427427
const parts = uuid.split(".");
428428
let result: foundry.abstract.Document<any, any> | null = null;
429429
if (parts[0] === "Compendium") {
430-
const pack = game["packs"].get(parts[1] + "." + parts[2]);
430+
const pack = (game as foundry.Game)["packs"].get(parts[1] + "." + parts[2]);
431431
if (pack !== undefined) {
432432
let id = parts[3];
433433
if(parts.length >= 5){
@@ -439,12 +439,13 @@ export class CoreSystem implements BeaverSystem {
439439
result = await fromUuid(uuid);
440440
}
441441
if (result === null) {
442-
throw new Error("Beavers System Interface | "+game['i18n'].localize("beaversSystemInterface.DocumentNotFound")+ uuid);
442+
throw new Error("Beavers System Interface | "+(game as foundry.Game)['i18n'].localize("beaversSystemInterface.DocumentNotFound")+ uuid);
443443
}
444444
return result;
445445
}
446446

447447
componentCreate(data: any): Component {
448+
// @ts-ignore
448449
const result = foundry.utils.mergeObject(this.componentDefaultData, data, {insertKeys: false});
449450
result.getEntity = async () => {
450451
if (result.jsonData) {
@@ -511,8 +512,8 @@ export class CoreSystem implements BeaverSystem {
511512
let result:Component;
512513
if (this._implementation?.componentFromEntity !== undefined) {
513514
if(this._implementation.version < 2){
514-
ui.notifications?.error(game['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
515-
throw Error(game['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
515+
ui.notifications?.error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
516+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.VersionsMismatch"));
516517
}
517518
result = this._implementation.componentFromEntity(entity,hasJsonData);
518519
} else {
@@ -531,7 +532,9 @@ export class CoreSystem implements BeaverSystem {
531532
Object.entries(this._extensions).forEach(([moduleId,ext])=>{
532533
if(ext.componentAddFlags){
533534
ext.componentAddFlags.forEach((flag)=>{
535+
// @ts-ignore
534536
const property = foundry.utils.getProperty(entity,`flags.${moduleId}.${flag}`);
537+
// @ts-ignore
535538
foundry.utils.setProperty(result,`flags.${moduleId}.${flag}`,property);
536539
});
537540
}
@@ -544,7 +547,7 @@ export class CoreSystem implements BeaverSystem {
544547
if (this._implementation?.itemQuantityAttribute !== undefined) {
545548
return this._implementation.itemQuantityAttribute;
546549
} else {
547-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'itemQuantityAttribute');
550+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'itemQuantityAttribute');
548551
}
549552
}
550553

@@ -553,7 +556,7 @@ export class CoreSystem implements BeaverSystem {
553556
if (this._implementation?.itemPriceAttribute !== undefined) {
554557
return this._implementation.itemPriceAttribute;
555558
} else {
556-
throw Error(game['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'itemQuantityAttribute');
559+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.MethodNotSupported") + 'itemQuantityAttribute');
557560
}
558561
}
559562

@@ -587,20 +590,14 @@ export class CoreSystem implements BeaverSystem {
587590
}
588591
}
589592

590-
tokenMovementCreate(actorId:string){
591-
const tokenMovement = new TokenMovement();
592-
tokenMovement.initialize(actorId);
593-
return tokenMovement;
594-
}
595-
596593
async uiDialogSelect(data: SelectData):Promise<string> {
597594
return SelectDialog.promise(data);
598595
}
599596

600597
private _checkImplementation() {
601598
if (this._implementation === undefined) {
602-
console.warn(game['i18n'].localize("beaversSystemInterface.SystemAdaptionNeededAddition"))
603-
throw Error(game['i18n'].localize("beaversSystemInterface.SystemAdaptionNeeded"));
599+
console.warn((game as foundry.Game)['i18n'].localize("beaversSystemInterface.SystemAdaptionNeededAddition"))
600+
throw Error((game as foundry.Game)['i18n'].localize("beaversSystemInterface.SystemAdaptionNeeded"));
604601
}
605602
}
606603

src/Settings.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ export class Settings {
55
public static ENABLE_SELECTION :ClientSettings.Key = "enableSelection";
66

77
static init() {
8-
game["settings"].register(this.NAMESPACE, this.ENABLE_SELECTION, {
9-
name: game["i18n"].localize('beaversSystemInterface.settings.enableSelection.name'),
10-
hint: game["i18n"].localize('beaversSystemInterface.settings.enableSelection.hint'),
8+
// @ts-ignore
9+
(game as foundry.Game)["settings"].register(this.NAMESPACE, this.ENABLE_SELECTION, {
10+
name: (game as foundry.Game)["i18n"].localize('beaversSystemInterface.settings.enableSelection.name'),
11+
hint: (game as foundry.Game)["i18n"].localize('beaversSystemInterface.settings.enableSelection.hint'),
1112
scope: "client",
1213
config: true,
1314
default: true,
@@ -17,11 +18,13 @@ export class Settings {
1718
}
1819

1920
static get(key) {
20-
return game["settings"].get(this.NAMESPACE, key);
21+
// @ts-ignore
22+
return (game as foundry.Game)["settings"].get(this.NAMESPACE, key);
2123
};
2224

2325
static set(key, value) {
24-
game.settings.set(this.NAMESPACE, key, value);
26+
// @ts-ignore
27+
(game as foundry.Game).settings.set(this.NAMESPACE, key, value);
2528
}
2629

2730
}

src/apps/SelectDialog.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Settings} from "../Settings.js";
2+
import {AppClass} from "../legacySupport.js";
23

3-
export class SelectDialog extends Application {
4+
export class SelectDialog extends AppClass {
45
selectData: SelectData
56
callback;
67
selected: string;
@@ -23,15 +24,16 @@ export class SelectDialog extends Application {
2324
});
2425
}
2526

26-
constructor(data: SelectData , callback: (id: string | PromiseLike<string>) => void, options?: Partial<ApplicationOptions>) {
27+
constructor(data: SelectData , callback: (id: string | PromiseLike<string>) => void, options?: any) {
2728
super(options);
2829
this.selectData = data;
2930
this.callback = callback;
3031
}
3132

3233
static get defaultOptions() {
34+
// @ts-ignore
3335
return foundry.utils.mergeObject(super.defaultOptions, {
34-
title: game["i18n"].localize(`beaversSystemInterface.select-dialog.title`),
36+
title: (game as foundry.Game)["i18n"].localize(`beaversSystemInterface.select-dialog.title`),
3537
width: 300,
3638
height: 80,
3739
template: "modules/beavers-system-interface/templates/selectDialog.hbs",
@@ -42,7 +44,9 @@ export class SelectDialog extends Application {
4244
}
4345

4446
getData() {
45-
return foundry.utils.mergeObject(this.selectData,{size:"l",enabled:Settings.get(Settings.ENABLE_SELECTION)});
47+
// @ts-ignore
48+
return foundry.utils.mergeObject(
49+
this.selectData,{size:"l",enabled:Settings.get(Settings.ENABLE_SELECTION)});
4650
}
4751

4852
activateListeners(html: JQuery) {

0 commit comments

Comments
 (0)