这是一次长久的提交:

1. 应用界面增加了返回主页的按钮
2. 修复了gif渲染内存泄漏的严重bug
3. 将PetDao当中的cJSON API替换为cpp_json,完美通过测试
4. 整合已经实现的各种上层建筑,实现了一个宠物对话基本业务应用,用于样品测试展示用
5. 重构了音频播放类,使其更modern,更加便于移植和拓展
This commit is contained in:
Misaki
2025-10-16 11:36:45 +08:00
parent 801138631e
commit ba5e47bc77
38 changed files with 2487 additions and 2008 deletions
+16 -17
View File
@@ -5,62 +5,61 @@
#include "PetBaseClass.h"
#include "SDFileManager.h"
#include "cJSON.h"
#include "cpp_json.h"
#include <string>
// 辅助函数:枚举类型与字符串的转换
namespace PetEnumConverter {
// PetStageType 转换
std::string stageTypeToString(PetStageType stage);
PetStageType stringToStageType(const std::string& str);
PetStageType stringToStageType(const std::string &str);
// PetActionType 转换
std::string actionTypeToString(PetActionType action);
PetActionType stringToActionType(const std::string& str);
PetActionType stringToActionType(const std::string &str);
}
// PetDAO 类 - 负责宠物的数据持久化
class PetDAO {
public:
// 构造函数,需要SDFileManager实例
explicit PetDAO(SDFileManager* fileManager);
explicit PetDAO(SDFileManager *fileManager);
// 保存宠物数据到文件
bool savePet(const std::shared_ptr<PetBase>& pet, const std::string& filename);
bool savePet(const std::shared_ptr<PetBase> &pet, const std::string &filename);
// 从文件加载宠物数据
std::shared_ptr<PetBase> loadPet(const std::string& filename);
std::shared_ptr<PetBase> loadPet(const std::string &filename);
// 获取所有保存的宠物文件列表
std::vector<std::string> listPetFiles();
// 删除宠物文件
bool deletePetFile(const std::string& filename);
bool deletePetFile(const std::string &filename);
private:
// 将宠物数据转换为JSON对象
cJSON* petToJson(const std::shared_ptr<PetBase>& pet);
cppjson::Json petToJson(const std::shared_ptr<PetBase> &pet); // 返回 cppjson::Json
// 从JSON对象创建宠物
std::shared_ptr<PetBase> petFromJson(cJSON* json);
std::shared_ptr<PetBase> petFromJson(const cppjson::Json &json); // 参数改为 cppjson::Json
// 将阶段策略转换为JSON对象
cJSON* stageStrategyToJson(const std::shared_ptr<PetStageStrategy>& strategy);
cppjson::Json stageStrategyToJson(const std::shared_ptr<PetStageStrategy> &strategy);
// 从JSON对象创建阶段策略
std::shared_ptr<PetStageStrategy> stageStrategyFromJson(cJSON* json);
std::shared_ptr<PetStageStrategy> stageStrategyFromJson(const cppjson::Json &json);
// 将动作策略转换为JSON对象
cJSON* actionStrategyToJson(const std::shared_ptr<PetActionStrategy>& strategy);
cppjson::Json actionStrategyToJson(const std::shared_ptr<PetActionStrategy> &strategy);
// 从JSON对象创建动作策略
std::shared_ptr<PetActionStrategy> actionStrategyFromJson(cJSON* json);
std::shared_ptr<PetActionStrategy> actionStrategyFromJson(const cppjson::Json &json);
// 文件管理器实例
SDFileManager* fileManager;
SDFileManager *fileManager;
// 宠物数据存储目录
static constexpr const char* PET_DATA_DIR = "/sdcard/pet_data";
static constexpr const char *PET_DATA_DIR = "/sdcard/pet_data";
};
/**
@@ -105,4 +104,4 @@ private:
}
}
}
*/
*/