const {ccclass, property} = cc._decorator;

@ccclass
export default class Helloworld extends cc.Component {

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

    @property
    text: string = 'hello';

    @property(dragonBones.ArmatureDisplay)
    robot: dragonBones.ArmatureDisplay = null;

    @property(dragonBones.ArmatureDisplay)
    weapon: dragonBones.ArmatureDisplay = null;
    weaponArr:Array<string> = [];
    index:number = -1;
    start () {
        // init logic
        // this.label.string = this.text;
        this.weaponArr = ["weapon_1004c_r","weapon_1004b_r","weapon_1004e_r","weapon_1004d_r","weapon_1004_r","weapon_1004s_r"]
    }

    changeWeapon(){
        this.index ++;
        if(this.index > 5){
            this.index = 0;
        }
        let robotArmature = this.robot.armature();
            let robotSlot = robotArmature.getSlot("weapon_hand_l");
            let factory = dragonBones.CCFactory.getInstance();
            factory.replaceSlotDisplay(
                this.weapon.getArmatureKey(),
                "weapon",
                "weapon_r",
                this.weaponArr[this.index],
                robotSlot
            );
    }
}
