add trophy logic
This commit is contained in:
59
src/models/DCManager.ts
Normal file
59
src/models/DCManager.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
|
||||
import { respath } from "../constants/respath"
|
||||
|
||||
|
||||
export const MONTH_LIST = [
|
||||
{year: 2024, month: 12, begin: 0, dayCount: 31, icon_res: respath.trophy_12},
|
||||
|
||||
{year: 2025, month: 1, begin: 3, dayCount: 31, icon_res: respath.trophy_01},
|
||||
{year: 2025, month: 2, begin: 6, dayCount: 30, icon_res: respath.trophy_02},
|
||||
{year: 2025, month: 3, begin: 6, dayCount: 31, icon_res: respath.trophy_03},
|
||||
{year: 2025, month: 4, begin: 2, dayCount: 30, icon_res: respath.trophy_04},
|
||||
{year: 2025, month: 5, begin: 4, dayCount: 31, icon_res: respath.trophy_05},
|
||||
{year: 2025, month: 6, begin: 0, dayCount: 30, icon_res: respath.trophy_06},
|
||||
{year: 2025, month: 7, begin: 2, dayCount: 31, icon_res: respath.trophy_07},
|
||||
{year: 2025, month: 8, begin: 5, dayCount: 31, icon_res: respath.trophy_08},
|
||||
{year: 2025, month: 9, begin: 1, dayCount: 30, icon_res: respath.trophy_09},
|
||||
{year: 2025, month: 10, begin: 3, dayCount: 31, icon_res: respath.trophy_10},
|
||||
{year: 2025, month: 11, begin: 6, dayCount: 30, icon_res: respath.trophy_11},
|
||||
{year: 2025, month: 12, begin: 1, dayCount: 31, icon_res: respath.trophy_12},
|
||||
|
||||
{year: 2026, month: 1, begin: 4, dayCount: 31, icon_res: respath.trophy_01},
|
||||
{year: 2026, month: 2, begin: 0, dayCount: 30, icon_res: respath.trophy_02},
|
||||
{year: 2026, month: 3, begin: 0, dayCount: 31, icon_res: respath.trophy_03},
|
||||
{year: 2026, month: 4, begin: 3, dayCount: 30, icon_res: respath.trophy_04},
|
||||
{year: 2026, month: 5, begin: 5, dayCount: 31, icon_res: respath.trophy_05},
|
||||
{year: 2026, month: 6, begin: 1, dayCount: 30, icon_res: respath.trophy_06},
|
||||
{year: 2026, month: 7, begin: 3, dayCount: 31, icon_res: respath.trophy_07},
|
||||
{year: 2026, month: 8, begin: 6, dayCount: 31, icon_res: respath.trophy_08},
|
||||
{year: 2026, month: 9, begin: 2, dayCount: 30, icon_res: respath.trophy_09},
|
||||
{year: 2026, month: 10, begin: 4, dayCount: 31, icon_res: respath.trophy_10},
|
||||
{year: 2026, month: 11, begin: 0, dayCount: 30, icon_res: respath.trophy_11},
|
||||
{year: 2026, month: 12, begin: 2, dayCount: 31, icon_res: respath.trophy_12},
|
||||
]
|
||||
|
||||
|
||||
export function G_getMonthInfo(year: number, month: number): any {
|
||||
for (var i=0; i<MONTH_LIST.length; i++) {
|
||||
var obj = MONTH_LIST[i]
|
||||
if (obj.year == year && obj.month == month) {
|
||||
return obj
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export class DCManager {
|
||||
|
||||
private static instance: DCManager
|
||||
public static getInstance(): DCManager {
|
||||
if (!DCManager.instance) {
|
||||
DCManager.instance = new DCManager()
|
||||
}
|
||||
return DCManager.instance
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
3
src/models/DCManager.ts.meta
Normal file
3
src/models/DCManager.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"uuid": "261c816d-1904-4442-9934-b0d91044ca02"
|
||||
}
|
||||
@@ -31,7 +31,7 @@ export class DOBlock {
|
||||
this.checked = show == this.get_correct()
|
||||
if (this.checked == false)
|
||||
this.set_score(0)
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_score(): number {
|
||||
@@ -39,7 +39,7 @@ export class DOBlock {
|
||||
}
|
||||
public set_score(score: number): void {
|
||||
this.data.score = score
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_notes(): Array<number> {
|
||||
@@ -48,20 +48,20 @@ export class DOBlock {
|
||||
public add_note(noteNumber: number): void {
|
||||
if (this.data.notes.indexOf(noteNumber) < 0) {
|
||||
this.data.notes.push(noteNumber)
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
}
|
||||
public remove_note(noteNumber: number): void {
|
||||
var find = this.data.notes.indexOf(noteNumber)
|
||||
if (find >= 0) {
|
||||
this.data.notes.splice(find, 1)
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
}
|
||||
public clean_notes(): void {
|
||||
if (this.data.notes.length > 0) {
|
||||
this.data.notes = new Array()
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
}
|
||||
//====================================持久化数据
|
||||
|
||||
@@ -107,7 +107,7 @@ export class DOStage {
|
||||
}
|
||||
public set_mistake(mistake: number): void {
|
||||
this.data.mistake = mistake
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_score(): number {
|
||||
@@ -115,7 +115,7 @@ export class DOStage {
|
||||
}
|
||||
public set_score(score: number): void {
|
||||
this.data.score = score
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_duration(): number {
|
||||
@@ -123,7 +123,7 @@ export class DOStage {
|
||||
}
|
||||
public set_duration(duration: number): void {//关卡计时
|
||||
this.data.duration = duration
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_note_open(): boolean {
|
||||
@@ -131,7 +131,7 @@ export class DOStage {
|
||||
}
|
||||
public set_note_open(note_open: boolean): void {
|
||||
this.data.note_open = note_open
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_select_index(): number {
|
||||
@@ -139,7 +139,7 @@ export class DOStage {
|
||||
}
|
||||
public set_select_index(select_index: number): void {//当前选中
|
||||
this.data.select_index = select_index
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_hint(): number {
|
||||
@@ -147,7 +147,7 @@ export class DOStage {
|
||||
}
|
||||
public set_hint(hint: number): void {//提示
|
||||
this.data.hint = hint
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
|
||||
public get_undos(): Array<DataUndo> {
|
||||
@@ -163,14 +163,14 @@ export class DOStage {
|
||||
var dataUndo: DataUndo = {index: index, show: show, notes: _notes}
|
||||
console.log("add_undo >>>>>>>>>>>>>>>>>>>>>>>>>>>>", JSON.stringify(dataUndo))
|
||||
this.data.undos.push(dataUndo)
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
public pop_undo(): DataUndo {
|
||||
var dataUndo: DataUndo
|
||||
if (this.data.undos.length > 0) {
|
||||
dataUndo = this.data.undos[this.data.undos.length-1]
|
||||
this.data.undos.splice(this.data.undos.length-1, 1)
|
||||
StorageManager.getInstance().onChanged()
|
||||
StorageManager.getInstance().onStageChanged()
|
||||
}
|
||||
return dataUndo
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DataProgress, DataUser, StageProgress } from "../types/global";
|
||||
import { DataProgress, DataUser, StageProgress, TrophyRecord } from "../types/global";
|
||||
import { StorageManager } from "./StorageManager"
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export class DOUser {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
public get_doneCountBydate(year: number, month: number): number {
|
||||
public get_doneCountByDate(year: number, month: number): number {
|
||||
var count = 0
|
||||
var key = `${year}-${month}`
|
||||
this.mapDones.forEach((progres: number, stageID: string)=>{
|
||||
@@ -35,6 +35,16 @@ export class DOUser {
|
||||
})
|
||||
return count
|
||||
}
|
||||
public get_isAllDoneByDate(year: number, month: number): boolean {
|
||||
var boolean = true
|
||||
var key = `${year}-${month}`
|
||||
this.mapDones.forEach((progres: number, stageID: string)=>{
|
||||
if (stageID.startsWith(key) && progres < 1) {
|
||||
boolean = false
|
||||
}
|
||||
})
|
||||
return boolean
|
||||
}
|
||||
public update_stage_done(stageID: string, progress: number): void {
|
||||
var find: StageProgress
|
||||
for (var i=0; i<this.data.dones.length; i++) {
|
||||
@@ -52,9 +62,78 @@ export class DOUser {
|
||||
this.data.dones.push(find)
|
||||
}
|
||||
this.mapDones.set(find.stageID, find.progress)
|
||||
StorageManager.getInstance().saveUser()
|
||||
StorageManager.getInstance().onUserChanged()
|
||||
}
|
||||
|
||||
//================奖杯获得记录
|
||||
public get_trophyRecord(year: number, month: number): TrophyRecord {
|
||||
var find: TrophyRecord
|
||||
for (var i=0; i<this.data.trophy_records.length; i++) {
|
||||
var obj = this.data.trophy_records[i]
|
||||
if (obj.year == year && obj.month == month) {
|
||||
find = obj
|
||||
break
|
||||
}
|
||||
}
|
||||
return find
|
||||
}
|
||||
public get_trophyHasNew(): TrophyRecord {
|
||||
var find: TrophyRecord
|
||||
for (var i=0; i<this.data.trophy_records.length; i++) {
|
||||
var obj = this.data.trophy_records[i]
|
||||
if (obj.isNew) {
|
||||
find = obj
|
||||
break
|
||||
}
|
||||
}
|
||||
return find
|
||||
}
|
||||
public set_trophyNew(record: TrophyRecord, isNew: boolean): void {
|
||||
if (record.isNew != isNew) {
|
||||
record.isNew = isNew
|
||||
StorageManager.getInstance().onUserChanged()
|
||||
}
|
||||
}
|
||||
public get_trophyHasUnread(): boolean {
|
||||
var unread = false
|
||||
for (var i=0; i<this.data.trophy_records.length; i++) {
|
||||
var obj = this.data.trophy_records[i]
|
||||
if (obj.read == false) {
|
||||
unread = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return unread
|
||||
}
|
||||
public set_trophyAllread(): void {
|
||||
var changed = false
|
||||
for (var i=0; i<this.data.trophy_records.length; i++) {
|
||||
var obj = this.data.trophy_records[i]
|
||||
if (obj.read == false) {
|
||||
obj.read = true
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
StorageManager.getInstance().onUserChanged()
|
||||
}
|
||||
}
|
||||
public add_trophy_record(year: number, month: number, day: number): void {
|
||||
var find
|
||||
for (var i=0; i<this.data.trophy_records.length; i++) {
|
||||
var obj = this.data.trophy_records[i]
|
||||
if (obj.year == year && obj.month == month) {
|
||||
find = obj
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!find) {
|
||||
this.data.trophy_records.push({year: year, month: month, day: day, isNew: true, read: false})
|
||||
StorageManager.getInstance().onUserChanged()
|
||||
}
|
||||
}
|
||||
|
||||
//=======关卡难度进度
|
||||
public get_progress(difficulty: string): number {
|
||||
var find: DataProgress
|
||||
for (var i=0; i<this.data.progresses.length; i++) {
|
||||
@@ -85,7 +164,7 @@ export class DOUser {
|
||||
find = {difficulty: difficulty, index: index}
|
||||
this.data.progresses.push(find)
|
||||
}
|
||||
StorageManager.getInstance().saveUser()
|
||||
StorageManager.getInstance().onUserChanged()
|
||||
}
|
||||
|
||||
//====================================持久化数据
|
||||
|
||||
@@ -17,6 +17,7 @@ export class StorageManager {
|
||||
}
|
||||
|
||||
private user: DOUser;
|
||||
private userChanged = false
|
||||
|
||||
private stageID: string = "";
|
||||
private stageChanged = false
|
||||
@@ -30,9 +31,11 @@ export class StorageManager {
|
||||
this.user = new DOUser(JSON.parse(jsonStr))
|
||||
}
|
||||
else {
|
||||
this.user = new DOUser({dones: new Array(), progresses: new Array()})
|
||||
this.user = new DOUser({dones: new Array(), trophy_records: new Array(), progresses: new Array()})
|
||||
}
|
||||
}
|
||||
this.userChanged = false
|
||||
|
||||
this.stageID = ""
|
||||
this.stageChanged = false
|
||||
}
|
||||
@@ -42,12 +45,17 @@ export class StorageManager {
|
||||
return this.user
|
||||
}
|
||||
public saveUser(): void {
|
||||
if (this.user) {
|
||||
var jsonStr = JSON.stringify(this.user.getData())
|
||||
Laya.LocalStorage.setItem("user", jsonStr)
|
||||
if (this.userChanged) {
|
||||
this.userChanged = false
|
||||
if (this.user) {
|
||||
var jsonStr = JSON.stringify(this.user.getData())
|
||||
Laya.LocalStorage.setItem("user", jsonStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public onUserChanged(): void {
|
||||
this.userChanged = true
|
||||
}
|
||||
|
||||
public newStage(stageID: string, type: number, name: string, difficulty: string, index: number): DOStage {
|
||||
this.stageID = stageID
|
||||
@@ -104,13 +112,14 @@ export class StorageManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
public onChanged(): void {
|
||||
public onStageChanged(): void {
|
||||
this.stageChanged = true
|
||||
}
|
||||
|
||||
|
||||
public cleanAll(): void {
|
||||
this.user = new DOUser({dones: new Array(), progresses: new Array()})
|
||||
this.user = new DOUser({dones: new Array(), trophy_records: new Array(), progresses: new Array()})
|
||||
this.userChanged = false
|
||||
|
||||
this.stageID = ""
|
||||
this.stageChanged = false
|
||||
|
||||
@@ -2,6 +2,9 @@ import { respath } from "../constants/respath"
|
||||
import { StorageManager } from "./StorageManager"
|
||||
import { Stage } from "../views/Stage"
|
||||
import { DailyChallenge } from "../views/DailyChallenge"
|
||||
import { TrophyRecord } from "../types/global"
|
||||
import { TrophyClaim } from "../views/TrophyClaim"
|
||||
import { TrophyShow } from "../views/TrophyShow"
|
||||
|
||||
|
||||
const { regClass, property } = Laya
|
||||
@@ -45,6 +48,14 @@ export class UIManager extends Laya.Script {
|
||||
})
|
||||
}
|
||||
|
||||
public loadTrophyClaimUI(record: TrophyRecord): void {
|
||||
Laya.loader.load(respath.trophy_claim_ui_res).then((go)=>{
|
||||
var prefab = go.create()
|
||||
var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyClaim)
|
||||
obj.onSetShow(record)
|
||||
})
|
||||
}
|
||||
|
||||
public loadTrophyUI(): void {
|
||||
Laya.loader.load(respath.trophy_ui_res).then((go)=>{
|
||||
var prefab = go.create()
|
||||
@@ -52,6 +63,14 @@ export class UIManager extends Laya.Script {
|
||||
})
|
||||
}
|
||||
|
||||
public loadTrophyShowUI(record: TrophyRecord): void {
|
||||
Laya.loader.load(respath.trophy_show_ui_res).then((go)=>{
|
||||
var prefab = go.create()
|
||||
var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyShow)
|
||||
obj.onSetShow(record)
|
||||
})
|
||||
}
|
||||
|
||||
public loadStageUI(stageID: string): void {
|
||||
if (this.stage) {
|
||||
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
|
||||
|
||||
Reference in New Issue
Block a user