chore: cleanup files and move common method

This commit is contained in:
Justin Scofield
2022-08-07 12:38:55 -04:00
parent 465b3fc49b
commit 3b24ce11d0
7 changed files with 20 additions and 16 deletions

View File

@@ -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, "<HOOK>", kMosaicChangeOffset)) {
if (!core::StringReplace(assembly_string, "<HOOK>", kMosaicChangeOffset)) {
return absl::InternalError(
"Mosaic template did not have proper `<HOOK>` to replace.");
}
if (!string_replace(
if (!core::StringReplace(
assembly_string, "<EXPANDED_SPACE>",
absl::StrFormat("$%x", routine_offset + kSNESToPCOffset))) {
return absl::InternalError(

View File

@@ -1,6 +1,7 @@
#include "common.h"
#include <cstdint>
#include <string>
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

View File

@@ -2,6 +2,7 @@
#define YAZE_CORE_COMMON_H
#include <cstdint>
#include <string>
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

View File

@@ -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")) {
}

View File

@@ -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<SDL_Renderer> renderer_;

View File

@@ -21,5 +21,5 @@ bool InputHexShort(const char* label, int* data) {
ImGuiInputTextFlags_CharsHexadecimal);
}
} // namespace Gui
} // namespace gui
} // namespace yaze

View File

@@ -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