11import { SelectDialog } from "./apps/SelectDialog.js" ;
2- import { TokenMovement } from "./classes/TokenMovement.js" ;
32import { Initiator } from "./classes/Initiator.js" ;
43
54export 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
0 commit comments