47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import gsap from "gsap";
|
|
import { ChipColorConfig } from "../config/chip-color-config";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export class Chip extends cc.Component
|
|
{
|
|
@property(cc.Label)
|
|
private labelChipValue: cc.Label = null;
|
|
@property(cc.Node)
|
|
private nodeChipColor: cc.Node = null;
|
|
@property(cc.Integer)
|
|
private value: number = 1;
|
|
|
|
public setChipValue(value: number): void
|
|
{
|
|
this.value = value;
|
|
this.labelChipValue.string = value.toString();
|
|
this.nodeChipColor.color = ChipColorConfig.getColor(value);
|
|
}
|
|
|
|
public getChipValue(): number
|
|
{
|
|
return this.value;
|
|
}
|
|
|
|
public placeChip(value: number): void
|
|
{
|
|
this.setChipValue(value);
|
|
var currentPos = this.node.position;
|
|
var newPos = new cc.Vec2(currentPos.x, currentPos.y);
|
|
newPos.y += 40;
|
|
this.node.setPosition(newPos);
|
|
gsap.to(this.node, {
|
|
duration: 0.2,
|
|
x: currentPos.x,
|
|
y: currentPos.y,
|
|
});
|
|
}
|
|
|
|
public hideChip(): void
|
|
{
|
|
this.node.active = false;
|
|
}
|
|
}
|