WheelItem.ts
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { SaveDataManager } from "../component/SaveDataManager";
import { tMgr } from "../Global";
import { GamePlayTable, TableName, WheelTable } from "../kernel/table/TableDefine";
const { ccclass, property } = cc._decorator;
@ccclass
export default class WheelItem extends cc.Component {
private _config: WheelTable;
// get config(): WheelTable { return this._config; }
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
setId(id: number): void {
this._config = tMgr.getConfig(TableName.WHEEL, id) as WheelTable;
if (this._config.Type == 5 && SaveDataManager.ins.runtimeData.ballSkinUnlocked.includes(5)) {
//已获得西瓜球皮肤的情况下 替换为钻石
let diamondConfig = tMgr.getConfig(TableName.WHEEL, 1) as WheelTable; //随便读一个钻石配置
let gameplayConfig = (tMgr.getConfig(TableName.GAME_PLAY, 19) as GamePlayTable);
this.node.getChildByName('txtNum').active = true;
this.node.getChildByName('txtNum').getComponent(cc.Label).string = 'x' + gameplayConfig.Value.toString();
cc.resources.load(diamondConfig.Icon, cc.SpriteFrame, (error, asset) => {
if (!error) {
this.node.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = asset as cc.SpriteFrame;
}
})
}
else {
cc.resources.load(this._config.Icon, cc.SpriteFrame, (error, asset) => {
if (!error) {
this.node.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = asset as cc.SpriteFrame;
}
})
this.node.getChildByName('txtNum').active = (this._config.Type == 1);
if (this._config.Type == 1) {
this.node.getChildByName('txtNum').getComponent(cc.Label).string = 'x' + this._config.Num.toString();
}
}
}
refresh() {
if (this._config) {
this.setId(this._config.ID);
}
}
// update (dt) {}
}