CanjuModel.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import GameData from "../../gcommon/GameData";
  2. import { Singleton } from "../../gcommon/Singleton";
  3. import { GameConst } from "../../GameConst";
  4. export interface CanjuData{
  5. fen:string,
  6. name:string
  7. }
  8. export default class CanjuModel extends Singleton<CanjuModel>() {
  9. public canjuDataArr:CanjuData[]=[]
  10. public get canjuData(){
  11. return this.canjuDataArr[this.selectLv-1];
  12. }
  13. selectLv:number=1;
  14. getCurMaxLevel(){
  15. var lv= GameData.GetCustomData(GameConst.canjuLevel);
  16. return Math.max(1,lv);
  17. }
  18. setNewMaxLevel(lv:number){
  19. GameData.SetCustomData(GameConst.canjuLevel,lv)
  20. }
  21. updateMaxLevel(value:number=1){
  22. var lv=this.getCurMaxLevel();
  23. lv+=value;
  24. lv=Math.min(lv,this.MaxLv)
  25. this.setNewMaxLevel(lv);
  26. }
  27. selectNextLv(){
  28. if(this.selectLv<this.MaxLv){
  29. this.selectLv++;
  30. }
  31. else this.selectLv=1;
  32. }
  33. get MaxLv(){
  34. return this.canjuDataArr.length;
  35. }
  36. public isUnlock(index:number){
  37. if(index<=0)return true;
  38. return this.getCurMaxLevel()>=index+1
  39. }
  40. }