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

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

View File

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