import { IronswornActor } from "../actor/actor" ; import { IronswornItem } from "../item/item" ; function noop ( ) { } async function fixFormidableSpelling ( ) { const setRank = async ( x ) => { if ( ( x ?. data ?. data as any ) . rank === 'formidible' ) { console . log ( `Upgrading ${ x . type } / ${ x . name }` ) ; await x . update ( { data : { rank : 'formidable' } } ) ; } } ; for ( const item of game . items ?. contents || [ ] ) { await setRank ( item ) ; } for ( const actor of game . actors ?. contents || [ ] ) { await setRank ( actor ) ; for ( const item of actor . items ) { await setRank ( item ) ; } } for ( const pack of game . packs . contents ) { for ( const thing of pack . contents ) { await setRank ( thing as any ) ; } } } const MIGRATIONS = [ noop , fixFormidableSpelling ] ; const NEWEST_VERSION = MIGRATIONS . length ; export async function runDataMigrations ( ) { if ( ! game . user ?. isGM ) return ; let currentVersion = game . settings . get ( 'foundry-ironsworn' , 'data-version' ) as number ; if ( currentVersion >= NEWEST_VERSION ) return ; try { ui . notifications ?. warn ( 'Doing some system housecleaning, please wait...' , { permanent : true } ) ; while ( currentVersion < NEWEST_VERSION ) { await MIGRATIONS [ currentVersion ] ( ) ; currentVersion ++ ; } game . settings . set ( 'foundry-ironsworn' , 'data-version' , NEWEST_VERSION ) ; ui . notifications ?. warn ( 'All done! Carry on.' , { permanent : true } ) ; } catch ( e ) { ui . notifications ?. error ( "Whoops! That didn't work at all. Try reloading your browser to run it again." , { permanent : true } ) ; } }