Skip to content

Commit 17950b2

Browse files
authored
fix: Color data is properly loaded (#42)
Original issue raised from usage in GTNH modpack. The data format generated in `colorPalette.json` is different from what is expected by this file script. The data still available and just required some refactor. Instead of `colorPalette.table`, a refactor of `colorPalette.basicColors` can be used. This refactor runs only when needed (just in case the previous format is in use somehow).
1 parent c401be9 commit 17950b2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/main/resources/assets/journeymap/web/colorpalette.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,43 @@ <h2>$jm.colorpalette.mods$:</h2>
8787
var count = 0;
8888
var table = colorpalette.table;
8989

90+
if (table === undefined && colorpalette.basicColors !== undefined) {
91+
table = Object.fromEntries(
92+
colorpalette.basicColors
93+
.reduce(
94+
(collector, basicColor) => {
95+
var parts = basicColor.uid.split(/:/, 2);
96+
97+
if (!collector.has(parts[0])) {
98+
collector.set(parts[0], new Map());
99+
}
100+
var blocks = collector.get(parts[0]);
101+
102+
if (!blocks.has(parts[1])) {
103+
blocks.set(parts[1], new Map());
104+
}
105+
var states = blocks.get(parts[1]);
106+
107+
states.set(basicColor.meta, [basicColor.color, basicColor.alpha]);
108+
109+
return collector;
110+
},
111+
new Map()
112+
)
113+
.entries()
114+
.map(([mod, blocks]) => ([
115+
mod,
116+
Object.fromEntries(blocks
117+
.entries()
118+
.map(([block, states]) => ([
119+
block,
120+
Object.fromEntries(states.entries())
121+
]))
122+
)
123+
]))
124+
)
125+
}
126+
90127
for (var mod in table) {
91128
var modEl = document.createElement("div");
92129
modEl.className = "mod";

0 commit comments

Comments
 (0)