yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
screen_graphics_context.cc
Go to the documentation of this file.
2
3#include <algorithm>
4#include <cstdint>
5#include <vector>
6
7#include "absl/status/status.h"
8#include "absl/status/statusor.h"
9#include "absl/strings/str_format.h"
11#include "zelda3/game_data.h"
13
14namespace yaze::editor {
15
16// The Screen editor's ROM-backed Dungeon Map / Tiles Gfx picker is four
17// 128x32 sheets stacked into a 128x128, 8x8-tile atlas. Its displayed raw
18// indices use the first eight colors of dungeon_main[3]. This is deliberately
19// separate from the map's Tile16 composition and its per-tile palette words.
20absl::StatusOr<usage_preview::PreviewImage> RenderDungeonMapTilesGfxPreview(
21 const zelda3::GameData* owner) {
22 if (owner == nullptr || owner->palette_groups.dungeon_main.size() <= 3) {
23 return absl::FailedPreconditionError(
24 "Dungeon Map / Tiles Gfx palette is unavailable");
25 }
26 const auto& palette = owner->palette_groups.dungeon_main[3];
27 if (palette.size() < 8) {
28 return absl::FailedPreconditionError(
29 "Dungeon Map / Tiles Gfx needs eight preview colors");
30 }
31
33 image.width = 128;
34 image.height = 128;
35 image.pixels.resize(128 * 128);
36 for (int slot = 0; slot < 4; ++slot) {
37 const auto sheet = owner->sheet_store.Sheet(212 + slot);
38 if (sheet.size() != 128 * 32) {
39 return absl::FailedPreconditionError(
40 absl::StrFormat("Dungeon Map sheet %d is not loaded", 212 + slot));
41 }
42 std::copy(sheet.begin(), sheet.end(),
43 image.pixels.begin() + slot * 128 * 32);
44 }
45 for (int color = 0; color < 8; ++color) {
46 const auto rgb = palette[color].rgb();
47 image.colors[color] =
48 SDL_Color{static_cast<uint8_t>(rgb.x), static_cast<uint8_t>(rgb.y),
49 static_cast<uint8_t>(rgb.z), 255};
50 }
51 return image;
52}
53
54absl::StatusOr<GraphicsEditContext> MakeDungeonMapTilesGfxEditContext(
55 const zelda3::GameData* owner, int selected_tile8, bool binary_gfx_loaded) {
56 if (binary_gfx_loaded) {
57 return absl::FailedPreconditionError(
58 "BIN graphics are not ROM sheets; reopen Screen assets to edit ROM "
59 "Dungeon Map tiles");
60 }
61 if (selected_tile8 < 0 || selected_tile8 >= 256) {
62 return absl::InvalidArgumentError(
63 "Select a Dungeon Map Tiles Gfx tile from 0 to 255");
64 }
65 const auto preview = RenderDungeonMapTilesGfxPreview(owner);
66 if (!preview.ok()) {
67 return preview.status();
68 }
69 const uint16_t sheet_id = static_cast<uint16_t>(212 + selected_tile8 / 64);
70 if (zelda3::GetGfxSheetStorageKind(sheet_id) ==
72 return absl::FailedPreconditionError(
73 "Selected Dungeon Map sheet is not 3bpp");
74 }
75 const auto& palette = owner->palette_groups.dungeon_main[3];
76 std::vector<gfx::SnesColor> colors;
77 colors.reserve(8);
78 for (int index = 0; index < 8; ++index) {
79 colors.push_back(palette[index]);
80 }
81
82 GraphicsEditContext context;
83 context.owner = owner;
84 context.label = "Dungeon Map / Tiles Gfx / raw palette row 0";
85 context.limitation =
86 "This previews raw 3bpp tile indices with dungeon_main[3] colors 0-7; "
87 "Tile16 composition and map palette words are separate.";
88 context.targets.push_back({
89 .sheet_id = sheet_id,
90 .tile_index = static_cast<uint16_t>(selected_tile8 % 64),
91 .label = absl::StrFormat("Dungeon Map Tiles Gfx tile %d / sheet %d / "
92 "local tile %d / raw row 0",
93 selected_tile8, sheet_id, selected_tile8 % 64),
94 .palette = gfx::SnesPalette(colors),
95 });
96 context.resolved.surface = "dungeon_map_tiles_gfx";
97 context.resolved.id = selected_tile8;
98 context.resolved.graphics_loaded = true;
99 context.resolved.loader_agrees = true;
100 context.resolved.palette_colors_resolved = true;
101 for (int slot = 0; slot < 4; ++slot) {
102 context.resolved.slots.push_back({
103 .slot = slot,
104 .role = "dungeon_map_tiles_gfx",
105 .palette_group = "dungeon_main",
106 .sheet_id = 212 + slot,
107 .source = "fixed_rom_sheet",
108 .loader_agrees = true,
109 .store_revision = owner->sheet_store.Revision(212 + slot),
110 .width = 128,
111 .height = 32,
112 });
113 }
114 context.resolved.palettes.push_back(
115 {"raw_preview", "dungeon_main", 3, false});
116 context.render_preview = [owner] {
118 };
119 return context;
120}
121
122} // namespace yaze::editor
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
uint64_t Revision(uint16_t sheet) const
absl::Span< const uint8_t > Sheet(uint16_t sheet) const
The sheet's 4096 pixels, or an empty span when it is not held.
Locates graphics sheets in the ROM and writes edited sheets back.
Editors are the view controllers for the application.
absl::StatusOr< usage_preview::PreviewImage > RenderDungeonMapTilesGfxPreview(const zelda3::GameData *owner)
absl::StatusOr< GraphicsEditContext > MakeDungeonMapTilesGfxEditContext(const zelda3::GameData *owner, int selected_tile8, bool binary_gfx_loaded)
GfxSheetStorageKind GetGfxSheetStorageKind(uint16_t sheet_id)
zelda3::ResolvedGraphicsContext resolved
std::vector< GraphicsEditTarget > targets
std::function< absl::StatusOr< usage_preview::PreviewImage >()> render_preview
gfx::PaletteGroupMap palette_groups
Definition game_data.h:95
std::vector< ResolvedPaletteSource > palettes
std::vector< ResolvedGraphicsSlot > slots