import { _decorator, Component, instantiate, Node, Prefab, Sprite, SpriteFrame } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('star_list')
export class star_list extends Component {
    @property(Prefab) img_star;
    @property(SpriteFrame) sf_yellow_start:SpriteFrame;
    @property(SpriteFrame) sf_grey_start:SpriteFrame;
    public initView(all_star_number:number){
        this.node.removeAllChildren()
        for (let index = 0; index < all_star_number; index++) {
           let item =   instantiate(this.img_star);
           item.name = index +"";
           item.parent = this.node;   
           item.getComponent(Sprite).spriteFrame = this.sf_grey_start;
        }
    }

    public showStartByNumber(show_star_number:number):Node{
        let node:Node = null;
        for (let index = 0; index < this.node.children.length; index++) {
            const element = this.node.children[index];
            if(index<show_star_number){
                element.getComponent(Sprite).spriteFrame = this.sf_yellow_start;
                node = element;
            }
        }
        return node;
    }
}


