yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
palette_controls_panel_internal.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_PALETTE_CONTROLS_PANEL_INTERNAL_H_
2#define YAZE_APP_EDITOR_GRAPHICS_PALETTE_CONTROLS_PANEL_INTERNAL_H_
3
4#include <cstddef>
5#include <string_view>
6
7namespace yaze {
8namespace editor {
9namespace internal {
10
11// Row-layout for a palette group's display in the panel.
12//
13// colors_per_row - cells across (e.g. 16 for HUD, 7 for OW main).
14// has_explicit_transparent - true if column 0 of the row is the SNES
15// transparent slot (rendered, but skipped when
16// building a sub-palette slice for sheets).
21
22// Determine the panel's row-layout for a named palette group.
23//
24// NOTE on a deferred unification:
25//
26// A previous plan (review-all-usages-of-vast-thunder slice 8 / B1) proposed
27// migrating this function onto `gfx::DefaultBindingFor(SheetRole)` from
28// `app/gfx/types/sheet_role_palette_table.h`, on the theory that the binding
29// table is the canonical place for palette-group metadata. Investigation
30// surfaced two structural blockers that make a literal migration lossy:
31//
32// 1. `SheetRolePaletteBinding` carries `{palette_group_name,
33// default_sub_index, cgram_base_row}`. It does NOT carry
34// `colors_per_row` or `has_explicit_transparent`. The row-layout
35// data has no representation in the binding struct today.
36//
37// 2. `SheetRole` covers 8 roles mapping to 6 distinct group names
38// (kOverworldMain/Aux1 share "ow_aux", kOverworldGfx maps to "ow_main"
39// not "ow_main" as the slot-0 rendering route, etc). The 13 group names
40// below cover seven groups not modeled by SheetRole at all:
41// "swords", "shields", "grass", "3d_object", "global_sprites",
42// "armors", "ow_mini_map" (plus "sprites_aux2"/"sprites_aux3" which
43// collapse onto kSpriteAux1 in the role taxonomy).
44//
45// A real unification would need to (a) extend `SheetRolePaletteBinding` with
46// row-layout fields, (b) add a reverse lookup `BindingForGroupName(string_view)`
47// keyed on the full set of palette group names, and (c) decide whether
48// non-SheetRole groups warrant new role variants or a separate
49// `KnownPaletteGroup` enum. That is a multi-file refactor with risk of
50// silently flipping cgram routing for callers of the existing binding, so it
51// stays out of slice 8.
52//
53// This header keeps the function inline so a regression test can pin the
54// truth table directly without depending on the panel UI; any future
55// migration is expected to use that test as a safety net.
56inline PaletteRowLayout GetPaletteRowLayout(std::string_view group_name,
57 std::size_t palette_size) {
58 if (group_name == "ow_main" || group_name == "ow_aux" ||
59 group_name == "ow_animated" || group_name == "sprites_aux1" ||
60 group_name == "sprites_aux2" || group_name == "sprites_aux3") {
61 return {7, false};
62 }
63 if (group_name == "global_sprites" || group_name == "armors" ||
64 group_name == "dungeon_main") {
65 return {15, false};
66 }
67 if (group_name == "hud" || group_name == "ow_mini_map") {
68 return {16, true};
69 }
70 if (group_name == "swords") {
71 return {3, false};
72 }
73 if (group_name == "shields") {
74 return {4, false};
75 }
76 if (group_name == "grass") {
77 return {3, false};
78 }
79 if (group_name == "3d_object") {
80 return {8, false};
81 }
82
83 if (palette_size % 16 == 0) {
84 return {16, true};
85 }
86 if (palette_size % 15 == 0) {
87 return {15, false};
88 }
89 if (palette_size % 7 == 0) {
90 return {7, false};
91 }
92
93 int fallback = palette_size > 0 ? static_cast<int>(palette_size) : 1;
94 return {fallback, false};
95}
96
97inline int GetPaletteRowCount(std::size_t palette_size, int colors_per_row) {
98 if (colors_per_row <= 0) {
99 return 1;
100 }
101 return static_cast<int>((palette_size + colors_per_row - 1) / colors_per_row);
102}
103
104} // namespace internal
105} // namespace editor
106} // namespace yaze
107
108#endif // YAZE_APP_EDITOR_GRAPHICS_PALETTE_CONTROLS_PANEL_INTERNAL_H_
int GetPaletteRowCount(std::size_t palette_size, int colors_per_row)
PaletteRowLayout GetPaletteRowLayout(std::string_view group_name, std::size_t palette_size)