Adapt for web, make CharacterState class

This commit is contained in:
Vladislav Khorev committed 2026-06-18 20:02:59 +03:00
1 parent c891161d69
commit 0eb9d0be25
88 files changed
+810 -102277

No files matched your search

+19 -26
View File
@@ -345,13 +345,13 @@ namespace ZL {
continue;
}
auto loadOptionalAnim = [&](AnimationState state, const std::string& path, const char* label) {
auto loadOptionalAnim = [&](AnimationState animState, const std::string& path, const char* label) {
if (path.empty()) return;
try {
if (path.size() >= 5 && path.substr(path.size() - 5) == ".anim")
npc->loadBinaryAnimation(state, path, zipPath);
npc->loadBinaryAnimation(animState, path, zipPath);
else
npc->loadAnimation(state, path, zipPath);
npc->loadAnimation(animState, path, zipPath);
std::cout << " Loaded " << label << " animation: " << path << std::endl;
} catch (const std::exception& e) {
std::cerr << "GameObjectLoader: Failed to load " << label
@@ -366,35 +366,28 @@ namespace ZL {
loadOptionalAnim(AnimationState::DEATH_IDLE, npcData.animationDeathIdlePath, "DEATH_IDLE");
try {
if (!npcData.meshTextures.empty()) {
for (const auto& entry : npcData.meshTextures) {
//set_Texture(*npc, entry.first, CreateTextureDataFromPng(entry.second, zipPath.c_str()));
npc->setTexture(entry.first, std::make_shared<Texture>(CreateTextureDataFromPng(entry.second, zipPath.c_str())));
for (const auto& entry : npcData.meshTextures) {
npc->setTexture(entry.first, std::make_shared<Texture>(CreateTextureDataFromPng(entry.second, zipPath.c_str())));
std::cout << " -> mesh '" << entry.first << "'" << std::endl;
}
} else {
//set_Texture(*npc, CreateTextureDataFromPng(npcData.texturePath, zipPath.c_str()));
npc->setTexture(std::make_shared<Texture>(CreateTextureDataFromPng(npcData.texturePath, zipPath.c_str())));
std::cout << " Loaded texture: " << npcData.texturePath << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "GameObjectLoader: Failed to load texture for '" << npcData.name << "': " << e.what() << std::endl;
continue;
}
npc->walkSpeed = npcData.walkSpeed;
npc->rotationSpeed = npcData.rotationSpeed;
npc->modelScale = npcData.modelScale;
npc->position = Eigen::Vector3f(npcData.positionX, npcData.positionY, npcData.positionZ);
npc->facingAngle = npcData.facingAngle;
npc->setHp(npcData.hp);
npc->initialHp = npcData.hp;
npc->canAttack = npcData.canAttack;
npc->enabled = npcData.enabled;
npc->interactionRadius = npcData.interactionRadius;
npc->npcId = npcData.id;
npc->npcName = npcData.name;
npc->state.walkSpeed = npcData.walkSpeed;
npc->state.rotationSpeed = npcData.rotationSpeed;
npc->state.modelScale = npcData.modelScale;
npc->state.position = Eigen::Vector3f(npcData.positionX, npcData.positionY, npcData.positionZ);
npc->state.facingAngle = npcData.facingAngle;
npc->state.setHp(npcData.hp);
npc->state.initialHp = npcData.hp;
npc->state.canAttack = npcData.canAttack;
npc->state.enabled = npcData.enabled;
npc->state.interactionRadius = npcData.interactionRadius;
npc->state.npcId = npcData.id;
npc->state.npcName = npcData.name;
Eigen::Quaternionf corrRot = Eigen::Quaternionf::Identity();
if (npcData.modelCorrectionRotX != 0.0f)
@@ -403,9 +396,9 @@ namespace ZL {
corrRot = Eigen::Quaternionf(Eigen::AngleAxisf(npcData.modelCorrectionRotY, Eigen::Vector3f::UnitY())) * corrRot;
if (npcData.modelCorrectionRotZ != 0.0f)
corrRot = Eigen::Quaternionf(Eigen::AngleAxisf(npcData.modelCorrectionRotZ, Eigen::Vector3f::UnitZ())) * corrRot;
npc->modelCorrectionRotation = corrRot;
npc->state.modelCorrectionRotation = corrRot;
npc->setTarget(npc->position);
npc->setTarget(npc->state.position);
npcs.push_back(std::move(npc));
std::cout << "Successfully loaded NPC: " << npcData.name << " at ("