Added the AssemblyEditor class

This commit is contained in:
scawful
2022-07-09 18:12:09 -04:00
parent 701e8e19a9
commit a038290ebb
5 changed files with 85 additions and 28 deletions

View File

@@ -0,0 +1,40 @@
#include "assembly_editor.h"
namespace yaze {
namespace app {
namespace editor {
void AssemblyEditor::Update() {
SetEditorText();
auto cpos = text_editor_.GetCursorPosition();
ImGui::Begin("ASM Editor", &file_is_loaded_);
ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1,
cpos.mColumn + 1, text_editor_.GetTotalLines(),
text_editor_.IsOverwrite() ? "Ovr" : "Ins",
text_editor_.CanUndo() ? "*" : " ",
text_editor_.GetLanguageDefinition().mName.c_str(),
current_file_.c_str());
text_editor_.Render(current_file_.c_str());
ImGui::End();
}
void AssemblyEditor::ChangeActiveFile(const std::string & filename) {
current_file_ = filename;
}
void AssemblyEditor::SetEditorText() {
if (!file_is_loaded_) {
std::ifstream t(current_file_);
if (t.good()) {
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
text_editor_.SetText(str);
}
file_is_loaded_ = true;
}
}
} // namespace editor
} // namespace app
} // namespace yaze

View File

@@ -0,0 +1,34 @@
#ifndef YAZE_APP_EDITOR_ASSEMBLY_EDITOR_H
#define YAZE_APP_EDITOR_ASSEMBLY_EDITOR_H
#include <ImGuiColorTextEdit/TextEditor.h>
#include <ImGuiFileDialog/ImGuiFileDialog.h>
#include <fstream>
#include <istream>
#include <string>
namespace yaze {
namespace app {
namespace editor {
class AssemblyEditor {
public:
AssemblyEditor() = default;
void Update();
void ChangeActiveFile(const std::string &);
private:
void SetEditorText();
std::string current_file_;
bool file_is_loaded_ = false;
TextEditor text_editor_;
};
} // namespace editor
} // namespace app
} // namespace yaze
#endif

View File

@@ -176,28 +176,8 @@ void Editor::DrawViewMenu() {
}
if (show_asm_editor) {
static bool asm_is_loaded = false;
auto cpos = asm_editor_.GetCursorPosition();
static const char *fileToEdit = "assets/bunnyhood.asm";
if (!asm_is_loaded) {
std::ifstream t(fileToEdit);
if (t.good()) {
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
asm_editor_.SetText(str);
}
asm_is_loaded = true;
}
ImGui::Begin("ASM Editor", &show_asm_editor);
ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1,
cpos.mColumn + 1, asm_editor_.GetTotalLines(),
asm_editor_.IsOverwrite() ? "Ovr" : "Ins",
asm_editor_.CanUndo() ? "*" : " ",
asm_editor_.GetLanguageDefinition().mName.c_str(), fileToEdit);
asm_editor_.Render(fileToEdit);
ImGui::End();
assembly_editor_.ChangeActiveFile("assets/bunnyhood.asm");
assembly_editor_.Update();
}
if (show_imgui_style_editor) {
@@ -248,8 +228,8 @@ void Editor::DrawGraphicsSheet(int offset) {
unsigned int snes_addr = 0;
unsigned int pc_addr = 0;
snes_addr = (unsigned int)((((rom_.data()[0x4F80 + offset]) << 16) |
((rom_.data()[0x505F + offset]) << 8) |
((rom_.data()[0x513E + offset]))));
((rom_.data()[0x505F + offset]) << 8) |
((rom_.data()[0x513E + offset]))));
pc_addr = core::SnesToPc(snes_addr);
std::cout << "Decompressing..." << std::endl;
char *decomp = rom_.Decompress(pc_addr);
@@ -325,7 +305,7 @@ void Editor::DrawProjectEditor() {
ImGui::InvisibleButton(
"canvas", canvas_sz,
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
const bool is_active = ImGui::IsItemActive(); // Held
const bool is_active = ImGui::IsItemActive(); // Held
const ImVec2 origin(canvas_p0.x + scrolling.x,
canvas_p0.y + scrolling.y); // Lock scrolled origin
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,

View File

@@ -10,6 +10,7 @@
#include "app/core/constants.h"
#include "app/editor/overworld_editor.h"
#include "app/gfx/tile.h"
#include "app/editor/assembly_editor.h"
#include "app/rom.h"
#include "gui/icons.h"
#include "gui/input.h"
@@ -43,12 +44,13 @@ class Editor {
void DrawHUDEditor();
bool is_loaded_ = true;
bool asm_is_loaded = false;
app::rom::ROM rom_;
app::gfx::TilePreset current_set_;
rom::ROM rom_;
gfx::TilePreset current_set_;
TextEditor asm_editor_;
TextEditor::LanguageDefinition language_65816_;
AssemblyEditor assembly_editor_;
OverworldEditor overworld_editor_;
std::shared_ptr<SDL_Renderer> sdl_renderer_;
std::unordered_map<uint, SDL_Texture *> image_cache_;