support ruby in rme

This commit is contained in:
garak 2022-04-28 20:52:31 -04:00 committed by garakmon
parent 80909734c2
commit aeb56e579c
8 changed files with 201 additions and 77 deletions

View file

@ -31,7 +31,11 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="config_alias"/> <widget class="QLineEdit" name="config_alias">
<property name="toolTip">
<string>A nickname for this region map that will differentiate it from others (should be unique).</string>
</property>
</widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="message_alias"> <widget class="QLabel" name="message_alias">
@ -58,6 +62,9 @@
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="config_tilemapFormat"> <widget class="QComboBox" name="config_tilemapFormat">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The tilemap format can be either:&lt;/p&gt;&lt;p&gt;1) Plain (tilemap is a list of 8-bit tile indexes into the tileset)&lt;/p&gt;&lt;p&gt;2) 4BPP (tilemap entries are 16 bits, with x/y-flip, and palette index for 16 16-color palettes)&lt;/p&gt;&lt;p&gt;3) 8BPP (tilemap entries are 16 bits, with x/y-flip, single 256-color palette)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>plain</string> <string>plain</string>
@ -123,6 +130,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>The height of the tilemap</string>
</property>
<property name="maximum"> <property name="maximum">
<number>255</number> <number>255</number>
</property> </property>
@ -170,6 +180,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Path to the tileset image (.png) relative to the project root.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -201,6 +214,9 @@
</item> </item>
<item row="8" column="1"> <item row="8" column="1">
<widget class="QFrame" name="frame_2"> <widget class="QFrame" name="frame_2">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Path to the tilemap binary relative to the project root.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -272,7 +288,11 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QLineEdit" name="config_tilemapPalettePath"/> <widget class="QLineEdit" name="config_tilemapPalettePath">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;(optional) Path to the .pal JASC palette file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="browse_tilemapPalettePath"> <widget class="QPushButton" name="browse_tilemapPalettePath">
@ -308,6 +328,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The width of the tilemap&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="maximum"> <property name="maximum">
<number>255</number> <number>255</number>
</property> </property>
@ -334,6 +357,9 @@
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="config_layoutFormat"> <widget class="QComboBox" name="config_layoutFormat">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The format of the layout file, can be a C array in a text file with &amp;quot;MAPSEC_&amp;quot;-prefixed constants, or a binary file where each byte is a value of some &amp;quot;MAPSEC_&amp;quot;-prefixed constant.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>C array</string> <string>C array</string>
@ -385,7 +411,11 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QLineEdit" name="config_layoutPath"/> <widget class="QLineEdit" name="config_layoutPath">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The path to the layout file, relative to the project root.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="browse_layoutPath"> <widget class="QPushButton" name="browse_layoutPath">
@ -443,6 +473,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The layout width.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum"> <property name="minimum">
<number>0</number> <number>0</number>
</property> </property>
@ -473,6 +506,9 @@
</item> </item>
<item> <item>
<widget class="QSpinBox" name="config_leftOffs"> <widget class="QSpinBox" name="config_leftOffs">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The offset from the left of the tilemap where the layout starts.&lt;/p&gt;&lt;p&gt;(ie, coordinate (0,0) in the layout would be (offset left, offset top) in the tilemap).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="maximum"> <property name="maximum">
<number>255</number> <number>255</number>
</property> </property>
@ -540,6 +576,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The layout height.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum"> <property name="minimum">
<number>0</number> <number>0</number>
</property> </property>
@ -569,7 +608,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="config_topOffs"/> <widget class="QSpinBox" name="config_topOffs">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The offset from the top of the tilemap where the layout starts.&lt;/p&gt;&lt;p&gt;(ie, coordinate (0,0) in the layout would be (offset left, offset top) in the tilemap).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_5"> <spacer name="horizontalSpacer_5">

View file

@ -181,6 +181,7 @@ private:
bool layout_uses_layers = false; bool layout_uses_layers = false;
QStringList layout_constants; QStringList layout_constants;
QString layout_qualifiers; QString layout_qualifiers;
QString layout_type;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QVector<shared_ptr<TilemapTile>> tilemap; QVector<shared_ptr<TilemapTile>> tilemap;

View file

