import Tool from "../common/util/Tool" ; import FsmCtr from "./fsm/FsmCtr" ; import InspectorCtr from "./inspector/InspectorCtr" ; import Menu from "./menu/Menu" ; import ParamCtr from "./parameters/ParamCtr" ; import Setting from "./Setting" ; const { ccclass , property } = cc . _decorator ; @ ccclass export default class Editor extends cc . Component { @ property ( FsmCtr ) Fsm : FsmCtr = null ; @ property ( InspectorCtr ) Inspector : InspectorCtr = null ; @ property ( ParamCtr ) Parameters : ParamCtr = null ; @ property ( Menu ) Menu : Menu = null ; public static Inst : Editor = null ; /** 按下的按键 */ private _keySet : Set < cc . macro . KEY > = new Set ( ) ; protected onLoad ( ) { Setting . read ( ) ; this . Inspector . node . width = Setting . inspectorWidth ; this . Inspector . getComponent ( cc . Widget ) . updateAlignment ( ) ; Tool . updateWidget ( this . Inspector . node ) ; this . Parameters . node . width = Setting . parametersWidth ; this . Parameters . getComponent ( cc . Widget ) . updateAlignment ( ) ; Tool . updateWidget ( this . Parameters . node ) ; cc . systemEvent . on ( cc . SystemEvent . EventType . KEY_DOWN , this . onKeyDown , this ) ; cc . systemEvent . on ( cc . SystemEvent . EventType . KEY_UP , this . onKeyUp , this ) ; } protected onDestroy ( ) { cc . systemEvent . off ( cc . SystemEvent . EventType . KEY_DOWN , this . onKeyDown , this ) ; cc . systemEvent . off ( cc . SystemEvent . EventType . KEY_UP , this . onKeyUp , this ) ; } private onKeyDown ( event ) { this . _keySet . add ( event . keyCode ) ; switch ( event . keyCode ) { case cc . macro . KEY . s : if ( this . _keySet . has ( cc . macro . KEY . ctrl ) ) { this . exportProject ( ) ; } break ; case cc . macro . KEY . e : if ( this . _keySet . has ( cc . macro . KEY . ctrl ) ) { this . exportRuntimeData ( ) ; } break ; case cc . macro . KEY . Delete : this . Fsm . deleteCurUnit ( ) ; this . Fsm . deleteCurLine ( ) ; default : break ; } } private onKeyUp ( event ) { this . _keySet . delete ( event . keyCode ) ; } private exportProject ( ) { let data = this . Fsm . exportProject ( ) ; data . parameters = this . Parameters . export ( ) ; this . save ( 'animator.json' , data ) ; } private exportRuntimeData ( ) { let data = this . Fsm . exportRuntimeData ( ) ; data . parameters = this . Parameters . export ( ) ; this . save ( 'runtimeData.json' , data ) ; } private save ( fileName , data ) { let content = JSON . stringify ( data ) ; let eleLink = document . createElement ( 'a' ) ; eleLink . download = `${ fileName }` ; eleLink . style . display = 'none' ; let blob = new Blob ( [ content ] ) ; eleLink . href = URL . createObjectURL ( blob ) ; document . body . appendChild ( eleLink ) ; eleLink . click ( ) ; document . body . removeChild ( eleLink ) ; } }