Refactor folder item management and move NotifyValue to a new utility header

This commit is contained in:
scawful
2025-01-22 13:32:45 -05:00
parent 50c9223a53
commit a5b94ab173
6 changed files with 75 additions and 78 deletions

View File

@@ -56,16 +56,6 @@ uint32_t ldle3(uint8_t const *const p_arr) { return ldle(p_arr, 3); }
} // namespace
bool StringReplace(std::string &str, const std::string &from,
const std::string &to) {
size_t start = str.find(from);
if (start == std::string::npos) return false;
str.replace(start, from.length(), to);
return true;
}
uint32_t Get24LocalFromPC(uint8_t *data, int addr, bool pc) {
uint32_t ret =
(PcToSnes(addr) & 0xFF0000) | (data[addr + 1] << 8) | data[addr];

View File

@@ -18,9 +18,6 @@ namespace yaze {
*/
namespace core {
bool StringReplace(std::string &str, const std::string &from,
const std::string &to);
/**
* @class ExperimentFlags
* @brief A class to manage experimental feature flags.
@@ -115,52 +112,6 @@ class ExperimentFlags {
}
};
/**
* @class NotifyValue
* @brief A class to manage a value that can be modified and notify when it
* changes.
*/
template <typename T>
class NotifyValue {
public:
NotifyValue() : value_(), modified_(false), temp_value_() {}
NotifyValue(const T &value)
: value_(value), modified_(false), temp_value_() {}
void set(const T &value) {
value_ = value;
modified_ = true;
}
const T &get() {
modified_ = false;
return value_;
}
T &mutable_get() {
modified_ = false;
temp_value_ = value_;
return temp_value_;
}
void apply_changes() {
if (temp_value_ != value_) {
value_ = temp_value_;
modified_ = true;
}
}
void operator=(const T &value) { set(value); }
operator T() { return get(); }
bool modified() const { return modified_; }
private:
T value_;
bool modified_;
T temp_value_;
};
static const std::string kLogFileOut = "yaze_log.txt";
template <typename... Args>
@@ -234,14 +185,6 @@ uint16_t ldle16b_i(uint8_t const *const p_arr, size_t const p_index);
// Load little endian halfword (16-bit) dereferenced from
uint16_t ldle16b(uint8_t const *const p_arr);
struct FolderItem {
std::string name;
std::vector<FolderItem> subfolders;
std::vector<std::string> files;
};
typedef struct FolderItem FolderItem;
} // namespace core
} // namespace yaze

View File

@@ -33,7 +33,7 @@ std::vector<std::string> RemoveIgnoredFiles(
return filtered_files;
}
core::FolderItem LoadFolder(const std::string& folder) {
FolderItem LoadFolder(const std::string& folder) {
// Check if .gitignore exists in the folder
std::ifstream gitignore(folder + "/.gitignore");
std::vector<std::string> ignored_files;
@@ -51,14 +51,14 @@ core::FolderItem LoadFolder(const std::string& folder) {
}
}
core::FolderItem current_folder;
FolderItem current_folder;
current_folder.name = folder;
auto root_files = FileDialogWrapper::GetFilesInFolder(current_folder.name);
current_folder.files = RemoveIgnoredFiles(root_files, ignored_files);
for (const auto& subfolder :
FileDialogWrapper::GetSubdirectoriesInFolder(current_folder.name)) {
core::FolderItem folder_item;
FolderItem folder_item;
folder_item.name = subfolder;
std::string full_folder = current_folder.name + "/" + subfolder;
auto folder_files = FileDialogWrapper::GetFilesInFolder(full_folder);
@@ -80,7 +80,7 @@ core::FolderItem LoadFolder(const std::string& folder) {
for (const auto& subdir :
FileDialogWrapper::GetSubdirectoriesInFolder(full_folder)) {
core::FolderItem subfolder_item;
FolderItem subfolder_item;
subfolder_item.name = subdir;
subfolder_item.files = FileDialogWrapper::GetFilesInFolder(subdir);
folder_item.subfolders.push_back(subfolder_item);

View File

@@ -11,6 +11,12 @@
namespace yaze {
namespace editor {
struct FolderItem {
std::string name;
std::vector<FolderItem> subfolders;
std::vector<std::string> files;
};
/**
* @class AssemblyEditor
* @brief Text editor for modifying assembly code.
@@ -63,7 +69,7 @@ class AssemblyEditor : public Editor {
int current_file_id_ = 0;
std::string current_file_;
core::FolderItem current_folder_;
FolderItem current_folder_;
TextEditor text_editor_;
};

View File

@@ -14,6 +14,7 @@
#include "app/rom.h"
#include "app/zelda3/overworld/overworld.h"
#include "imgui/imgui.h"
#include "util/notify.h"
namespace yaze {
namespace editor {
@@ -23,7 +24,9 @@ namespace editor {
*/
class Tile16Editor : public gfx::GfxContext, public SharedRom {
public:
Tile16Editor(std::array<gfx::Bitmap, zelda3::kNumTile16Individual>& tile16_individual) : tile16_individual_(tile16_individual) {}
Tile16Editor(
std::array<gfx::Bitmap, zelda3::kNumTile16Individual> &tile16_individual)
: tile16_individual_(tile16_individual) {}
absl::Status InitBlockset(const gfx::Bitmap &tile16_blockset_bmp,
const gfx::Bitmap &current_gfx_bmp,
std::array<uint8_t, 0x200> &all_tiles_types);
@@ -60,8 +63,8 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
int current_tile8_ = 0;
uint8_t current_palette_ = 0;
core::NotifyValue<uint32_t> notify_tile16;
core::NotifyValue<uint8_t> notify_palette;
util::NotifyValue<uint32_t> notify_tile16;
util::NotifyValue<uint8_t> notify_palette;
std::array<uint8_t, 0x200> all_tiles_types_;
@@ -85,7 +88,7 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
gui::Canvas transfer_canvas_;
gfx::Bitmap transfer_blockset_bmp_;
std::array<gfx::Bitmap, zelda3::kNumTile16Individual>& tile16_individual_;
std::array<gfx::Bitmap, zelda3::kNumTile16Individual> &tile16_individual_;
std::vector<gfx::Bitmap> current_gfx_individual_;
PaletteEditor palette_editor_;
@@ -94,8 +97,8 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
absl::Status status_;
Rom transfer_rom_;
zelda3::Overworld transfer_overworld_{ transfer_rom_ };
std::array<gfx::Bitmap, kNumGfxSheets> transfer_gfx_;
zelda3::Overworld transfer_overworld_{transfer_rom_};
std::array<gfx::Bitmap, kNumGfxSheets> transfer_gfx_;
absl::Status transfer_status_;
};