import Game from "./Game";
import pg from "./pg";

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:
    private player: cc.Node;
    private robot: cc.Node;
    onLoad() {
        this.player = pg.view.find(this, "player");
        this.robot = pg.view.find(this, "robot");

        // pg.event.on("player_point_update", (data) => {
        // })
    }
    protected onDestroy(): void {
        // pg.event.off("player_point_update");
    }
    updatePlayer() {
        let icon_player = pg.view.find(this.player, "icon_player");
        let icon_player_dice = pg.view.find(this.player, "icon_player_dice");
        pg.view.visible(icon_player, Game.getIns().isRobot);
        pg.view.visible(icon_player_dice, !Game.getIns().isRobot);
    }
    updateRobot() {
        let icon_robot = pg.view.find(this.robot, "icon_robot");
        let icon_robot_dice = pg.view.find(this.robot, "icon_robot_dice");
        pg.view.visible(icon_robot, !Game.getIns().isRobot);
        pg.view.visible(icon_robot_dice, Game.getIns().isRobot);
    }
    updateScore() {
        let score = pg.view.find(this, "score");
        pg.view.setString(score, `${Game.getIns().playerScore} : ${Game.getIns().robotScore}`);
    }
    update(dt) {
        if (!Game || !Game.getIns() || !Game.getIns().start) return;
        this.updatePlayer();
        this.updateRobot();
        this.updateScore();
    }
}
