// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {

        let dddd = new cc.Event.EventKeyboard('keydown', false)



        console.error(this.node.name);



        switch (this.node.name) {
            case 'Enter':
                this.node.on('click', () => {
                    dddd.bubbles = false
                    dddd.eventPhase = 0
                    dddd.keyCode = 13
                    cc.systemEvent.emit('keydown', dddd);
                }, this)
                break;
            case 'A':
                this.node.on(cc.Node.EventType.TOUCH_START, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.a;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_DOWN
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_CANCEL, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.a;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_END, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.a;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                break;
            case 'W':
                this.node.on(cc.Node.EventType.TOUCH_START, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.w;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_DOWN
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_CANCEL, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.w;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_END, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.w;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                break;
            case 'D':
                this.node.on(cc.Node.EventType.TOUCH_START, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.d;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_DOWN
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_CANCEL, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.d;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_END, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.d;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                break;

            case 'L':
                this.node.on(cc.Node.EventType.TOUCH_START, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.l;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_DOWN
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_CANCEL, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.l;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_END, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.l;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                break;

            case 'J':
                this.node.on(cc.Node.EventType.TOUCH_START, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.j;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_DOWN
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_CANCEL, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.j;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_END, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.j;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                break;

            case 'K':
                this.node.on(cc.Node.EventType.TOUCH_START, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.k;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_DOWN
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_CANCEL, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.k;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                this.node.on(cc.Node.EventType.TOUCH_END, () => {
                    let keyEvent = new cc.Event.EventKeyboard('keydown', false)
                    keyEvent.keyCode = cc.macro.KEY.k;
                    keyEvent.type = cc.SystemEvent.EventType.KEY_UP
                    cc.systemEvent.dispatchEvent(keyEvent);
                }, this)
                break;
            case 'Add':
                console.error('FF');


                break;
            default:
                break;
        }


    }

    click() {

    }

    adddd() {
        console.error('vv');

        sdk.showVideoAd(() => {
            cc.Canvas.instance.node
                .getChildByName('player')
                .getComponent('player')
                .playerHP = 3
            cc.Canvas.instance.node
                .getChildByName('player')
                .getComponent('player')
                .addhhh()
            cc.Canvas.instance.node
                .getChildByName('player')
                .getComponent('player')
                .setHP()
        }, null)





    }

    // bubbles
    // : 
    // false
    // currentTarget
    // : 
    // null
    // eventPhase
    // : 
    // 0
    // isPressed
    // : 
    // true
    // keyCode
    // : 
    // 13
    // target
    // : 
    // null
    // type
    // : 
    // "keydown"
    // _propagationImmediateStopped
    // : 
    // false
    // _propagationStopped
    // : 
    // false

    // update (dt) {}
}
