dumb regex stuff and snestileskitten code. almost there though

This commit is contained in:
Justin Scofield
2022-06-11 23:41:05 -04:00
parent 6bf720e0e6
commit b26720f14d
4 changed files with 78 additions and 92 deletions

View File

@@ -25,6 +25,7 @@ void OverworldEditor::Update() {
surface = current_scene_.buildSurface( surface = current_scene_.buildSurface(
rom_.ExtractTiles(4, 2048), palette_, current_set_.tilesPattern); rom_.ExtractTiles(4, 2048), palette_, current_set_.tilesPattern);
gfx_texture = SDL_CreateTextureFromSurface(Core::renderer, surface); gfx_texture = SDL_CreateTextureFromSurface(Core::renderer, surface);
doneLoaded = true; doneLoaded = true;
} }
@@ -257,7 +258,7 @@ void OverworldEditor::DrawOverworldCanvas() {
draw_list->PopClipRect(); draw_list->PopClipRect();
} }
void OverworldEditor::DrawTileSelector() { void OverworldEditor::DrawTileSelector() {
if (ImGui::BeginTabBar("##TabBar")) { if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
if (ImGui::BeginTabItem("Tile8")) { if (ImGui::BeginTabItem("Tile8")) {
if (rom_.isLoaded()) { if (rom_.isLoaded()) {
ImGui::Image((void *)(intptr_t)gfx_texture, ImVec2(128, 7104)); ImGui::Image((void *)(intptr_t)gfx_texture, ImVec2(128, 7104));

View File

@@ -5,6 +5,7 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <regex>
#include "png.h" #include "png.h"
@@ -45,67 +46,55 @@ char *hexString(const char *str, const unsigned int size) {
TilesPattern::TilesPattern() { TilesPattern::TilesPattern() {
tilesPerRow = 16; tilesPerRow = 16;
numberOfTiles = 16; numberOfTiles = 16;
transformVector.push_back(std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9, 11, 12, 13, 14, 15, 16});
// transformVector.push_back(std::vector<int>{0, 1, 2, 3});
// transformVector.push_back(std::vector<int>{4, 5, 6, 7});
// transformVector.push_back(std::vector<int>{8, 9, 11, 12});
// transformVector.push_back(std::vector<int>{13, 14, 15, 16});
// default_settings();
} }
// [pattern] // [pattern]
// name = "32x32 B (4x4)" // name = "32x32 B (4x4)"
// number_of_tile = 16 // number_of_tile = 16
// pattern = // pattern =
void TilesPattern::default_settings() { void TilesPattern::default_settings() {
numberOfTiles = 16; numberOfTiles = 16;
std::string patternString = "[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, A, B], [C, D, E, F]"; std::string patternString =
"[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, A, B], [C, D, E, F]";
transformVector.clear(); transformVector.clear();
// if (regex_match ("softwareTesting", regex("(soft)(.*)") )) std::smatch cm;
// cout << "string:literal => matched\n";
// const char mystr[] = "SoftwareTestingHelp";
// string str ("software");
// regex str_expr ("(soft)(.*)");
// if (regex_match (str,str_expr))
// cout << "string:object => matched\n";
// if ( regex_match ( str.begin(), str.end(), str_expr ) )
// cout << "string:range(begin-end)=> matched\n";
// cmatch cm;
// regex_match (mystr,cm,str_expr);
// smatch sm;
// regex_match (str,sm,str_expr);
// regex_match ( str.cbegin(), str.cend(), sm, str_expr);
// cout << "String:range, size:" << sm.size() << " matches\n";
// regex_match ( mystr, cm, str_expr, regex_constants::match_default );
std::cmatch cm;
std::regex arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])"); std::regex arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])");
int pos = 0; int pos = 0;
while (arrayRegExp.indexIn(patternString, pos) != -1) { while (std::regex_search(patternString, cm, arrayRegExp)) {
std::string arrayString = arrayRegExp.cap(1); // while (arrayRegExp.indexIn(patternString, pos) != -1) {
std::string arrayString = cm[1];
std::vector<int> tmpVect; std::vector<int> tmpVect;
// std::cout << arrayString; // std::cout << arrayString;
unsigned int stringPos = 1; unsigned int stringPos = 1;
while (arrayString[stringPos] != ']') { while (arrayString[stringPos] != ']') {
while (arrayString[stringPos] == ' ') stringPos++; while (arrayString[stringPos] == ' ') stringPos++;
std::smatch cm_;
std::regex hex("([0-F|a-f]+)"); std::regex hex("([0-F|a-f]+)");
bool ok; bool ok;
if (hex.indexIn(arrayString, stringPos) == stringPos) { std::regex_search(arrayString, cm, hex);
tmpVect.push_back(hex.cap(1).toInt(&ok, 16)); if (cm[1] == stringPos) {
std::cout << "here" << std::endl;
// tmpVect.push_back(stoi(cm[1]));
} }
while (arrayString[stringPos] == ' ') stringPos++; while (arrayString[stringPos] == ' ') stringPos++;
stringPos++; // should be the comma stringPos++; // should be the comma
} }
pos += arrayRegExp.matchedLength(); pos += cm.size();
transformVector.push_back(tmpVect); transformVector.push_back(tmpVect);
} }
std::cout << transformVector.size() << std::endl; std::cout << transformVector.size() << std::endl;
for ( const auto & each : transformVector )
std::cout << each << std::endl;
} }
bool TilesPattern::load(std::string patternFile) { bool TilesPattern::load(std::string patternFile) {
@@ -260,75 +249,73 @@ std::vector<tile8> TilesPattern::reverse(const TilesPattern &pattern,
return pattern.reverse(tiles); return pattern.reverse(tiles);
} }
TilePreset::TilePreset() {
name = "";
romName = "";
romType = "";
TilePreset::TilePreset() pcTilesLocation = -1;
{ SNESTilesLocation = 0;
name = ""; length = 0;
romName = ""; bpp = 0;
romType = ""; compression = "None";
pcPaletteLocation = 0;
pcTilesLocation = -1; SNESPaletteLocation = 0;
SNESTilesLocation = 0; paletteNoZeroColor = false;
length = 0;
bpp = 0;
compression = "None";
pcPaletteLocation = 0;
SNESPaletteLocation = 0;
paletteNoZeroColor = false;
} }
bool TilePreset::save(const std::string &file) bool TilePreset::save(const std::string &file) {
{ // QSettings pFile(file, QSettings::IniFormat);
// QSettings pFile(file, QSettings::IniFormat);
// if (pFile.isWritable() == false) // if (pFile.isWritable() == false)
// return false; // return false;
// pFile.setValue("_/name", name); // pFile.setValue("_/name", name);
// pFile.setValue("rom/name", romName); // pFile.setValue("rom/name", romName);
// pFile.setValue("rom/type", romType); // pFile.setValue("rom/type", romType);
// pFile.setValue("tiles/pc_location", QString::number(pcTilesLocation, 16)); // pFile.setValue("tiles/pc_location", QString::number(pcTilesLocation, 16));
// pFile.setValue("tiles/snes_location", QString::number(SNESTilesLocation, 16)); // pFile.setValue("tiles/snes_location", QString::number(SNESTilesLocation,
// pFile.setValue("tiles/length", length); // 16)); pFile.setValue("tiles/length", length); pFile.setValue("tiles/bpp",
// pFile.setValue("tiles/bpp", bpp); // bpp); pFile.setValue("tiles/compression", compression);
// pFile.setValue("tiles/compression", compression); // pFile.setValue("tiles/pattern", tilesPattern.name);
// pFile.setValue("tiles/pattern", tilesPattern.name);
// pFile.setValue("palette/pc_location", QString::number(pcPaletteLocation, 16)); // pFile.setValue("palette/pc_location", QString::number(pcPaletteLocation,
// pFile.setValue("palette/snes_location", QString::number(SNESPaletteLocation, 16)); // 16)); pFile.setValue("palette/snes_location",
// pFile.setValue("palette/nozerocolor", paletteNoZeroColor); // QString::number(SNESPaletteLocation, 16));
// pFile.setValue("palette/nozerocolor", paletteNoZeroColor);
return true; return true;
} }
bool TilePreset::load(const std::string& file) bool TilePreset::load(const std::string &file) {
{ // QSettings pFile(file, QSettings::IniFormat);
// QSettings pFile(file, QSettings::IniFormat);
// /* Meh solution to know if the file is right*/ // /* Meh solution to know if the file is right*/
// if (pFile.value("_/name").toString().isEmpty()) // if (pFile.value("_/name").toString().isEmpty())
// return false; // return false;
// name = pFile.value("_/name").toString(); // name = pFile.value("_/name").toString();
// romName = pFile.value("rom/name").toString(); // romName = pFile.value("rom/name").toString();
// romType = pFile.value("rom/type").toString(); // romType = pFile.value("rom/type").toString();
// /* Locations are stored in a hex string */ // /* Locations are stored in a hex string */
// bool ok; // bool ok;
// pcTilesLocation = pFile.value("tiles/pc_location").toString().toUInt(&ok, 16); // pcTilesLocation = pFile.value("tiles/pc_location").toString().toUInt(&ok,
// SNESTilesLocation = pFile.value("tiles/snes_location").toString().toUInt(&ok, 16); // 16); SNESTilesLocation =
// length = pFile.value("tiles/length").toInt(); // pFile.value("tiles/snes_location").toString().toUInt(&ok, 16); length =
// bpp = pFile.value("tiles/bpp").toInt(); // pFile.value("tiles/length").toInt(); bpp =
// compression = pFile.value("tiles/compression").toString(); // pFile.value("tiles/bpp").toInt(); compression =
// QString patternName = pFile.value("tiles/pattern").toString(); // pFile.value("tiles/compression").toString(); QString patternName =
// if (patternName.isEmpty()) // pFile.value("tiles/pattern").toString(); if (patternName.isEmpty())
// patternName = "normal"; // patternName = "normal";
// tilesPattern = TilesPattern::pattern(patternName); // tilesPattern = TilesPattern::pattern(patternName);
// pcPaletteLocation = pFile.value("palette/pc_location").toString().toUInt(&ok, 16); // pcPaletteLocation =
// SNESPaletteLocation = pFile.value("palette/snes_location").toString().toUInt(&ok, 16); // pFile.value("palette/pc_location").toString().toUInt(&ok, 16);
// paletteNoZeroColor = pFile.value("palette/nozerocolor").toBool(); // SNESPaletteLocation =
return true; // pFile.value("palette/snes_location").toString().toUInt(&ok, 16);
// paletteNoZeroColor = pFile.value("palette/nozerocolor").toBool();
return true;
} }
} // namespace Graphics } // namespace Graphics

View File

@@ -3,7 +3,6 @@
#include <tile.h> #include <tile.h>
#include <regex>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>

View File

@@ -41,8 +41,7 @@ std::vector<tile8> ROM::ExtractTiles(unsigned int bpp, unsigned int length) {
std::vector<tile8> rawTiles; std::vector<tile8> rawTiles;
unsigned int lastCompressedSize; unsigned int lastCompressedSize;
unsigned int size = length; unsigned int size = length;
char *data = char *data = alttp_decompress_gfx((char*)current_rom_, 0, length, &size, &lastCompressedSize);
alttp_decompress_gfx(data, 0, length, &size, &lastCompressedSize);
if (data == NULL) { if (data == NULL) {
return rawTiles; return rawTiles;