import { RollDialog } from '../../helpers/roll' ; import { IronswornSettings } from '../../helpers/settings' ; import { CharacterMoveSheet } from './charactermovesheet' ; export class IronswornCharacterSheet extends ActorSheet { static get defaultOptions ( ) { return mergeObject ( super . defaultOptions , { classes : [ 'ironsworn' , 'sheet' , 'actor' , `theme-${ IronswornSettings . theme }` ] , width : 700 , height : 800 , left : 50 , template : 'systems/foundry-ironsworn/templates/actor/character.hbs' , } ) ; } constructor ( actor , options ) { super ( actor , options ) ; this . _openMoveSheet ( ) ; } activateListeners ( html ) { super . activateListeners ( html ) ; for ( const itemClass of CONFIG . IRONSWORN . itemClasses ) { itemClass . activateActorSheetListeners ( html , this ) ; } html . find ( '.ironsworn__stat__roll' ) . on ( 'click' , ( e ) => this . _onStatRoll . call ( this , e ) ) ; html . find ( '.ironsworn__stat__value' ) . on ( 'click' , ( e ) => this . _onStatSet . call ( this , e ) ) ; html . find ( '.ironsworn__momentum__burn' ) . on ( 'click' , ( e ) => this . _onBurnMomentum . call ( this , e ) ) ; } getData ( ) { let data = super . getData ( ) ; data . assets = this . actor . items . filter ( ( x ) => x . type === 'asset' ) ; data . vows = this . actor . items . filter ( ( x ) => x . type === 'vow' ) ; data . progresses = this . actor . items . filter ( ( x ) => x . type === 'progress' ) ; data . bonds = this . actor . items . find ( ( x ) => x . type === 'bondset' ) ; for ( const itemType of CONFIG . IRONSWORN . itemClasses ) { data = itemType . getActorSheetData ( data , this ) ; } return data ; } _getHeaderButtons ( ) { return [ { class : 'ironsworn-toggle-edit-mode' , label : 'Edit' , icon : 'fas fa-edit' , onclick : ( e ) => this . _toggleEditMode ( e ) , } , { class : 'ironsworn-open-move-sheet' , label : 'Moves' , icon : 'fas fa-directions' , onclick : ( e ) => this . _openMoveSheet ( e ) , } , ... super . _getHeaderButtons ( ) , ] ; } _toggleEditMode ( _e ) { const currentValue = this . actor . getFlag ( 'foundry-ironsworn' , 'edit-mode' ) ; this . actor . setFlag ( 'foundry-ironsworn' , 'edit-mode' , ! currentValue ) ; } _openMoveSheet ( _e ? ) { if ( this . actor . moveSheet ) { this . actor . moveSheet . render ( true , { focus : true } ) ; } else { new CharacterMoveSheet ( this . actor ) . render ( true ) ; } } _onBurnMomentum ( _ev ) { if ( this . actor . data . type !== 'character' ) return ; this . actor . burnMomentum ( ) ; } _onStatRoll ( ev ) { const el = ev . currentTarget ; const stat = el . dataset . stat ; if ( stat ) { RollDialog . show ( { actor : this . actor , stat } ) ; } } _onStatSet ( ev ) { const el = ev . currentTarget ; const { resource , value } = el . dataset ; if ( resource ) { const newValue = parseInt ( value ) ; if ( resource === 'momentum' && this . actor . data . type === 'character' ) { const { momentumMax } = this . actor . data . data ; if ( newValue > momentumMax ) { return ; } } this . actor . update ( { data : { [ resource ] : newValue } } ) ; if ( resource === 'supply' ) { IronswornSettings . maybeSetGlobalSupply ( newValue ) ; } } } }