import { ActionSerialized } from './ActionSerialized' ; import { getCanvas } from "./main" ; import { Action } from "./Action" ; export class ActionInit extends Action { get xMax ( ) : number { if ( this . img ) this . img . width ; else return 0 ; } private img = undefined ; constructor ( userid , private canvasDataURL ) { super ( userid ) ; if ( canvasDataURL ) { this . img = new Image ( ) ; this . img . src = canvasDataURL ; } } serializeData ( ) { return { type : "init" , pause : this . pause , userid : this . userid , canvasDataURL : this . canvasDataURL } ; } createOverviewImage ( ) { return "url(img/icons/start.svg)" ; } redo ( ) { return new Promise ( ( resolve ) => { if ( this . img ) { const drawAndResolve = ( ) => { const canvas = getCanvas ( ) ; canvas . width = Math . max ( canvas . width , this . img . width ) ; canvas . height = Math . max ( canvas . height , this . img . height ) ; canvas . getContext ( "2d" ) . drawImage ( this . img , 0 , 0 ) ; resolve ( ) ; } ; if ( this . img . height != 0 ) { drawAndResolve ( ) ; } else this . img . onload = drawAndResolve ; } else resolve ( ) ; } ) ; } }