Skip to content

Commit

Permalink
0.5.1a
Browse files Browse the repository at this point in the history
- 0.5.1a Loading files that does not stick to 4 digit object indexing
- 0.5.1a Blending transition hotfix
- 0.5.1a Transition array hotfix
  • Loading branch information
Pentalimbed committed May 12, 2022
1 parent 825dd9a commit 6455cb4
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 27 deletions.
6 changes: 5 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
- 0.5a ListView/PropEdit edit all kinds of hkx file (which they're supposed to but were not due to my stupidity)
- 0.5a Scalar/Reference edit's width set to fixed

- 0.5.1a Loading files that does not stick to 4 digit object indexing
- 0.5.1a Blending transition hotfix
- 0.5.1a Transition array hotfix

Behaviour diagnosis
Display names within the var/state/ref/evt edit when not editing (using combobox?)
Editing character file (anim name & properties)
Nested state id picker
Nested state id picker
4 changes: 2 additions & 2 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ int initApp()

Hkx::HkxFileManager::getSingleton()->appendListener(Hkx::kEventFileChanged, [=]() {
auto file_manager = Hkx::HkxFileManager::getSingleton();
if (auto file = file_manager->getCurrentFile(); file)
glfwSetWindowTitle(g_window, fmt::format("{} [{}]", g_window_title, file->getPath()).c_str());
if (file_manager->isCurrentFileReady())
glfwSetWindowTitle(g_window, fmt::format("{} [{}]", g_window_title, file_manager->getCurrentFile()->getPath()).c_str());
else
glfwSetWindowTitle(g_window, g_window_title);
});
Expand Down
2 changes: 1 addition & 1 deletion src/hkx/hkclass.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ constexpr auto g_class_expr_array = std::to_array<std::string_view>({"hkbE
constexpr auto g_class_binding = std::to_array<std::string_view>({"hkbVariableBindingSet"});
constexpr auto g_class_graph_data = std::to_array<std::string_view>({"hkbBehaviorGraphData"});
constexpr auto g_class_state_chooser = std::to_array<std::string_view>({"hkbStateChooser"});
constexpr auto g_class_transition_array = std::to_array<std::string_view>({"hkbBlendingTrahkbStateMachineTransitionInfoArraynsitionEffect"});
constexpr auto g_class_transition_array = std::to_array<std::string_view>({"hkbStateMachineTransitionInfoArray"});
constexpr auto g_class_events_array = std::to_array<std::string_view>({"hkbStateMachineEventPropertyArray"});
constexpr auto g_class_bone_weights = std::to_array<std::string_view>({"hkbBoneWeightArray"});
constexpr auto g_class_bone_indices = std::to_array<std::string_view>({"hkbBoneIndexArray"});
Expand Down
47 changes: 34 additions & 13 deletions src/hkx/hkxfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void HkxFile::loadFile(std::string_view path)
for (auto hkobject = m_data_node.child("hkobject"); hkobject; hkobject = hkobject.next_sibling("hkobject"))
{
std::string name = hkobject.attribute("name").as_string();
if (name.empty() || (name.length() != 5) || !name.starts_with('#'))
if (name.empty() || !name.starts_with('#'))
{
file_logger->error("hkobject at location {} has no valid name.", hkobject.path());
return;
Expand All @@ -68,6 +68,7 @@ void HkxFile::loadFile(std::string_view path)
uint16_t id = std::atoi(name.data() + 1); // There's a potential crash here...
m_latest_id = std::max(id, m_latest_id);
}
reindexObjInternal(); // in case some file don't follow the 4 digit indexing

m_loaded = true;
}
Expand Down Expand Up @@ -256,16 +257,32 @@ void HkxFile::reindexObj(uint16_t start_id)

file_logger->info("Attempting to reindex all objects...");

reindexObjInternal(start_id);

file_logger->info("All objects reindexed.");
HkxFileManager::getSingleton()->dispatch(kEventObjChanged);
}

void HkxFile::reindexObjInternal(uint16_t start_id)
{
// get the id map
StringMap<std::string> remap = {};

auto new_idx = start_id;
for (uint16_t i = 0; i <= m_latest_id; ++i)
if (auto old_id_str = fmt::format("#{:04}", i); m_obj_list.contains(old_id_str))
{
remap[old_id_str] = fmt::format("#{:04}", new_idx);
++new_idx;
}
auto new_idx = start_id;
std::vector<std::string> obj_list;
getObjList(obj_list);
std::ranges::sort(obj_list);
for (auto& id : obj_list)
{
remap[id] = fmt::format("#{:04}", new_idx);
++new_idx;
}
// for (uint16_t i = 0; i <= m_latest_id; ++i)
// if (auto old_id_str = fmt::format("#{:04}", i); m_obj_list.contains(old_id_str))
// {
// remap[old_id_str] = fmt::format("#{:04}", new_idx);
// ++new_idx;
// }
m_latest_id = new_idx - 1;

// remap the lists
Expand Down Expand Up @@ -325,7 +342,14 @@ void HkxFile::reindexObj(uint16_t start_id)
while (pos != text.npos)
{
if (!pos || (text[pos - 1] != '&')) // in case html entity, fuck html entities
text.replace(pos, 5, m_remap->at(std::string(&text[pos], 5)));
{
auto next_break = pos + 1;
while ((next_break != text.size()) && (text[next_break] >= '0') && (text[next_break] <= '9')) ++next_break;
auto rep_len = next_break - pos;
text.replace(pos, rep_len, m_remap->at(std::string(&text[pos], rep_len)));
pos = next_break;
}

pos = text.find('#', pos + 1);
}
node.text() = text.c_str();
Expand All @@ -338,9 +362,6 @@ void HkxFile::reindexObj(uint16_t start_id)

for (auto [key, obj] : m_obj_list)
obj.attribute("name") = key.c_str();

file_logger->info("All objects reindexed.");
HkxFileManager::getSingleton()->dispatch(kEventObjChanged);
}

//////////////////// BEHAVIOUR
Expand Down Expand Up @@ -669,7 +690,7 @@ void HkxFileManager::loadFile(std::string_view path)
file.loadFile(path);
if (file.isFileLoaded())
{
m_current_file = &m_files[m_files.size() - 1];
m_current_file = &m_files.back();
dispatch(kEventFileChanged);
}
else
Expand Down
3 changes: 3 additions & 0 deletions src/hkx/hkxfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class HkxFile
StringMap<std::vector<std::string>> m_obj_class_list;
StringMap<StringSet> m_obj_ref_list;
StringMap<StringSet> m_obj_ref_by_list;

void reindexObjInternal(uint16_t start_id = 100); // reindex w/o logging & event
};

// Single behaviour file
Expand Down Expand Up @@ -219,6 +221,7 @@ class HkxFileManager : public eventpp::EventDispatcher<HkxFileEventEnum, void()>
dispatch(kEventFileChanged);
}
inline HkxFile* getCurrentFile() { return m_current_file; }
inline bool isCurrentFileReady() { return m_current_file && m_current_file->isFileLoaded(); }