@ -93,11 +93,11 @@ private:
bool saveRegionMapEntries(); bool saveRegionMapEntries();
tsl::ordered_map<QString, MapSectionEntry> region_map_entries; tsl::ordered_map<QString, MapSectionEntry> region_map_entries;
void buildConfigDialog(); bool buildConfigDialog();
poryjson::Json configRegionMapDialog(); poryjson::Json configRegionMapDialog();
void buildUpdateConfigDialog(); void buildUpdateConfigDialog();
poryjson::Json buildDefaultJson(); poryjson::Json buildDefaultJson();
poryjson::Json getJsonFromAlias(QString alias); bool verifyConfig(poryjson::Json cfg);
bool modified(); bool modified();
@ -117,7 +117,6 @@ private:
void setRegionMap(RegionMap *map); void setRegionMap(RegionMap *map);
bool createCityMap(QString name); bool createCityMap(QString name);
bool tryInsertNewMapEntry(QString);
void restoreWindowState(); void restoreWindowState();
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);

View file

@ -0,0 +1,22 @@
{
"region_maps": [
{
"alias": "hoenn",
"tilemap": {
"width": 64,
"height": 64,
"format": "plain",
"tileset_path": "graphics/pokenav/region_map.png",
"tilemap_path": "graphics/pokenav/region_map_map.bin"
},
"layout": {
"width": 28,
"height": 15,
"offset_left": 1,
"offset_top": 2,
"format": "C array",
"path": "src/data/region_map/region_map_layout.h"
}
}
]
}

View file

@ -15,13 +15,7 @@
using std::make_shared; using std::make_shared;
static bool ensureRegionMapFileExists(QString filepath) {
if (!QFile::exists(filepath)) {
logError(QString("Region map file does not exist: %1").arg(filepath));
return false;
}
return true;
}
RegionMap::RegionMap(Project *project) { RegionMap::RegionMap(Project *project) {
this->project = project; this->project = project;
@ -39,8 +33,7 @@ bool RegionMap::loadMapData(poryjson::Json data) {
this->layout_layers.clear(); this->layout_layers.clear();
this->layouts.clear(); this->layouts.clear();
loadTilemap(tilemapJson); return loadTilemap(tilemapJson) && loadLayout(layoutJson);
loadLayout(layoutJson);
} }
int RegionMap::tilemapBytes() { int RegionMap::tilemapBytes() {
@ -166,8 +159,6 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
} }
case LayoutFormat::CArray: case LayoutFormat::CArray:
{ {
// TODO: pokeruby / non-layered style C array or just an array of mapsections
ParseUtil parser; ParseUtil parser;
QString text = parser.readTextFile(fullPath(this->layout_path)); QString text = parser.readTextFile(fullPath(this->layout_path));
@ -228,8 +219,46 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) {
} }
} else { } else {
logError("Region map layout is not readable."); // try single-layered
return false; QRegularExpression reAlt("(?<qual_1>static)?\\s?(?<qual_2>const)?\\s?(?<type>[A-Za-z0-9_]+)?\\s+(?<label>[A-Za-z0-9_]+)\\[\\]");
QRegularExpressionMatch matchAlt = reAlt.match(text);
if (matchAlt.hasMatch()) {
// TODO: save type info
QString qualifiers = matchAlt.captured("qual_1") + " " + matchAlt.captured("qual_2");
QString type = matchAlt.captured("type");
QString label = matchAlt.captured("label");
this->layout_constants.append("");
this->layout_qualifiers = qualifiers + " " + type;
this->layout_array_label = label;
this->layout_type = type;
QRegularExpression reSec("(?<sec>MAPSEC_[A-Za-z0-9_]+)");
QRegularExpressionMatchIterator k = reSec.globalMatch(text);
QList<LayoutSquare> layout;
int l = 0;
while (k.hasNext()) {
QRegularExpressionMatch p = k.next();
QString sec = p.captured("sec");
int x = l % this->layout_width;
int y = l / this->layout_width;
LayoutSquare square;
square.map_section = sec;
square.has_map = (sec != "MAPSEC_NONE" && !sec.isEmpty());
square.x = x;
square.y = y;
layout.append(square);
l++;
}
this->layout_layers.append("main");
setLayout("main", layout);
} else {
logError("Region map layout is not readable.");
return false;
}
} }
break; break;
} }
@ -256,6 +285,8 @@ void RegionMap::redo() {
void RegionMap::save() { void RegionMap::save() {
saveTilemap(); saveTilemap();
saveLayout(); saveLayout();
this->editHistory.setClean();
} }
poryjson::Json::object RegionMap::config() { poryjson::Json::object RegionMap::config() {
@ -330,8 +361,11 @@ void RegionMap::saveLayout() {
} }
text += " = {\n"; text += " = {\n";
if (this->layout_layers.size() == 1) { if (this->layout_layers.size() == 1) {
// TODO: single layered for (LayoutSquare s : this->getLayout("main")) {
// just dump the array of map sections, or save as multi dimensional [width][height]? text += " " + s.map_section + ",\n";
}
text.chop(2);
text += "\n";
} else { } else {
// multi layered // multi layered
for (auto layoutName : this->layout_layers) { for (auto layoutName : this->layout_layers) {

View file

@ -1798,14 +1798,11 @@ void MainWindow::connectSubEditorsToShortcutsEditor() {
connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved, connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved,
tilesetEditor, &TilesetEditor::applyUserShortcuts); tilesetEditor, &TilesetEditor::applyUserShortcuts);
// TODO: Remove this check when the region map editor supports pokefirered. if (!regionMapEditor)
//if (projectConfig.getBaseGameVersion() != BaseGameVersion::pokefirered) { initRegionMapEditor();
if (!regionMapEditor) if (regionMapEditor)
initRegionMapEditor(); connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved,
if (regionMapEditor) regionMapEditor, &RegionMapEditor::applyUserShortcuts);
connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved,
regionMapEditor, &RegionMapEditor::applyUserShortcuts);
//}
} }
void MainWindow::on_actionPencil_triggered() void MainWindow::on_actionPencil_triggered()

