Refactor sprite editor to use Zelda3 namespace for default sprite names

This commit is contained in:
scawful
2024-08-20 21:42:50 -04:00
parent a8ed9b7f92
commit dc244ac02d
7 changed files with 13 additions and 124 deletions

View File

@@ -1,9 +1,7 @@
#ifndef YAZE_APP_CORE_CONSTANTS_H
#define YAZE_APP_CORE_CONSTANTS_H
#include <vector>
#include "absl/strings/string_view.h"
#include <string_view>
#define TAB_BAR(w) if (ImGui::BeginTabBar(w)) {
#define END_TAB_BAR() \

View File

@@ -1,48 +0,0 @@
#ifndef YAZE_APP_CORE_NOTIFICATION_H
#define YAZE_APP_CORE_NOTIFICATION_H
#include <any>
#include <string>
#include <unordered_map>
#include <vector>
#include "app/core/message.h"
namespace yaze {
namespace app {
namespace core {
struct Notification : public Message {
Notification(const std::string& type, void* sender, std::any payload)
: Message{type, sender, payload} {}
};
class NotificationCenter {
public:
void AddObserver(const std::string& notificationType,
IMessageListener* observer) {
observers[notificationType].push_back(observer);
}
void RemoveObserver(const std::string& notificationType,
IMessageListener* observer) {
auto& observerList = observers[notificationType];
observerList.erase(
std::remove(observerList.begin(), observerList.end(), observer),
observerList.end());
}
void PostNotification(const Notification& notification) {
const auto& observerList = observers[notification.type];
for (auto observer : observerList) {
observer->OnMessageReceived(notification);
}
}
private:
std::unordered_map<std::string, std::vector<IMessageListener*>> observers;
};
} // namespace core
} // namespace app
} // namespace yaze

View File

@@ -384,7 +384,7 @@ void DrawSpriteTable(std::function<void(int)> onSpriteSelect) {
// Initialize items if empty
if (items.empty()) {
for (int i = 0; i < 256; ++i) {
items.push_back(SpriteItem{i, kSpriteDefaultNames[i].data()});
items.push_back(SpriteItem{i, zelda3::kSpriteDefaultNames[i].data()});
}
}

View File

@@ -4,6 +4,7 @@
#include "app/editor/sprite/zsprite.h"
#include "app/gui/icons.h"
#include "app/gui/input.h"
#include "app/zelda3/sprite/sprite.h"
namespace yaze {
namespace app {
@@ -71,13 +72,13 @@ void SpriteEditor::DrawVanillaSpriteEditor() {
for (int n = 0; n < active_sprites_.Size;) {
bool open = true;
if (active_sprites_[n] > sizeof(kSpriteDefaultNames) / 4) {
if (active_sprites_[n] > sizeof(zelda3::kSpriteDefaultNames) / 4) {
active_sprites_.erase(active_sprites_.Data + n);
continue;
}
if (ImGui::BeginTabItem(
kSpriteDefaultNames[active_sprites_[n]].data(), &open,
zelda3::kSpriteDefaultNames[active_sprites_[n]].data(), &open,
ImGuiTabItemFlags_None)) {
DrawSpriteCanvas();
ImGui::EndTabItem();
@@ -188,10 +189,10 @@ void SpriteEditor::DrawSpritesList() {
ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
ImGuiWindowFlags_NoDecoration)) {
int i = 0;
for (const auto each_sprite_name : kSpriteDefaultNames) {
for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) {
rom()->resource_label()->SelectableLabelWithNameEdit(
current_sprite_id_ == i, "Sprite Names", core::UppercaseHexByte(i),
kSpriteDefaultNames[i].data());
zelda3::kSpriteDefaultNames[i].data());
if (ImGui::IsItemClicked()) {
current_sprite_id_ = i;
if (!active_sprites_.contains(i)) {

View File

@@ -1,8 +1,9 @@
#include "snes_tile.h"
#include <cassert>
#include <cstdint>
#include <vector>
#include <stdexcept>
#include <vector>
#include "app/core/constants.h"
@@ -148,7 +149,8 @@ std::vector<uint8_t> Convert4bppTo3bpp(const std::vector<uint8_t>& tiles) {
return ConvertBpp(tiles, 4, 3);
}
std::vector<uint8_t> SnesTo8bppSheet(const std::vector<uint8_t>& sheet, int bpp) {
std::vector<uint8_t> SnesTo8bppSheet(const std::vector<uint8_t>& sheet,
int bpp) {
int xx = 0; // positions where we are at on the sheet
int yy = 0;
int pos = 0;
@@ -200,7 +202,8 @@ std::vector<uint8_t> SnesTo8bppSheet(const std::vector<uint8_t>& sheet, int bpp)
return sheet_buffer_out;
}
std::vector<uint8_t> Bpp8SnesToIndexed(std::vector<uint8_t> data, uint64_t bpp) {
std::vector<uint8_t> Bpp8SnesToIndexed(std::vector<uint8_t> data,
uint64_t bpp) {
// 3BPP
// [r0,bp1],[r0,bp2],[r1,bp1],[r1,bp2],[r2,bp1],[r2,bp2],[r3,bp1],[r3,bp2]
// [r4,bp1],[r4,bp2],[r5,bp1],[r5,bp2],[r6,bp1],[r6,bp2],[r7,bp1],[r7,bp2]

View File

@@ -1,26 +0,0 @@
LIBRARY snes_spc
DESCRIPTION "snes_spc 0.9.0"
EXPORTS
spc_new @1
spc_delete @2
spc_init_rom @3
spc_set_output @4
spc_sample_count @5
spc_reset @6
spc_soft_reset @7
spc_read_port @8
spc_write_port @9
spc_end_frame @10
spc_mute_voices @11
spc_disable_surround @12
spc_set_tempo @13
spc_load_spc @14
spc_clear_echo @15
spc_play @16
spc_skip @17
spc_filter_new @18
spc_filter_delete @19
spc_filter_run @20
spc_filter_clear @21
spc_filter_set_gain @22
spc_filter_set_bass @23