inline std::vector<std::string_view> getPathList()
{
Expand Down
1 change: 1 addition & 0 deletions src/ui/classinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ UICLASS(hkbBlendingTransitionEffect)
"Which blend curve to use.")();
FlagEdit<Hkx::f_hkbBlendingTransitionEffect_FlagBits>(obj.getByName("flags"), file,
"Flags to indicate specialized behavior.")();
ImGui::EndTable();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/columnview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ColumnView::ColumnView()
{
auto file_manager = Hkx::HkxFileManager::getSingleton();
m_file_listener = file_manager->appendListener(Hkx::kEventFileChanged, [=]() {
if (file_manager->getCurrentFile())
if (file_manager->isCurrentFileReady())
m_columns.push_back({});
});

Expand Down
6 changes: 3 additions & 3 deletions src/ui/listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void ListView::show()
if (ImGui::Begin("List View", &m_show))
{
auto file_manager = Hkx::HkxFileManager::getSingleton();
if (auto file = file_manager->getCurrentFile(); file)
if (file_manager->isCurrentFileReady())
{
auto& hkxfile = *file;
auto& hkxfile = *file_manager->getCurrentFile();
if (ImGui::InputText("Filter", &m_filter))
updateCache();
ImGui::SameLine();
Expand Down Expand Up @@ -107,7 +107,7 @@ void ListView::show()

void ListView::updateCache(bool sort_only)
{
if (!Hkx::HkxFileManager::getSingleton()->getCurrentFile())
if (!Hkx::HkxFileManager::getSingleton()->isCurrentFileReady())
return;
auto& hkxfile = *Hkx::HkxFileManager::getSingleton()->getCurrentFile();
if (!sort_only)
Expand Down
10 changes: 5 additions & 5 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ void showMenuBar()
newFile();
if (ImGui::MenuItem("Open", "CTRL+O"))
openFile();
if (ImGui::MenuItem("Save", "CTRL+S", false, file_manager->getCurrentFile() != nullptr))
if (ImGui::MenuItem("Save", "CTRL+S", false, file_manager->isCurrentFileReady()))
file_manager->saveFile();
if (ImGui::MenuItem("Save As", nullptr, false, file_manager->getCurrentFile() != nullptr))
if (ImGui::MenuItem("Save As", nullptr, false, file_manager->isCurrentFileReady()))
saveFileAs();

ImGui::Separator();
Expand All @@ -220,7 +220,7 @@ void showMenuBar()
else
for (int i = 0; i < path_list.size(); ++i)
if (ImGui::MenuItem(path_list[i].data(), nullptr,
(file_manager->getCurrentFile() != nullptr) && (path_list[i] == file_manager->getCurrentFile()->getPath())))
file_manager->isCurrentFileReady() && (path_list[i] == file_manager->getCurrentFile()->getPath())))
file_manager->setCurrentFile(i);

ImGui::Separator();
Expand Down Expand Up @@ -278,9 +278,9 @@ void showMenuBar()
}
if (ImGui::BeginMenu("Edit"))
{
if (ImGui::MenuItem("Build Reference List", nullptr, false, file_manager->getCurrentFile() != nullptr))
if (ImGui::MenuItem("Build Reference List", nullptr, false, file_manager->isCurrentFileReady()))
file_manager->getCurrentFile()->buildRefList();
if (ImGui::MenuItem("Reindex Objects", nullptr, false, file_manager->getCurrentFile() != nullptr))
if (ImGui::MenuItem("Reindex Objects", nullptr, false, file_manager->isCurrentFileReady()))
file_manager->getCurrentFile()->reindexObj();
ImGui::EndMenu();
}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/varedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ void VarEdit::show()
if (ImGui::Begin("Variable/Event List", &m_show, ImGuiWindowFlags_NoScrollbar))
{
auto file_manager = Hkx::HkxFileManager::getSingleton();
if (auto file = file_manager->getCurrentFile(); file)
if (file_manager->isCurrentFileReady())
{
auto file = file_manager->getCurrentFile();
if (file->getType() == Hkx::HkxFile::kBehaviour)
{
if (ImGui::BeginTable("varlisttbl", 2))
Expand Down

0 comments on commit 6455cb4

Please sign in to comment.