View file

@ -180,8 +180,14 @@ void buildEmeraldDefaults(poryjson::Json &json) {
QString err; QString err;
json = poryjson::Json::parse(emeraldDefault, err); json = poryjson::Json::parse(emeraldDefault, err);
}
// TODO: error check these void buildRubyDefaults(poryjson::Json &json) {
ParseUtil parser;
QString emeraldDefault = parser.readTextFile(":/text/region_map_default_ruby.json");
QString err;
json = poryjson::Json::parse(emeraldDefault, err);
} }
void buildFireredDefaults(poryjson::Json &json) { void buildFireredDefaults(poryjson::Json &json) {
@ -201,7 +207,7 @@ poryjson::Json RegionMapEditor::buildDefaultJson() {
break; break;
case BaseGameVersion::pokeruby: case BaseGameVersion::pokeruby:
// TODO: pokeruby defaults buildRubyDefaults(defaultJson);
break; break;
case BaseGameVersion::pokefirered: case BaseGameVersion::pokefirered:
@ -212,7 +218,7 @@ poryjson::Json RegionMapEditor::buildDefaultJson() {
return defaultJson; return defaultJson;
} }
void RegionMapEditor::buildConfigDialog() { bool RegionMapEditor::buildConfigDialog() {
// use this temporary object while window is active, save only when user accepts // use this temporary object while window is active, save only when user accepts
poryjson::Json rmConfigJsonUpdate = this->rmConfigJson; poryjson::Json rmConfigJsonUpdate = this->rmConfigJson;
@ -302,13 +308,13 @@ void RegionMapEditor::buildConfigDialog() {
// //cityMapList->setFocusPolicy(Qt::NoFocus); // //cityMapList->setFocusPolicy(Qt::NoFocus);
// form.addRow(new QLabel("City Map List:")); // form.addRow(new QLabel("City Map List:"));
// form.addRow(cityMapList); // form.addRow(cityMapList);
//
// for (int i = 0; i < 20; i++) { // for (int i = 0; i < 20; i++) {
// QListWidgetItem *newItem = new QListWidgetItem; // QListWidgetItem *newItem = new QListWidgetItem;
// newItem->setText(QString("city %1").arg(i)); // newItem->setText(QString("city %1").arg(i));
// cityMapList->addItem(newItem); // cityMapList->addItem(newItem);
// } // }
//
// QPushButton *addCitiesButton = new QPushButton("Configure City Maps..."); // QPushButton *addCitiesButton = new QPushButton("Configure City Maps...");
// form.addRow(addCitiesButton); // form.addRow(addCitiesButton);
// // needs to pick tilemaps and such here too // // needs to pick tilemaps and such here too
@ -347,12 +353,12 @@ void RegionMapEditor::buildConfigDialog() {
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
// if everything looks good, we can update the master json // if everything looks good, we can update the master json
this->rmConfigJson = rmConfigJsonUpdate; this->rmConfigJson = rmConfigJsonUpdate;
} else { return true;
// TODO: return bool from this function so can close RME on error
} }
return false;
} }
// TODO: set tooltips, default values in spinboxes
poryjson::Json RegionMapEditor::configRegionMapDialog() { poryjson::Json RegionMapEditor::configRegionMapDialog() {
RegionMapPropertiesDialog dialog(this); RegionMapPropertiesDialog dialog(this);
@ -361,8 +367,6 @@ poryjson::Json RegionMapEditor::configRegionMapDialog() {
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
poryjson::Json regionMapJson = dialog.saveToJson(); poryjson::Json regionMapJson = dialog.saveToJson();
return regionMapJson; return regionMapJson;
} else {
// TODO: anything?
} }
return poryjson::Json(); return poryjson::Json();
@ -373,17 +377,45 @@ void RegionMapEditor::buildUpdateConfigDialog() {
// TODO: get rid of this function // TODO: get rid of this function
} }
poryjson::Json RegionMapEditor::getJsonFromAlias(QString alias) { bool RegionMapEditor::verifyConfig(poryjson::Json cfg) {
// unused OrderedJson::object obj = cfg.object_items();
// TODO: get a map Json from an alias
if (!obj.contains("region_maps")) {
logError("Region map config json has no map list.");
return false;
}
OrderedJson::array arr = obj["region_maps"].array_items();
for (auto ref : arr) {
RegionMap tempMap(this->project);
if (!tempMap.loadMapData(ref)) {
return false;
}
}
return true;
} }
bool RegionMapEditor::load() { bool RegionMapEditor::load() {
// check for config json file // check for config json file
QString jsonConfigFilepath = this->project->root + "/src/data/region_map/porymap_config.json"; QString jsonConfigFilepath = this->project->root + "/src/data/region_map/porymap_config.json";
if (!QFile::exists(jsonConfigFilepath)) {
logWarn("Region Map config file not found.");
bool badConfig = true;
if (QFile::exists(jsonConfigFilepath)) {
logInfo("Region map configuration file found.");
ParseUtil parser;
OrderedJson::object obj;
if (parser.tryParseOrderedJsonFile(&obj, jsonConfigFilepath)) {
this->rmConfigJson = OrderedJson(obj);
}
badConfig = !verifyConfig(this->rmConfigJson);
} else {
logWarn("Region Map config file not found.");
}
if (badConfig) {
// show popup explaining next window // show popup explaining next window
QMessageBox warning; QMessageBox warning;
warning.setText("Region map configuration not found."); warning.setText("Region map configuration not found.");
@ -393,25 +425,16 @@ bool RegionMapEditor::load() {
if (warning.exec() == QMessageBox::Ok) { if (warning.exec() == QMessageBox::Ok) {
// there is a separate window that allows to load multiple region maps, // there is a separate window that allows to load multiple region maps,
buildConfigDialog(); if (!buildConfigDialog()) {
logError("Region map loading interrupted [user]");
// TODO: need to somehow handle (by making above function return bool?) return false;
// when user closes the config dialog without setting up maps so we }
// can return false from here in that case as well
} else { } else {
// TODO: Do not open region map editor (maybe just return false is sufficient?) // do not open editor
logError("Region map loading interrupted [user]");
return false; return false;
} }
} }
else {
// TODO: put this first? so can fall back on the above if parse errors
// TODO: verify this object before assignment
logInfo("Region map configuration file found.");
ParseUtil parser;
OrderedJson::object obj;
parser.tryParseOrderedJsonFile(&obj, jsonConfigFilepath);
this->rmConfigJson = OrderedJson(obj);
}
// if all has gone well, this->rmConfigJson should be populated // if all has gone well, this->rmConfigJson should be populated
// next, load the entries // next, load the entries
@ -420,13 +443,14 @@ bool RegionMapEditor::load() {
// load the region maps into this->region_maps // load the region maps into this->region_maps
poryjson::Json::object regionMapObjectCopy = this->rmConfigJson.object_items(); poryjson::Json::object regionMapObjectCopy = this->rmConfigJson.object_items();
for (auto o : regionMapObjectCopy["region_maps"].array_items()) { for (auto o : regionMapObjectCopy["region_maps"].array_items()) {
// TODO: could this crash?
QString alias = o.object_items().at("alias").string_value(); QString alias = o.object_items().at("alias").string_value();
RegionMap *newMap = new RegionMap(this->project); RegionMap *newMap = new RegionMap(this->project);
// TODO: is there a better way than this pointer to get entries to pixmap item? (surely)
newMap->setEntries(&this->region_map_entries); newMap->setEntries(&this->region_map_entries);
newMap->loadMapData(o); if (!newMap->loadMapData(o)) {
delete newMap;
return false;
}
connect(newMap, &RegionMap::mapNeedsDisplaying, [this]() { connect(newMap, &RegionMap::mapNeedsDisplaying, [this]() {
displayRegionMap(); displayRegionMap();
@ -481,7 +505,6 @@ bool RegionMapEditor::loadCityMaps() {
} }
bool RegionMapEditor::saveRegionMap(RegionMap *map) { bool RegionMapEditor::saveRegionMap(RegionMap *map) {
//
if (!map) return false; if (!map) return false;
map->save(); map->save();
@ -512,7 +535,6 @@ void RegionMapEditor::saveConfig() {
} }
void RegionMapEditor::on_action_RegionMap_Save_triggered() { void RegionMapEditor::on_action_RegionMap_Save_triggered() {
// TODO: add "Save All" to save all region maps
saveRegionMap(this->region_map); saveRegionMap(this->region_map);
// save entries // save entries
@ -875,11 +897,6 @@ bool RegionMapEditor::createCityMap(QString name) {
*/ */
} }
bool RegionMapEditor::tryInsertNewMapEntry(QString mapsec) {
// TODO
return false;
}
void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) { void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) {
this->selectedImageTile = id; this->selectedImageTile = id;
} }
@ -1059,7 +1076,6 @@ void RegionMapEditor::on_comboBox_RM_Entry_MapSection_textActivated(const QStrin
} }
void RegionMapEditor::on_comboBox_layoutLayer_textActivated(const QString &text) { void RegionMapEditor::on_comboBox_layoutLayer_textActivated(const QString &text) {
// TODO: verify whether layer is legit
this->region_map->setLayer(text); this->region_map->setLayer(text);
displayRegionMapLayout(); displayRegionMapLayout();
displayRegionMapLayoutOptions(); displayRegionMapLayoutOptions();

View file

@ -48,28 +48,40 @@ QImage TilemapTileSelector::tileImg(shared_ptr<TilemapTile> tile) {
tilesetImage.convertTo(QImage::Format::Format_Indexed8); tilesetImage.convertTo(QImage::Format::Format_Indexed8);
// TODO: bounds check on the palette copying // TODO: bounds check on the palette copying
switch(this->format) { switch(this->format) {
case TilemapFormat::Plain: case TilemapFormat::Plain:
break; break;
case TilemapFormat::BPP_4: case TilemapFormat::BPP_4:
{ {
QVector<QRgb> newColorTable;
int palMinLength = tile->palette() * 16 + 16;
if ((this->palette.count() < palMinLength) || (tilesetImage.colorTable().count() != 16)) {
// either a) the palette has less than 256 colors, or b) the image is improperly indexed
for (QRgb color : tilesetImage.colorTable()) {
int gray = qGray(color);
newColorTable.append(qRgb(gray, gray, gray));
}
} else {
// use actual pal
// before Qt 6, the color table is a QVector which is deprecated now, and this method does not exits // before Qt 6, the color table is a QVector which is deprecated now, and this method does not exits
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
tilesetImage.setColorTable(this->palette.toVector().mid(tile->palette() * 16, 16)); newColorTable = this->palette.toVector().mid(tile->palette() * 16, 16);
#else #else
tilesetImage.setColorTable(this->palette.mid(tile->palette() * 16, 16)); newColorTable = this->palette.mid(tile->palette() * 16, 16);
#endif #endif
}
tilesetImage.setColorTable(newColorTable);
break; break;
} }
case TilemapFormat::BPP_8: case TilemapFormat::BPP_8:
{ {
// TODO: if (tilesetImage.colorTable().count() == this->palette.count()) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
//tilesetImage.setColorTable(this->palette.toVector()); tilesetImage.setColorTable(this->palette.toVector());
#else #else
//tilesetImage.setColorTable(this->palette); tilesetImage.setColorTable(this->palette);
#endif #endif
}
break; break;
} }
default: break; default: break;