From 3b24ce11d0d11ed6fbaeeb826a21034c6484bcd7 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:38:55 -0400 Subject: [PATCH] chore: cleanup files and move common method --- src/app/asm/script.cc | 14 +++----------- src/app/core/common.cc | 12 +++++++++++- src/app/core/common.h | 3 +++ src/app/editor/palette_editor.cc | 1 - src/app/rom.h | 2 +- src/gui/input.cc | 2 +- src/gui/input.h | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/app/asm/script.cc b/src/app/asm/script.cc index 6203353f..e7bc30b0 100644 --- a/src/app/asm/script.cc +++ b/src/app/asm/script.cc @@ -12,6 +12,7 @@ #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" +#include "app/core/common.h" #include "app/core/constants.h" #include "app/rom.h" @@ -19,15 +20,6 @@ namespace yaze { namespace app { namespace snes_asm { -static auto string_replace(std::string &str, const std::string &from, - const std::string &to) -> bool { - size_t start = str.find(from); - if (start == std::string::npos) return false; - - str.replace(start, from.length(), to); - return true; -} - std::string GenerateBytePool(char mosaic_tiles[core::kNumOverworldMaps]) { std::string to_return = ""; int column = 0; @@ -89,12 +81,12 @@ absl::Status Script::GenerateMosaicChangeAssembly( file.close(); auto assembly_string = assembly.str(); - if (!string_replace(assembly_string, "", kMosaicChangeOffset)) { + if (!core::StringReplace(assembly_string, "", kMosaicChangeOffset)) { return absl::InternalError( "Mosaic template did not have proper `` to replace."); } - if (!string_replace( + if (!core::StringReplace( assembly_string, "", absl::StrFormat("$%x", routine_offset + kSNESToPCOffset))) { return absl::InternalError( diff --git a/src/app/core/common.cc b/src/app/core/common.cc index 1a280333..a8d0ee85 100644 --- a/src/app/core/common.cc +++ b/src/app/core/common.cc @@ -1,6 +1,7 @@ #include "common.h" #include +#include namespace yaze { namespace app { @@ -19,7 +20,7 @@ int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) { } // hextodec has been imported from SNESDisasm to parse hex numbers -int HexToDec(char* input, int length) { +int HexToDec(char *input, int length) { int result = 0; int value; int ceiling = length - 1; @@ -48,6 +49,15 @@ int HexToDec(char* input, int length) { return result; } +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; +} + } // namespace core } // namespace app } // namespace yaze diff --git a/src/app/core/common.h b/src/app/core/common.h index 5217f66f..4a6969a5 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -2,6 +2,7 @@ #define YAZE_CORE_COMMON_H #include +#include namespace yaze { namespace app { @@ -10,6 +11,8 @@ namespace core { unsigned int SnesToPc(unsigned int addr); int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3); int HexToDec(char *input, int length); +bool StringReplace(std::string &str, const std::string &from, + const std::string &to); } // namespace core } // namespace app diff --git a/src/app/editor/palette_editor.cc b/src/app/editor/palette_editor.cc index bee5abb4..e22f88a6 100644 --- a/src/app/editor/palette_editor.cc +++ b/src/app/editor/palette_editor.cc @@ -14,7 +14,6 @@ namespace editor { absl::Status PaletteEditor::Update() { for (const auto &name : kPaletteCategoryNames) { if (ImGui::TreeNode(name.data())) { - ImGui::SameLine(); if (ImGui::SmallButton("button")) { } diff --git a/src/app/rom.h b/src/app/rom.h index 9f95f8a2..3039664f 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -114,9 +114,9 @@ class ROM { private: long size_ = 0; - std::string filename_; uchar title[21] = "ROM Not Loaded"; bool is_loaded_ = false; + std::string filename_; Bytes rom_data_; std::shared_ptr renderer_; diff --git a/src/gui/input.cc b/src/gui/input.cc index 2596d423..ccbe6870 100644 --- a/src/gui/input.cc +++ b/src/gui/input.cc @@ -21,5 +21,5 @@ bool InputHexShort(const char* label, int* data) { ImGuiInputTextFlags_CharsHexadecimal); } -} // namespace Gui +} // namespace gui } // namespace yaze diff --git a/src/gui/input.h b/src/gui/input.h index f99c2884..c5704258 100644 --- a/src/gui/input.h +++ b/src/gui/input.h @@ -13,7 +13,7 @@ namespace gui { IMGUI_API bool InputHex(const char* label, int* data); IMGUI_API bool InputHexShort(const char* label, int* data); -} // namespace Gui +} // namespace gui } // namespace yaze #endif \ No newline at end of file