123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import EventName from "../EventName/EventName";
- import TimeOver from "../GameUI/TimeOver";
- export var WorkState = {
- 引导: 0,
- 上班: 1,
- 加班: 2,
- }
- //本地数据管理
- export default class LocalData {
- //临时数据 不保存
- //每日免费游玩总次数
- public FreePlayCount: number = 333;
- //当前免费游玩次数
- private $FreeGameCount: number;
- private static _instance: LocalData = null;
- public static getInstance() {
- if (!this._instance) {
- this._instance = new LocalData();
- this._instance.init();
- }
- return this._instance;
- }
- private readonly $localkey: string = "Daegongsi1";
- //上次登录时间
- private lastLoginTime: number = 0;
- //临时时间停止次数
- private $TimeStopCount: number = 0;
- //弹射入座次数
- private $NowSitDownCount: number = 0;
- //关卡状态
- private $_WorkState = WorkState.引导;
- private $Music: boolean = true;
- private $Effects: boolean = true;
- private $Shake: boolean = true;
- //我的职场等级
- private MyWorkplaceLevel: number = 1;
- public init() {
- // 尝试从本地存储中获取上次登录的时间戳
- const storedLastLogin = localStorage.getItem('lastLoginTime');
- this.lastLoginTime = storedLastLogin ? parseInt(storedLastLogin) : 0;
- this.load();
- this.Restore()
- this.save();
- }
- ////////////////////////////////////////////加班状态
- public setWorkState(Temp: number) {
- this.$_WorkState = Temp
- this.save();
- }
- public getWorkState() {
- return this.$_WorkState;//
- }
- /////////////////////////////////////////////我的职场等级
- public setMyWorkplaceLevel(num: number) {
- this.MyWorkplaceLevel = num
- }
- public getMyWorkplaceLevel() {
- return this.MyWorkplaceLevel;
- }
- public getMyWorkplaceLevel_Name(num?: number): string {
- let temp = 0
- if (num) {
- temp = num
- } else {
- temp = this.MyWorkplaceLevel
- }
- let name = {
- 1: '实习生',
- 2: '正式员工',
- 3: '资深员工',
- 4: '小组长',
- 5: '主管',
- 6: '总监',
- 7: '部门经理',
- 8: '副总经理',
- 9: '总经理',
- 10: '执行副总裁',
- 11: '不用执行副总裁',
- 12: '首席运营官',
- 13: 'CE0',
- 14: '董事长',
- }
- return name[temp]
- }
- /////////////////////////////////////////////时间停止次数
- public setTimeStopCount(num: number) {
- this.$TimeStopCount = num
- this.save();
- cc.systemEvent.emit(EventName.UpdataPropCount)
- }
- public LessTimeStopCount() {
- if (this.$TimeStopCount > 0) {
- this.$TimeStopCount--
- this.save();
- cc.systemEvent.emit(EventName.UpdataPropCount)
- }
- }
- public AddTimeStopCount() {
- this.$TimeStopCount++
- this.save();
- cc.systemEvent.emit(EventName.UpdataPropCount)
- }
- public getTimeStopCount() {
- return this.$TimeStopCount;
- }
- /////////////////////////////////////////////弹射入座次数
- public setNowSitDownCount(num: number) {
- this.$NowSitDownCount = num
- this.save();
- cc.systemEvent.emit(EventName.UpdataPropCount)
- }
- public LessNowSitDownCount() {
- if (this.$NowSitDownCount > 0) {
- this.$NowSitDownCount--
- this.save();
- cc.systemEvent.emit(EventName.UpdataPropCount)
- }
- }
- public AddNowSitDownCount() {
- this.$NowSitDownCount++
- this.save();
- cc.systemEvent.emit(EventName.UpdataPropCount)
- }
- public getNowSitDownCount() {
- return this.$NowSitDownCount;
- }
- /////////////////////////////////////////////巴士皮肤
- public getBusSkin() {
- // return this.BusSkin;
- //1 巴士
- //2 地铁
- //3 豪车
- //4 高铁
- //5 火车
- //6 游艇
- //7 飞机
- let temp: { [key: number]: number } = {
- 1: 1,
- 2: 1,
- 3: 2,
- 4: 2,
- 5: 5,
- 6: 5,
- 7: 4,
- 8: 4,
- 9: 7,
- 10: 7,
- 11: 3,
- 12: 3,
- 13: 6,
- 14: 6,
- }
- return temp[this.MyWorkplaceLevel]
- }
- /////////////////////////////////////////////设置
- public setMusic(Temp: boolean) {
- this.$Music = Temp
- this.save();
- }
- public getMusic() {
- return this.$Music;
- }
- public setEffects(Temp: boolean) {
- this.$Effects = Temp
- this.save();
- }
- public getEffects() {
- return this.$Effects;
- }
- public setVibrate(Temp: boolean) {
- this.$Shake = Temp
- this.save();
- }
- public getVibrate() {
- return this.$Shake;
- }
- /////////////////////////////////////////////免费游玩局数设置
- //还原
- private FreeGameCountResorte() {
- this.$FreeGameCount = this.FreePlayCount
- this.save();
- }
- // 设置
- public setFreeGameCount(num: number) {
- this.$FreeGameCount = num
- this.save();
- }
- // 得到
- public getFreeGameCount() {
- return this.$FreeGameCount;
- }
- //保存玩家本地数据
- public save() {
- let data: any = {};
- for (const key in this) {
- if (Object.prototype.hasOwnProperty.call(this, key)) {
- if (key.charAt(0) == '$') {
- data[key] = this[key];
- }
- }
- }
- cc.sys.localStorage.setItem(this.$localkey, JSON.stringify(data));
- }
- //加载玩家本地数据
- private load() {
- let data = cc.sys.localStorage.getItem(this.$localkey);
- if (data) {
- data = JSON.parse(data);
- for (const key in data) {
- this[key] = data[key];
- }
- }
- }
- //每日还原默认值
- private Restore() {
- if (this.checkIfNewDay()) {
- //还原每日游玩次数
- this.FreeGameCountResorte()
- TimeOver.isVideobtn=false
- }else{
- TimeOver.isVideobtn=true
- }
- }
- public checkIfNewDay(): boolean {
- const currentDate = new Date();
- const todayStart = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()).getTime();
- const isNewDay = todayStart > this.lastLoginTime;
- // 更新上次登录时间为今天
- this.lastLoginTime = todayStart;
- localStorage.setItem('lastLoginTime', this.lastLoginTime.toString());
- return isNewDay;
- }
- }
|