feat: group 1.0.0
This commit is contained in:
92
assets/seripts/libs/Common.ts
Normal file
92
assets/seripts/libs/Common.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 游戏开发者:程序员加菲猫
|
||||
* 游戏名称:Like A Dino!
|
||||
*/
|
||||
|
||||
import { Color, Node, Sprite } from "cc";
|
||||
import { GlobalData } from "../config/GlobalData";
|
||||
import { DataManager } from "./DataManager";
|
||||
|
||||
//公共业务方法类
|
||||
export default class Common {
|
||||
/**
|
||||
* 加载对应的音乐音符数据
|
||||
* @param musicID 音乐ID
|
||||
* @returns 音乐音符数据对象
|
||||
*/
|
||||
public static async loadMusicNoteData(musicID: number): Promise<any | null> {
|
||||
return await DataManager.loadJson<any>(`data/music_${musicID}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否解锁了指定的音乐
|
||||
* @param musicID 音乐ID
|
||||
* @returns 是否解锁了指定的音乐
|
||||
*/
|
||||
public static isMusicUnlocked(musicID: number): boolean {
|
||||
return GlobalData.unlockMusicIDList?.includes(musicID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁指定的音乐
|
||||
* @param musicID 音乐ID
|
||||
*/
|
||||
public static unlockMusic(musicID: number) {
|
||||
//如果已经解锁了,则直接返回
|
||||
if (Common.isMusicUnlocked(musicID)) {
|
||||
return;
|
||||
}
|
||||
let unlockMusicIDList = GlobalData.unlockMusicIDList || [];
|
||||
//解锁音乐,并存储到本地缓存中
|
||||
unlockMusicIDList?.push(musicID);
|
||||
//更新本地缓存
|
||||
GlobalData.unlockMusicIDList = unlockMusicIDList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否解锁了指定的小恐龙
|
||||
* @param dinoID 小恐龙ID
|
||||
* @returns 是否解锁了指定的小恐龙
|
||||
*/
|
||||
public static isDinoUnlocked(dinoID: number): boolean {
|
||||
return GlobalData.unlockDinoIDList?.includes(dinoID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁指定的小恐龙
|
||||
* @param dinoID 小恐龙ID
|
||||
*/
|
||||
public static unlockDino(dinoID: number) {
|
||||
//如果已经解锁了,则直接返回
|
||||
if (Common.isDinoUnlocked(dinoID)) {
|
||||
return;
|
||||
}
|
||||
let unlockDinoIDList = GlobalData.unlockDinoIDList || [];
|
||||
//解锁小恐龙,并存储到本地缓存中
|
||||
unlockDinoIDList?.push(dinoID);
|
||||
//更新本地缓存
|
||||
GlobalData.unlockDinoIDList = unlockDinoIDList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置页面背景色
|
||||
* @param node 页面节点
|
||||
* @param color 背景色
|
||||
*/
|
||||
public static setPageBackgroundColor(node: Node, color: Color) {
|
||||
node.getComponent(Sprite).color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置页面背景色和小恐龙背景色相同
|
||||
* @param node 页面节点
|
||||
*/
|
||||
public static setPageBackgroundColorAsDino(node: Node) {
|
||||
// 获取当前小恐龙信息
|
||||
const dinoInfo = GlobalData.currentDinoInfo;
|
||||
// 获取背景色
|
||||
const backgroundColor = new Color(dinoInfo.bgColor);
|
||||
// 设置页面的背景颜色
|
||||
this.setPageBackgroundColor(node.getChildByName("bg"), backgroundColor);
|
||||
}
|
||||
}
|
||||
9
assets/seripts/libs/Common.ts.meta
Normal file
9
assets/seripts/libs/Common.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b80b50f7-99b8-4174-9ee1-e3a0b698d4ea",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
22
assets/seripts/libs/DataManager.ts
Normal file
22
assets/seripts/libs/DataManager.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { _decorator, JsonAsset, resources } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("DataManager")
|
||||
export class DataManager {
|
||||
/**
|
||||
* 从resources目录读取JSON文件
|
||||
* @param path 文件路径(不包含扩展名)
|
||||
*/
|
||||
public static async loadJson<T>(path: string): Promise<T | null> {
|
||||
return new Promise((resolve) => {
|
||||
resources.load(path, JsonAsset, (err, asset) => {
|
||||
if (err) {
|
||||
console.error(`加载JSON文件失败: ${path}`, err);
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
resolve(asset.json as T);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
9
assets/seripts/libs/DataManager.ts.meta
Normal file
9
assets/seripts/libs/DataManager.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "de375e5e-601f-472d-bbe7-e9ada0277697",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -34,6 +34,12 @@ export class EventDispatcher {
|
||||
public static readonly SHOW_PAUSE_MODAL = "show_pause_modal";
|
||||
// 显示继续游戏弹窗事件
|
||||
public static readonly SHOW_CONTINUE_MODAL = "show_continue_modal";
|
||||
// 提示消息事件
|
||||
public static readonly TIP_MSG = "tip_msg";
|
||||
// 选中音乐列表某一个 item 事件
|
||||
public static readonly SELECT_MOOD_ITEM = "select_mood_item";
|
||||
// 解锁音乐列表某一个 item 事件
|
||||
public static readonly UNLOCK_MOOD_ITEM = "unlock_mood_item";
|
||||
|
||||
static getTarget() {
|
||||
if (EventDispatcher.data == null) {
|
||||
|
||||
Reference in New Issue
Block a user